Commit fa588156 authored by Vikas Soni's avatar Vikas Soni Committed by Commit Bot

Refactor SharedImageBackingFactoryAHB to pull out common code.

1. Refactor SharedImageBackingFactoryAHB to pull out GenGLTexture() method
into ahardwarebuffer_utils* so that it can be re-used by multiple
classes. This will eliminate code duplications in future.

2. Make few private members of gles2::Texture as public since those
members were used by too many friend classes.

Bug: 1091945
Change-Id: I0e82cd93d431d900fce2787478a97bef19b11eaf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2249582
Commit-Queue: vikas soni <vikassoni@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779807}
parent 8b98d8b7
...@@ -46,10 +46,10 @@ AbstractTextureImplOnSharedContext::AbstractTextureImplOnSharedContext( ...@@ -46,10 +46,10 @@ AbstractTextureImplOnSharedContext::AbstractTextureImplOnSharedContext(
texture_ = new gpu::gles2::Texture(service_id); texture_ = new gpu::gles2::Texture(service_id);
texture_->SetLightweightRef(); texture_->SetLightweightRef();
texture_->SetTarget(target, 1); texture_->SetTarget(target, 1);
texture_->sampler_state_.min_filter = GL_LINEAR; texture_->set_min_filter(GL_LINEAR);
texture_->sampler_state_.mag_filter = GL_LINEAR; texture_->set_mag_filter(GL_LINEAR);
texture_->sampler_state_.wrap_t = GL_CLAMP_TO_EDGE; texture_->set_wrap_t(GL_CLAMP_TO_EDGE);
texture_->sampler_state_.wrap_s = GL_CLAMP_TO_EDGE; texture_->set_wrap_s(GL_CLAMP_TO_EDGE);
gfx::Rect cleared_rect; gfx::Rect cleared_rect;
texture_->SetLevelInfo(target, 0, internal_format, width, height, depth, texture_->SetLevelInfo(target, 0, internal_format, width, height, depth,
border, format, type, cleared_rect); border, format, type, cleared_rect);
......
...@@ -8,6 +8,12 @@ ...@@ -8,6 +8,12 @@
#include "base/check.h" #include "base/check.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gl/gl_gl_api_implementation.h"
#include "ui/gl/gl_image_ahardwarebuffer.h"
#include "ui/gl/scoped_binders.h"
namespace gpu { namespace gpu {
...@@ -46,4 +52,51 @@ unsigned int AHardwareBufferFormat(viz::ResourceFormat format) { ...@@ -46,4 +52,51 @@ unsigned int AHardwareBufferFormat(viz::ResourceFormat format) {
} }
} }
gles2::Texture* GenGLTexture(AHardwareBuffer* buffer,
GLenum target,
const gfx::ColorSpace& color_space,
const gfx::Size& size,
const gfx::Rect& cleared_rect) {
gl::GLApi* api = gl::g_current_gl_context;
GLuint service_id = 0;
api->glGenTexturesFn(1, &service_id);
gl::ScopedTextureBinder texture_binder(target, service_id);
api->glTexParameteriFn(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
api->glTexParameteriFn(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
api->glTexParameteriFn(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
api->glTexParameteriFn(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Create an egl image using AHardwareBuffer.
auto egl_image = base::MakeRefCounted<gl::GLImageAHardwareBuffer>(size);
if (!egl_image->Initialize(buffer, false)) {
LOG(ERROR) << "Failed to create EGL image";
api->glDeleteTexturesFn(1, &service_id);
return nullptr;
}
if (!egl_image->BindTexImage(target)) {
LOG(ERROR) << "Failed to bind egl image";
api->glDeleteTexturesFn(1, &service_id);
return nullptr;
}
egl_image->SetColorSpace(color_space);
// Create a gles2 Texture.
auto* texture = new gles2::Texture(service_id);
texture->SetLightweightRef();
texture->SetTarget(target, 1);
texture->set_min_filter(GL_LINEAR);
texture->set_mag_filter(GL_LINEAR);
texture->set_wrap_t(GL_CLAMP_TO_EDGE);
texture->set_wrap_s(GL_CLAMP_TO_EDGE);
texture->SetLevelInfo(target, 0, egl_image->GetInternalFormat(), size.width(),
size.height(), 1, 0, egl_image->GetDataFormat(),
egl_image->GetDataType(), cleared_rect);
texture->SetLevelImage(target, 0, egl_image.get(), gles2::Texture::BOUND);
texture->SetImmutable(true, false);
return texture;
}
} // namespace gpu } // namespace gpu
...@@ -8,7 +8,20 @@ ...@@ -8,7 +8,20 @@
#include "components/viz/common/resources/resource_format.h" #include "components/viz/common/resources/resource_format.h"
#include "gpu/gpu_gles2_export.h" #include "gpu/gpu_gles2_export.h"
extern "C" typedef struct AHardwareBuffer AHardwareBuffer;
typedef unsigned int GLenum;
namespace gfx {
class ColorSpace;
class Rect;
class Size;
} // namespace gfx
namespace gpu { namespace gpu {
namespace gles2 {
class Texture;
} // namespace gles2
// TODO(vikassoni): In future we will need to expose the set of formats and // TODO(vikassoni): In future we will need to expose the set of formats and
// constraints (e.g. max size) to the clients somehow that are available for // constraints (e.g. max size) to the clients somehow that are available for
...@@ -25,6 +38,15 @@ AHardwareBufferSupportedFormat(viz::ResourceFormat format); ...@@ -25,6 +38,15 @@ AHardwareBufferSupportedFormat(viz::ResourceFormat format);
// Returns the corresponding AHardwareBuffer format. // Returns the corresponding AHardwareBuffer format.
unsigned int GPU_GLES2_EXPORT AHardwareBufferFormat(viz::ResourceFormat format); unsigned int GPU_GLES2_EXPORT AHardwareBufferFormat(viz::ResourceFormat format);
// Generates a gles2 texture from AHB. This method must be called with a current
// GLContext which will be used to create the Texture. This method adds a
// lightweight ref on the Texture which the caller is responsible for releasing.
gles2::Texture* GenGLTexture(AHardwareBuffer* buffer,
GLenum target,
const gfx::ColorSpace& color_space,
const gfx::Size& size,
const gfx::Rect& cleared_rect);
} // namespace gpu } // namespace gpu
#endif // GPU_COMMAND_BUFFER_SERVICE_AHARDWAREBUFFER_UTILS_H_ #endif // GPU_COMMAND_BUFFER_SERVICE_AHARDWAREBUFFER_UTILS_H_
...@@ -600,10 +600,10 @@ ExternalVkImageBacking::ProduceGLTexture(SharedImageManager* manager, ...@@ -600,10 +600,10 @@ ExternalVkImageBacking::ProduceGLTexture(SharedImageManager* manager,
texture_ = new gles2::Texture(texture_service_id); texture_ = new gles2::Texture(texture_service_id);
texture_->SetLightweightRef(); texture_->SetLightweightRef();
texture_->SetTarget(GL_TEXTURE_2D, 1); texture_->SetTarget(GL_TEXTURE_2D, 1);
texture_->sampler_state_.min_filter = GL_LINEAR; texture_->set_min_filter(GL_LINEAR);
texture_->sampler_state_.mag_filter = GL_LINEAR; texture_->set_mag_filter(GL_LINEAR);
texture_->sampler_state_.wrap_t = GL_CLAMP_TO_EDGE; texture_->set_wrap_t(GL_CLAMP_TO_EDGE);
texture_->sampler_state_.wrap_s = GL_CLAMP_TO_EDGE; texture_->set_wrap_s(GL_CLAMP_TO_EDGE);
// If the backing is already cleared, no need to clear it again. // If the backing is already cleared, no need to clear it again.
gfx::Rect cleared_rect; gfx::Rect cleared_rect;
if (IsCleared()) if (IsCleared())
......
...@@ -262,10 +262,10 @@ gles2::Texture* SharedImageBackingEglImage::GenEGLImageSibling() { ...@@ -262,10 +262,10 @@ gles2::Texture* SharedImageBackingEglImage::GenEGLImageSibling() {
auto* texture = new gles2::Texture(service_id); auto* texture = new gles2::Texture(service_id);
texture->SetLightweightRef(); texture->SetLightweightRef();
texture->SetTarget(target, 1 /*max_levels*/); texture->SetTarget(target, 1 /*max_levels*/);
texture->sampler_state_.min_filter = GL_LINEAR; texture->set_min_filter(GL_LINEAR);
texture->sampler_state_.mag_filter = GL_LINEAR; texture->set_mag_filter(GL_LINEAR);
texture->sampler_state_.wrap_t = GL_CLAMP_TO_EDGE; texture->set_wrap_t(GL_CLAMP_TO_EDGE);
texture->sampler_state_.wrap_s = GL_CLAMP_TO_EDGE; texture->set_wrap_s(GL_CLAMP_TO_EDGE);
// If the backing is already cleared, no need to clear it again. // If the backing is already cleared, no need to clear it again.
gfx::Rect cleared_rect; gfx::Rect cleared_rect;
......
...@@ -170,7 +170,6 @@ class SharedImageBackingAHB : public ClearTrackingSharedImageBacking { ...@@ -170,7 +170,6 @@ class SharedImageBackingAHB : public ClearTrackingSharedImageBacking {
MemoryTypeTracker* tracker) override; MemoryTypeTracker* tracker) override;
private: private:
gles2::Texture* GenGLTexture();
const base::android::ScopedHardwareBufferHandle hardware_buffer_handle_; const base::android::ScopedHardwareBufferHandle hardware_buffer_handle_;
// Not guarded by |lock_| as we do not use legacy_texture_ in threadsafe // Not guarded by |lock_| as we do not use legacy_texture_ in threadsafe
...@@ -582,7 +581,8 @@ bool SharedImageBackingAHB::ProduceLegacyMailbox( ...@@ -582,7 +581,8 @@ bool SharedImageBackingAHB::ProduceLegacyMailbox(
DCHECK(!is_writing_); DCHECK(!is_writing_);
DCHECK_EQ(size_t{0}, active_readers_.size()); DCHECK_EQ(size_t{0}, active_readers_.size());
DCHECK(hardware_buffer_handle_.is_valid()); DCHECK(hardware_buffer_handle_.is_valid());
legacy_texture_ = GenGLTexture(); legacy_texture_ = GenGLTexture(hardware_buffer_handle_.get(), GL_TEXTURE_2D,
color_space(), size(), ClearedRect());
if (!legacy_texture_) if (!legacy_texture_)
return false; return false;
// Make sure our |legacy_texture_| has the right initial cleared rect. // Make sure our |legacy_texture_| has the right initial cleared rect.
...@@ -602,7 +602,15 @@ SharedImageBackingAHB::ProduceGLTexture(SharedImageManager* manager, ...@@ -602,7 +602,15 @@ SharedImageBackingAHB::ProduceGLTexture(SharedImageManager* manager,
MemoryTypeTracker* tracker) { MemoryTypeTracker* tracker) {
// Use same texture for all the texture representations generated from same // Use same texture for all the texture representations generated from same
// backing. // backing.
auto* texture = GenGLTexture(); DCHECK(hardware_buffer_handle_.is_valid());
// Note that we are not using GL_TEXTURE_EXTERNAL_OES target(here and all
// other places in this file) since sksurface
// doesn't supports it. As per the egl documentation -
// https://www.khronos.org/registry/OpenGL/extensions/OES/OES_EGL_image_external.txt
// if GL_OES_EGL_image is supported then <target> may also be TEXTURE_2D.
auto* texture = GenGLTexture(hardware_buffer_handle_.get(), GL_TEXTURE_2D,
color_space(), size(), ClearedRect());
if (!texture) if (!texture)
return nullptr; return nullptr;
...@@ -633,8 +641,9 @@ SharedImageBackingAHB::ProduceSkia( ...@@ -633,8 +641,9 @@ SharedImageBackingAHB::ProduceSkia(
tracker); tracker);
} }
DCHECK(context_state->GrContextIsGL()); DCHECK(context_state->GrContextIsGL());
DCHECK(hardware_buffer_handle_.is_valid());
auto* texture = GenGLTexture(); auto* texture = GenGLTexture(hardware_buffer_handle_.get(), GL_TEXTURE_2D,
color_space(), size(), ClearedRect());
if (!texture) if (!texture)
return nullptr; return nullptr;
auto gl_representation = auto gl_representation =
...@@ -759,64 +768,6 @@ void SharedImageBackingAHB::EndOverlayAccess() { ...@@ -759,64 +768,6 @@ void SharedImageBackingAHB::EndOverlayAccess() {
read_sync_fd_ = gl::MergeFDs(std::move(read_sync_fd_), std::move(fence_fd)); read_sync_fd_ = gl::MergeFDs(std::move(read_sync_fd_), std::move(fence_fd));
} }
gles2::Texture* SharedImageBackingAHB::GenGLTexture() {
DCHECK(hardware_buffer_handle_.is_valid());
// Target for AHB backed egl images.
// Note that we are not using GL_TEXTURE_EXTERNAL_OES target since sksurface
// doesn't supports it. As per the egl documentation -
// https://www.khronos.org/registry/OpenGL/extensions/OES/OES_EGL_image_external.txt
// if GL_OES_EGL_image is supported then <target> may also be TEXTURE_2D.
GLenum target = GL_TEXTURE_2D;
GLenum get_target = GL_TEXTURE_BINDING_2D;
// Create a gles2 texture using the AhardwareBuffer.
gl::GLApi* api = gl::g_current_gl_context;
GLuint service_id = 0;
api->glGenTexturesFn(1, &service_id);
GLint old_texture_binding = 0;
api->glGetIntegervFn(get_target, &old_texture_binding);
api->glBindTextureFn(target, service_id);
api->glTexParameteriFn(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
api->glTexParameteriFn(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
api->glTexParameteriFn(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
api->glTexParameteriFn(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Create an egl image using AHardwareBuffer.
auto egl_image = base::MakeRefCounted<gl::GLImageAHardwareBuffer>(size());
if (!egl_image->Initialize(hardware_buffer_handle_.get(), false)) {
LOG(ERROR) << "Failed to create EGL image";
api->glBindTextureFn(target, old_texture_binding);
api->glDeleteTexturesFn(1, &service_id);
return nullptr;
}
if (!egl_image->BindTexImage(target)) {
LOG(ERROR) << "Failed to bind egl image";
api->glBindTextureFn(target, old_texture_binding);
api->glDeleteTexturesFn(1, &service_id);
return nullptr;
}
egl_image->SetColorSpace(color_space());
// Create a gles2 Texture.
auto* texture = new gles2::Texture(service_id);
texture->SetLightweightRef();
texture->SetTarget(target, 1);
texture->sampler_state_.min_filter = GL_LINEAR;
texture->sampler_state_.mag_filter = GL_LINEAR;
texture->sampler_state_.wrap_t = GL_CLAMP_TO_EDGE;
texture->sampler_state_.wrap_s = GL_CLAMP_TO_EDGE;
texture->SetLevelInfo(target, 0, egl_image->GetInternalFormat(),
size().width(), size().height(), 1, 0,
egl_image->GetDataFormat(), egl_image->GetDataType(),
ClearedRect());
texture->SetLevelImage(target, 0, egl_image.get(), gles2::Texture::BOUND);
texture->SetImmutable(true, false);
api->glBindTextureFn(target, old_texture_binding);
return texture;
}
SharedImageBackingFactoryAHB::SharedImageBackingFactoryAHB( SharedImageBackingFactoryAHB::SharedImageBackingFactoryAHB(
const GpuDriverBugWorkarounds& workarounds, const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info) { const GpuFeatureInfo& gpu_feature_info) {
......
...@@ -753,10 +753,10 @@ SharedImageBackingGLImage::ProduceRGBEmulationGLTexture( ...@@ -753,10 +753,10 @@ SharedImageBackingGLImage::ProduceRGBEmulationGLTexture(
rgb_emulation_texture_ = new gles2::Texture(service_id); rgb_emulation_texture_ = new gles2::Texture(service_id);
rgb_emulation_texture_->SetLightweightRef(); rgb_emulation_texture_->SetLightweightRef();
rgb_emulation_texture_->SetTarget(target, 1); rgb_emulation_texture_->SetTarget(target, 1);
rgb_emulation_texture_->sampler_state_.min_filter = GL_LINEAR; rgb_emulation_texture_->set_min_filter(GL_LINEAR);
rgb_emulation_texture_->sampler_state_.mag_filter = GL_LINEAR; rgb_emulation_texture_->set_mag_filter(GL_LINEAR);
rgb_emulation_texture_->sampler_state_.wrap_s = GL_CLAMP_TO_EDGE; rgb_emulation_texture_->set_wrap_t(GL_CLAMP_TO_EDGE);
rgb_emulation_texture_->sampler_state_.wrap_t = GL_CLAMP_TO_EDGE; rgb_emulation_texture_->set_wrap_s(GL_CLAMP_TO_EDGE);
GLenum format = GLenum format =
gles2::TextureManager::ExtractFormatFromStorageFormat(internal_format); gles2::TextureManager::ExtractFormatFromStorageFormat(internal_format);
...@@ -1092,10 +1092,10 @@ bool SharedImageBackingGLCommon::InitializeGLTexture( ...@@ -1092,10 +1092,10 @@ bool SharedImageBackingGLCommon::InitializeGLTexture(
texture_ = new gles2::Texture(service_id); texture_ = new gles2::Texture(service_id);
texture_->SetLightweightRef(); texture_->SetLightweightRef();
texture_->SetTarget(params.target, 1); texture_->SetTarget(params.target, 1);
texture_->sampler_state_.min_filter = GL_LINEAR; texture_->set_min_filter(GL_LINEAR);
texture_->sampler_state_.mag_filter = GL_LINEAR; texture_->set_mag_filter(GL_LINEAR);
texture_->sampler_state_.wrap_s = GL_CLAMP_TO_EDGE; texture_->set_wrap_t(GL_CLAMP_TO_EDGE);
texture_->sampler_state_.wrap_t = GL_CLAMP_TO_EDGE; texture_->set_wrap_s(GL_CLAMP_TO_EDGE);
texture_->SetLevelInfo(params.target, 0, params.internal_format, texture_->SetLevelInfo(params.target, 0, params.internal_format,
size().width(), size().height(), 1, 0, params.format, size().width(), size().height(), 1, 0, params.format,
params.type, params.type,
...@@ -1125,7 +1125,6 @@ bool SharedImageBackingGLImage::InitializeGLTexture( ...@@ -1125,7 +1125,6 @@ bool SharedImageBackingGLImage::InitializeGLTexture(
} else { } else {
is_bound = image_->BindTexImage(params.target); is_bound = image_->BindTexImage(params.target);
} }
if (is_bound) { if (is_bound) {
image_state = gles2::Texture::BOUND; image_state = gles2::Texture::BOUND;
} else { } else {
......
...@@ -610,10 +610,10 @@ class SharedImageBackingIOSurface : public ClearTrackingSharedImageBacking { ...@@ -610,10 +610,10 @@ class SharedImageBackingIOSurface : public ClearTrackingSharedImageBacking {
*texture = new gles2::Texture(service_id); *texture = new gles2::Texture(service_id);
(*texture)->SetLightweightRef(); (*texture)->SetLightweightRef();
(*texture)->SetTarget(GL_TEXTURE_RECTANGLE, 1); (*texture)->SetTarget(GL_TEXTURE_RECTANGLE, 1);
(*texture)->sampler_state_.min_filter = GL_LINEAR; (*texture)->set_min_filter(GL_LINEAR);
(*texture)->sampler_state_.mag_filter = GL_LINEAR; (*texture)->set_mag_filter(GL_LINEAR);
(*texture)->sampler_state_.wrap_t = GL_CLAMP_TO_EDGE; (*texture)->set_wrap_t(GL_CLAMP_TO_EDGE);
(*texture)->sampler_state_.wrap_s = GL_CLAMP_TO_EDGE; (*texture)->set_wrap_s(GL_CLAMP_TO_EDGE);
(*texture)->SetLevelInfo(GL_TEXTURE_RECTANGLE, 0, gl_info.internal_format, (*texture)->SetLevelInfo(GL_TEXTURE_RECTANGLE, 0, gl_info.internal_format,
size().width(), size().height(), 1, 0, size().width(), size().height(), 1, 0,
gl_info.format, gl_info.type, cleared_rect); gl_info.format, gl_info.type, cleared_rect);
......
...@@ -63,10 +63,10 @@ SharedImageRepresentationGLOzone::Create( ...@@ -63,10 +63,10 @@ SharedImageRepresentationGLOzone::Create(
gles2::Texture* texture = new gles2::Texture(gl_texture_service_id); gles2::Texture* texture = new gles2::Texture(gl_texture_service_id);
texture->SetLightweightRef(); texture->SetLightweightRef();
texture->SetTarget(GL_TEXTURE_2D, 1 /*max_levels=*/); texture->SetTarget(GL_TEXTURE_2D, 1 /*max_levels=*/);
texture->sampler_state_.min_filter = GL_LINEAR; texture->set_min_filter(GL_LINEAR);
texture->sampler_state_.mag_filter = GL_LINEAR; texture->set_mag_filter(GL_LINEAR);
texture->sampler_state_.wrap_t = GL_CLAMP_TO_EDGE; texture->set_wrap_t(GL_CLAMP_TO_EDGE);
texture->sampler_state_.wrap_s = GL_CLAMP_TO_EDGE; texture->set_wrap_s(GL_CLAMP_TO_EDGE);
GLenum gl_format = viz::GLDataFormat(format); GLenum gl_format = viz::GLDataFormat(format);
GLenum gl_type = viz::GLDataType(format); GLenum gl_type = viz::GLDataType(format);
......
...@@ -146,10 +146,10 @@ TestSharedImageBacking::TestSharedImageBacking( ...@@ -146,10 +146,10 @@ TestSharedImageBacking::TestSharedImageBacking(
texture_ = new gles2::Texture(service_id_); texture_ = new gles2::Texture(service_id_);
texture_->SetLightweightRef(); texture_->SetLightweightRef();
texture_->SetTarget(GL_TEXTURE_2D, 1); texture_->SetTarget(GL_TEXTURE_2D, 1);
texture_->sampler_state_.min_filter = GL_LINEAR; texture_->set_min_filter(GL_LINEAR);
texture_->sampler_state_.mag_filter = GL_LINEAR; texture_->set_mag_filter(GL_LINEAR);
texture_->sampler_state_.wrap_s = GL_CLAMP_TO_EDGE; texture_->set_wrap_t(GL_CLAMP_TO_EDGE);
texture_->sampler_state_.wrap_t = GL_CLAMP_TO_EDGE; texture_->set_wrap_s(GL_CLAMP_TO_EDGE);
texture_->SetLevelInfo(GL_TEXTURE_2D, 0, GLInternalFormat(format), texture_->SetLevelInfo(GL_TEXTURE_2D, 0, GLInternalFormat(format),
size.width(), size.height(), 1, 0, size.width(), size.height(), 1, 0,
GLDataFormat(format), GLDataType(format), gfx::Rect()); GLDataFormat(format), GLDataType(format), gfx::Rect());
......
...@@ -35,25 +35,7 @@ class ProgressReporter; ...@@ -35,25 +35,7 @@ class ProgressReporter;
namespace gpu { namespace gpu {
class DecoderContext; class DecoderContext;
class ExternalVkImageBacking;
class ExternalVkImageGlRepresentation;
class ServiceDiscardableManager; class ServiceDiscardableManager;
class SharedImageBackingGLCommon;
class SharedImageBackingGLImage;
class SharedImageBackingFactoryGLTexture;
class SharedImageBackingAHB;
class SharedImageBackingEglImage;
class SharedImageRepresentationGLTexture;
class SharedImageRepresentationEglImageGLTexture;
class SharedImageRepresentationGLTextureAHB;
class SharedImageRepresentationSkiaGLAHB;
class SharedImageBackingIOSurface;
class SharedImageRepresentationGLTextureIOSurface;
class SharedImageRepresentationSkiaIOSurface;
class SharedImageRepresentationGLOzone;
class SharedImageVideo;
class StreamTexture;
class TestSharedImageBacking;
namespace gles2 { namespace gles2 {
class GLStreamTextureImage; class GLStreamTextureImage;
...@@ -188,6 +170,28 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase { ...@@ -188,6 +170,28 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase {
GLenum alpha; GLenum alpha;
}; };
struct LevelInfo {
LevelInfo();
LevelInfo(const LevelInfo& rhs);
~LevelInfo();
gfx::Rect cleared_rect;
GLenum target = 0;
GLint level = -1;
GLenum internal_format = 0;
GLsizei width = 0;
GLsizei height = 0;
GLsizei depth = 0;
GLint border = 0;
GLenum format = 0;
GLenum type = 0;
scoped_refptr<gl::GLImage> image;
scoped_refptr<GLStreamTextureImage> stream_texture_image;
ImageState image_state = UNBOUND;
uint32_t estimated_size = 0;
bool internal_workaround = false;
};
explicit Texture(GLuint service_id); explicit Texture(GLuint service_id);
// TextureBase implementation: // TextureBase implementation:
...@@ -199,22 +203,36 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase { ...@@ -199,22 +203,36 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase {
return sampler_state_; return sampler_state_;
} }
void set_min_filter(GLenum min_filter) {
sampler_state_.min_filter = min_filter;
}
GLenum min_filter() const { GLenum min_filter() const {
return sampler_state_.min_filter; return sampler_state_.min_filter;
} }
void set_mag_filter(GLenum mag_filter) {
sampler_state_.mag_filter = mag_filter;
}
GLenum mag_filter() const { GLenum mag_filter() const {
return sampler_state_.mag_filter; return sampler_state_.mag_filter;
} }
void set_wrap_r(GLenum wrap_r) { sampler_state_.wrap_r = wrap_r; }
GLenum wrap_r() const { GLenum wrap_r() const {
return sampler_state_.wrap_r; return sampler_state_.wrap_r;
} }
void set_wrap_s(GLenum wrap_s) { sampler_state_.wrap_s = wrap_s; }
GLenum wrap_s() const { GLenum wrap_s() const {
return sampler_state_.wrap_s; return sampler_state_.wrap_s;
} }
void set_wrap_t(GLenum wrap_t) { sampler_state_.wrap_t = wrap_t; }
GLenum wrap_t() const { GLenum wrap_t() const {
return sampler_state_.wrap_t; return sampler_state_.wrap_t;
} }
...@@ -430,27 +448,43 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase { ...@@ -430,27 +448,43 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase {
// Returns GL_NONE on error. // Returns GL_NONE on error.
GLenum GetInternalFormatOfBaseLevel() const; GLenum GetInternalFormatOfBaseLevel() const;
void SetLightweightRef();
void RemoveLightweightRef(bool have_context);
// Set the info for a particular level.
void SetLevelInfo(GLenum target,
GLint level,
GLenum internal_format,
GLsizei width,
GLsizei height,
GLsizei depth,
GLint border,
GLenum format,
GLenum type,
const gfx::Rect& cleared_rect);
// Returns the LevelInfo for |target| and |level| if it's set, else nullptr.
const LevelInfo* GetLevelInfo(GLint target, GLint level) const;
// Sets the Texture's target
// Parameters:
// target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP or
// GL_TEXTURE_EXTERNAL_OES or GL_TEXTURE_RECTANGLE_ARB
// GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3)
// max_levels: The maximum levels this type of target can have.
void SetTarget(GLenum target, GLint max_levels);
void SetCompatibilitySwizzle(const CompatibilitySwizzle* swizzle);
bool NeedsMips() const {
return sampler_state_.min_filter != GL_NEAREST &&
sampler_state_.min_filter != GL_LINEAR;
}
private: private:
friend class MailboxManagerSync; friend class MailboxManagerSync;
friend class MailboxManagerTest; friend class MailboxManagerTest;
friend class gpu::ExternalVkImageBacking;
friend class gpu::ExternalVkImageGlRepresentation;
friend class gpu::SharedImageVideo;
friend class gpu::SharedImageBackingGLCommon;
friend class gpu::SharedImageBackingGLImage;
friend class gpu::SharedImageBackingFactoryGLTexture;
friend class gpu::SharedImageBackingAHB;
friend class gpu::SharedImageBackingEglImage;
friend class gpu::SharedImageRepresentationGLTextureAHB;
friend class gpu::SharedImageRepresentationEglImageGLTexture;
friend class gpu::SharedImageRepresentationSkiaGLAHB;
friend class gpu::SharedImageBackingIOSurface;
friend class gpu::SharedImageRepresentationGLTextureIOSurface;
friend class gpu::SharedImageRepresentationSkiaIOSurface;
friend class gpu::SharedImageRepresentationGLOzone;
friend class gpu::StreamTexture;
friend class gpu::TestSharedImageBacking;
friend class AbstractTextureImplOnSharedContext;
friend class TextureDefinition; friend class TextureDefinition;
friend class TextureManager; friend class TextureManager;
friend class TextureRef; friend class TextureRef;
...@@ -460,8 +494,6 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase { ...@@ -460,8 +494,6 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase {
~Texture() override; ~Texture() override;
void AddTextureRef(TextureRef* ref); void AddTextureRef(TextureRef* ref);
void RemoveTextureRef(TextureRef* ref, bool have_context); void RemoveTextureRef(TextureRef* ref, bool have_context);
void SetLightweightRef();
void RemoveLightweightRef(bool have_context);
void MaybeDeleteThis(bool have_context); void MaybeDeleteThis(bool have_context);
// Condition on which this texture is renderable. Can be ONLY_IF_NPOT if it // Condition on which this texture is renderable. Can be ONLY_IF_NPOT if it
...@@ -476,28 +508,6 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase { ...@@ -476,28 +508,6 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase {
CAN_RENDER_NEEDS_VALIDATION, CAN_RENDER_NEEDS_VALIDATION,
}; };
struct LevelInfo {
LevelInfo();
LevelInfo(const LevelInfo& rhs);
~LevelInfo();
gfx::Rect cleared_rect;
GLenum target;
GLint level;
GLenum internal_format;
GLsizei width;
GLsizei height;
GLsizei depth;
GLint border;
GLenum format;
GLenum type;
scoped_refptr<gl::GLImage> image;
scoped_refptr<GLStreamTextureImage> stream_texture_image;
ImageState image_state;
uint32_t estimated_size;
bool internal_workaround;
};
struct FaceInfo { struct FaceInfo {
FaceInfo(); FaceInfo();
FaceInfo(const FaceInfo& other); FaceInfo(const FaceInfo& other);
...@@ -516,23 +526,9 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase { ...@@ -516,23 +526,9 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase {
GLStreamTextureImage* stream_texture_image, GLStreamTextureImage* stream_texture_image,
ImageState state); ImageState state);
// Returns the LevelInfo for |target| and |level| if it's set, else NULL.
const LevelInfo* GetLevelInfo(GLint target, GLint level) const;
// Returns NULL if the base level is not defined. // Returns NULL if the base level is not defined.
const LevelInfo* GetBaseLevelInfo() const; const LevelInfo* GetBaseLevelInfo() const;
// Set the info for a particular level.
void SetLevelInfo(GLenum target,
GLint level,
GLenum internal_format,
GLsizei width,
GLsizei height,
GLsizei depth,
GLint border,
GLenum format,
GLenum type,
const gfx::Rect& cleared_rect);
// Causes us to report |service_id| as our service id, but does not delete // Causes us to report |service_id| as our service id, but does not delete
// it when we are destroyed. Will rebind any OES_EXTERNAL texture units to // it when we are destroyed. Will rebind any OES_EXTERNAL texture units to
// our new service id in all contexts. If |service_id| is zero, then we // our new service id in all contexts. If |service_id| is zero, then we
...@@ -575,11 +571,6 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase { ...@@ -575,11 +571,6 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase {
// Makes each of the mip levels as though they were generated. // Makes each of the mip levels as though they were generated.
void MarkMipmapsGenerated(); void MarkMipmapsGenerated();
bool NeedsMips() const {
return sampler_state_.min_filter != GL_NEAREST &&
sampler_state_.min_filter != GL_LINEAR;
}
// True if this texture meets all the GLES2 criteria for rendering. // True if this texture meets all the GLES2 criteria for rendering.
// See section 3.8.2 of the GLES2 spec. // See section 3.8.2 of the GLES2 spec.
bool CanRender(const FeatureInfo* feature_info) const; bool CanRender(const FeatureInfo* feature_info) const;
...@@ -620,14 +611,6 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase { ...@@ -620,14 +611,6 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase {
GLenum type, GLenum type,
bool immutable); bool immutable);
// Sets the Texture's target
// Parameters:
// target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP or
// GL_TEXTURE_EXTERNAL_OES or GL_TEXTURE_RECTANGLE_ARB
// GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3)
// max_levels: The maximum levels this type of target can have.
void SetTarget(GLenum target, GLint max_levels);
// Update info about this texture. // Update info about this texture.
void Update(); void Update();
...@@ -684,7 +667,6 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase { ...@@ -684,7 +667,6 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase {
GLuint owned_service_id() const { return owned_service_id_; } GLuint owned_service_id() const { return owned_service_id_; }
GLenum GetCompatibilitySwizzleForChannel(GLenum channel); GLenum GetCompatibilitySwizzleForChannel(GLenum channel);
void SetCompatibilitySwizzle(const CompatibilitySwizzle* swizzle);
// Info about each face and level of texture. // Info about each face and level of texture.
std::vector<FaceInfo> face_infos_; std::vector<FaceInfo> face_infos_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment