Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Unified Diff: cc/resources/resource_provider.cc

Issue 2945673002: Allow creating GLImage-backed textures with glTexStorage2D. (Closed)
Patch Set: add test Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/resources/resource_provider.cc
diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc
index 505df05948e1334bf546679ad951587d6104d34d..dfa5d624c6b43ce0b1cb73cb34205a92fa594aa4 100644
--- a/cc/resources/resource_provider.cc
+++ b/cc/resources/resource_provider.cc
@@ -579,9 +579,11 @@ ResourceId ResourceProvider::CreateResource(
case RESOURCE_TYPE_GPU_MEMORY_BUFFER:
// GPU memory buffers don't support LUMINANCE_F16 yet.
if (format != LUMINANCE_F16) {
- return CreateGLTexture(
- size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, format,
- gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, color_space);
+ TextureHint new_hint =
+ static_cast<TextureHint>(hint | TEXTURE_HINT_IMAGE);
+ return CreateGLTexture(size, new_hint, RESOURCE_TYPE_GL_TEXTURE, format,
+ gfx::BufferUsage::GPU_READ_CPU_READ_WRITE,
+ color_space);
}
// Fall through and use a regular texture.
case RESOURCE_TYPE_GL_TEXTURE:
@@ -634,9 +636,10 @@ ResourceId ResourceProvider::CreateGLTexture(
// TODO(crbug.com/590317): We should not assume that all resources created by
// ResourceProvider are GPU_READ_CPU_READ_WRITE. We should determine this
// based on the current RasterBufferProvider's needs.
- GLenum target = type == RESOURCE_TYPE_GPU_MEMORY_BUFFER
- ? GetImageTextureTarget(usage, format)
- : GL_TEXTURE_2D;
+ GLenum target =
+ type == RESOURCE_TYPE_GPU_MEMORY_BUFFER || (hint & TEXTURE_HINT_IMAGE)
+ ? GetImageTextureTarget(usage, format)
+ : GL_TEXTURE_2D;
ResourceId id = next_id_++;
Resource* resource =
@@ -2001,7 +2004,12 @@ void ResourceProvider::LazyAllocate(Resource* resource) {
gfx::Size& size = resource->size;
ResourceFormat format = resource->format;
gl->BindTexture(resource->target, resource->gl_id);
- if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) {
+ bool can_use_texture_storage =
+ (settings_.use_texture_storage_ext &&
+ IsFormatSupportedForStorage(format, settings_.use_texture_format_bgra) &&
+ (resource->hint & TEXTURE_HINT_IMMUTABLE));
+ if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER ||
+ ((resource->hint & TEXTURE_HINT_IMAGE) && !can_use_texture_storage)) {
resource->gpu_memory_buffer =
gpu_memory_buffer_manager_->CreateGpuMemoryBuffer(
size, BufferFormat(format), resource->usage,
@@ -2020,11 +2028,13 @@ void ResourceProvider::LazyAllocate(Resource* resource) {
// Read lock fences are required to ensure that we're not trying to map a
// buffer that is currently in-use by the GPU.
resource->read_lock_fences_enabled = true;
- } else if (settings_.use_texture_storage_ext &&
- IsFormatSupportedForStorage(format,
- settings_.use_texture_format_bgra) &&
- (resource->hint & TEXTURE_HINT_IMMUTABLE)) {
+ } else if (can_use_texture_storage) {
GLenum storage_format = TextureToStorageFormat(format);
+ if (resource->hint & TEXTURE_HINT_IMAGE) {
+ gl->TexParameteri(resource->target, GL_TEXTURE_BUFFER_USAGE_CHROMIUM,
+ GL_TEXTURE_BUFFER_SCANOUT_CHROMIUM);
+ }
+
gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(),
size.height());
} else {

Powered by Google App Engine
This is Rietveld 408576698