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

Side by Side Diff: cc/resources/resource_provider.cc

Issue 2945673002: Allow creating GLImage-backed textures with glTexStorage2D. (Closed)
Patch Set: add extension spec and don't enable for webgl 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/resource_provider.h" 5 #include "cc/resources/resource_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 ResourceId ResourceProvider::CreateResource( 572 ResourceId ResourceProvider::CreateResource(
573 const gfx::Size& size, 573 const gfx::Size& size,
574 TextureHint hint, 574 TextureHint hint,
575 ResourceFormat format, 575 ResourceFormat format,
576 const gfx::ColorSpace& color_space) { 576 const gfx::ColorSpace& color_space) {
577 DCHECK(!size.IsEmpty()); 577 DCHECK(!size.IsEmpty());
578 switch (settings_.default_resource_type) { 578 switch (settings_.default_resource_type) {
579 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: 579 case RESOURCE_TYPE_GPU_MEMORY_BUFFER:
580 // GPU memory buffers don't support LUMINANCE_F16 yet. 580 // GPU memory buffers don't support LUMINANCE_F16 yet.
581 if (format != LUMINANCE_F16) { 581 if (format != LUMINANCE_F16) {
582 return CreateGLTexture( 582 TextureHint new_hint =
583 size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, format, 583 static_cast<TextureHint>(hint | TEXTURE_HINT_IMAGE);
584 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, color_space); 584 return CreateGLTexture(size, new_hint, RESOURCE_TYPE_GL_TEXTURE, format,
585 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE,
586 color_space);
585 } 587 }
586 // Fall through and use a regular texture. 588 // Fall through and use a regular texture.
587 case RESOURCE_TYPE_GL_TEXTURE: 589 case RESOURCE_TYPE_GL_TEXTURE:
588 return CreateGLTexture(size, hint, RESOURCE_TYPE_GL_TEXTURE, format, 590 return CreateGLTexture(size, hint, RESOURCE_TYPE_GL_TEXTURE, format,
589 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, 591 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE,
590 color_space); 592 color_space);
591 593
592 case RESOURCE_TYPE_BITMAP: 594 case RESOURCE_TYPE_BITMAP:
593 DCHECK_EQ(RGBA_8888, format); 595 DCHECK_EQ(RGBA_8888, format);
594 return CreateBitmap(size, color_space); 596 return CreateBitmap(size, color_space);
595 } 597 }
596 598
597 LOG(FATAL) << "Invalid default resource type."; 599 LOG(FATAL) << "Invalid default resource type.";
598 return 0; 600 return 0;
599 } 601 }
600 602
601 ResourceId ResourceProvider::CreateGpuMemoryBufferResource( 603 ResourceId ResourceProvider::CreateGpuMemoryBufferResource(
602 const gfx::Size& size, 604 const gfx::Size& size,
603 TextureHint hint, 605 TextureHint hint,
604 ResourceFormat format, 606 ResourceFormat format,
605 gfx::BufferUsage usage, 607 gfx::BufferUsage usage,
606 const gfx::ColorSpace& color_space) { 608 const gfx::ColorSpace& color_space) {
607 DCHECK(!size.IsEmpty()); 609 DCHECK(!size.IsEmpty());
608 switch (settings_.default_resource_type) { 610 switch (settings_.default_resource_type) {
609 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: 611 case RESOURCE_TYPE_GPU_MEMORY_BUFFER:
610 case RESOURCE_TYPE_GL_TEXTURE: { 612 case RESOURCE_TYPE_GL_TEXTURE: {
611 return CreateGLTexture(size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, 613 return CreateGLTexture(size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER,
ericrk 2017/06/27 00:31:30 Do we want similar logic here? Can we just move th
612 format, usage, color_space); 614 format, usage, color_space);
613 } 615 }
614 case RESOURCE_TYPE_BITMAP: 616 case RESOURCE_TYPE_BITMAP:
615 DCHECK_EQ(RGBA_8888, format); 617 DCHECK_EQ(RGBA_8888, format);
616 return CreateBitmap(size, color_space); 618 return CreateBitmap(size, color_space);
617 } 619 }
618 620
619 LOG(FATAL) << "Invalid default resource type."; 621 LOG(FATAL) << "Invalid default resource type.";
620 return 0; 622 return 0;
621 } 623 }
622 624
623 ResourceId ResourceProvider::CreateGLTexture( 625 ResourceId ResourceProvider::CreateGLTexture(
624 const gfx::Size& size, 626 const gfx::Size& size,
625 TextureHint hint, 627 TextureHint hint,
626 ResourceType type, 628 ResourceType type,
627 ResourceFormat format, 629 ResourceFormat format,
628 gfx::BufferUsage usage, 630 gfx::BufferUsage usage,
629 const gfx::ColorSpace& color_space) { 631 const gfx::ColorSpace& color_space) {
630 DCHECK_LE(size.width(), settings_.max_texture_size); 632 DCHECK_LE(size.width(), settings_.max_texture_size);
631 DCHECK_LE(size.height(), settings_.max_texture_size); 633 DCHECK_LE(size.height(), settings_.max_texture_size);
632 DCHECK(thread_checker_.CalledOnValidThread()); 634 DCHECK(thread_checker_.CalledOnValidThread());
633 635
634 // TODO(crbug.com/590317): We should not assume that all resources created by 636 // TODO(crbug.com/590317): We should not assume that all resources created by
635 // ResourceProvider are GPU_READ_CPU_READ_WRITE. We should determine this 637 // ResourceProvider are GPU_READ_CPU_READ_WRITE. We should determine this
636 // based on the current RasterBufferProvider's needs. 638 // based on the current RasterBufferProvider's needs.
637 GLenum target = type == RESOURCE_TYPE_GPU_MEMORY_BUFFER 639 GLenum target =
638 ? GetImageTextureTarget(usage, format) 640 type == RESOURCE_TYPE_GPU_MEMORY_BUFFER || (hint & TEXTURE_HINT_IMAGE)
639 : GL_TEXTURE_2D; 641 ? GetImageTextureTarget(usage, format)
642 : GL_TEXTURE_2D;
640 643
641 ResourceId id = next_id_++; 644 ResourceId id = next_id_++;
642 Resource* resource = 645 Resource* resource =
643 InsertResource(id, Resource(0, size, Resource::INTERNAL, target, 646 InsertResource(id, Resource(0, size, Resource::INTERNAL, target,
644 GL_LINEAR, hint, type, format)); 647 GL_LINEAR, hint, type, format));
645 resource->usage = usage; 648 resource->usage = usage;
646 resource->allocated = false; 649 resource->allocated = false;
647 resource->color_space = color_space; 650 resource->color_space = color_space;
648 return id; 651 return id;
649 } 652 }
(...skipping 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1994 if (resource->allocated) 1997 if (resource->allocated)
1995 return; 1998 return;
1996 LazyCreate(resource); 1999 LazyCreate(resource);
1997 if (!resource->gl_id) 2000 if (!resource->gl_id)
1998 return; 2001 return;
1999 resource->allocated = true; 2002 resource->allocated = true;
2000 GLES2Interface* gl = ContextGL(); 2003 GLES2Interface* gl = ContextGL();
2001 gfx::Size& size = resource->size; 2004 gfx::Size& size = resource->size;
2002 ResourceFormat format = resource->format; 2005 ResourceFormat format = resource->format;
2003 gl->BindTexture(resource->target, resource->gl_id); 2006 gl->BindTexture(resource->target, resource->gl_id);
2004 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { 2007 bool can_use_texture_storage =
2008 (settings_.use_texture_storage_ext &&
2009 IsFormatSupportedForStorage(format, settings_.use_texture_format_bgra) &&
2010 (resource->hint & TEXTURE_HINT_IMMUTABLE));
2011 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER ||
2012 ((resource->hint & TEXTURE_HINT_IMAGE) && !can_use_texture_storage)) {
2005 resource->gpu_memory_buffer = 2013 resource->gpu_memory_buffer =
2006 gpu_memory_buffer_manager_->CreateGpuMemoryBuffer( 2014 gpu_memory_buffer_manager_->CreateGpuMemoryBuffer(
2007 size, BufferFormat(format), resource->usage, 2015 size, BufferFormat(format), resource->usage,
2008 gpu::kNullSurfaceHandle); 2016 gpu::kNullSurfaceHandle);
2009 // Note that this impacts overlay compositing, not rasterization. 2017 // Note that this impacts overlay compositing, not rasterization.
2010 if (resource->gpu_memory_buffer && 2018 if (resource->gpu_memory_buffer &&
2011 settings_.enable_color_correct_rasterization) { 2019 settings_.enable_color_correct_rasterization) {
2012 resource->gpu_memory_buffer->SetColorSpaceForScanout( 2020 resource->gpu_memory_buffer->SetColorSpaceForScanout(
2013 resource->color_space); 2021 resource->color_space);
2014 } 2022 }
2015 2023
2016 LazyCreateImage(resource); 2024 LazyCreateImage(resource);
2017 resource->dirty_image = true; 2025 resource->dirty_image = true;
2018 resource->is_overlay_candidate = true; 2026 resource->is_overlay_candidate = true;
2019 // GpuMemoryBuffer provides direct access to the memory used by the GPU. 2027 // GpuMemoryBuffer provides direct access to the memory used by the GPU.
2020 // Read lock fences are required to ensure that we're not trying to map a 2028 // Read lock fences are required to ensure that we're not trying to map a
2021 // buffer that is currently in-use by the GPU. 2029 // buffer that is currently in-use by the GPU.
2022 resource->read_lock_fences_enabled = true; 2030 resource->read_lock_fences_enabled = true;
2023 } else if (settings_.use_texture_storage_ext && 2031 } else if (can_use_texture_storage) {
2024 IsFormatSupportedForStorage(format,
2025 settings_.use_texture_format_bgra) &&
2026 (resource->hint & TEXTURE_HINT_IMMUTABLE)) {
2027 GLenum storage_format = TextureToStorageFormat(format); 2032 GLenum storage_format = TextureToStorageFormat(format);
2033 if (resource->hint & TEXTURE_HINT_IMAGE) {
2034 gl->TexParameteri(resource->target, GL_TEXTURE_BUFFER_USAGE_CHROMIUM,
2035 GL_TEXTURE_BUFFER_SCANOUT_CHROMIUM);
2036 }
2037
2028 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), 2038 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(),
2029 size.height()); 2039 size.height());
2030 } else { 2040 } else {
2031 // ETC1 does not support preallocation. 2041 // ETC1 does not support preallocation.
2032 if (format != ETC1) { 2042 if (format != ETC1) {
2033 gl->TexImage2D(resource->target, 0, GLInternalFormat(format), 2043 gl->TexImage2D(resource->target, 0, GLInternalFormat(format),
2034 size.width(), size.height(), 0, GLDataFormat(format), 2044 size.width(), size.height(), 0, GLDataFormat(format),
2035 GLDataType(format), nullptr); 2045 GLDataType(format), nullptr);
2036 } 2046 }
2037 } 2047 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2202 } else { 2212 } else {
2203 pmd->CreateSharedGlobalAllocatorDump(guid); 2213 pmd->CreateSharedGlobalAllocatorDump(guid);
2204 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); 2214 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
2205 } 2215 }
2206 } 2216 }
2207 2217
2208 return true; 2218 return true;
2209 } 2219 }
2210 2220
2211 } // namespace cc 2221 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.h ('k') | gpu/GLES2/extensions/CHROMIUM/CHROMIUM_texture_buffer.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698