#ifndef GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_GL_TEXTURE_HOLDER_H_
#define GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_GL_TEXTURE_HOLDER_H_
#include "gpu/command_buffer/service/shared_image/gl_common_image_backing_factory.h"
#include "gpu/command_buffer/service/shared_image/shared_image_format_service_utils.h"
#include "ui/gl/progress_reporter.h"
class GrPromiseImageTexture;
namespace gpu {
class SharedContextState;
class GLTextureHolder {
public:
static viz::SharedImageFormat GetPlaneFormat(viz::SharedImageFormat format,
int plane_index);
GLTextureHolder(viz::SharedImageFormat format,
const gfx::Size& size,
bool is_passthrough,
gl::ProgressReporter* progress_reporter);
GLTextureHolder(GLTextureHolder&& other);
GLTextureHolder& operator=(GLTextureHolder&& other);
~GLTextureHolder();
gles2::Texture* texture() { return texture_; }
const scoped_refptr<gles2::TexturePassthrough>& passthrough_texture() {
return passthrough_texture_;
}
GLuint GetServiceId() const;
void Initialize(const GLCommonImageBackingFactory::FormatInfo& format_info,
bool framebuffer_attachment_angle,
base::span<const uint8_t> pixel_data,
const std::string& debug_label);
void InitializeWithTexture(const GLFormatDesc& format_desc,
scoped_refptr<gles2::TexturePassthrough> texture);
void InitializeWithTexture(const GLFormatDesc& format_desc,
gles2::Texture* texture);
bool UploadFromMemory(const SkPixmap& pixmap);
bool ReadbackToMemory(const SkPixmap& pixmap);
sk_sp<GrPromiseImageTexture> GetPromiseImage(
SharedContextState* context_state);
gfx::Rect GetClearedRect() const;
void SetClearedRect(const gfx::Rect& cleared_rect);
void SetContextLost();
private:
viz::SharedImageFormat format_;
gfx::Size size_;
bool is_passthrough_;
bool context_lost_ = false;
raw_ptr<gles2::Texture> texture_ = nullptr;
scoped_refptr<gles2::TexturePassthrough> passthrough_texture_;
GLFormatDesc format_desc_;
raw_ptr<gl::ProgressReporter> progress_reporter_ = nullptr;
};
}
#endif