#ifndef UI_GL_ANDROID_SCOPED_JAVA_SURFACE_CONTROL_H_
#define UI_GL_ANDROID_SCOPED_JAVA_SURFACE_CONTROL_H_
#include <jni.h>
#include <cstddef>
#include <optional>
#include "base/android/scoped_java_ref.h"
#include "base/memory/scoped_refptr.h"
#include "ui/gfx/android/android_surface_control_compat.h"
#include "ui/gl/gl_export.h"
namespace gl {
class GL_EXPORT ScopedJavaSurfaceControl {
public:
ScopedJavaSurfaceControl();
ScopedJavaSurfaceControl(
const base::android::JavaRef<jobject>& j_surface_control,
bool release_on_destroy);
~ScopedJavaSurfaceControl();
ScopedJavaSurfaceControl(ScopedJavaSurfaceControl&& other);
ScopedJavaSurfaceControl& operator=(ScopedJavaSurfaceControl&& other);
ScopedJavaSurfaceControl(const ScopedJavaSurfaceControl&) = delete;
ScopedJavaSurfaceControl& operator=(const ScopedJavaSurfaceControl&) = delete;
explicit operator bool() const { return !!j_surface_control_; }
ScopedJavaSurfaceControl CopyRetainOwnership() const;
base::android::ScopedJavaGlobalRef<jobject> TakeJavaSurfaceControl(
bool& release_on_destroy);
scoped_refptr<gfx::SurfaceControl::Surface> MakeSurface();
private:
void DestroyIfNeeded();
base::android::ScopedJavaGlobalRef<jobject> j_surface_control_;
bool release_on_destroy_ = false;
};
}
#endif