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

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

Issue 2945673002: Allow creating GLImage-backed textures with glTexStorage2D. (Closed)
Patch Set: rebase Created 3 years, 4 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
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 best_texture_format = viz::RGBA_8888; 375 best_texture_format = viz::RGBA_8888;
376 return; 376 return;
377 } 377 }
378 378
379 DCHECK(IsGpuResourceType(default_resource_type)); 379 DCHECK(IsGpuResourceType(default_resource_type));
380 380
381 const auto& caps = compositor_context_provider->ContextCapabilities(); 381 const auto& caps = compositor_context_provider->ContextCapabilities();
382 use_texture_storage_ext = caps.texture_storage; 382 use_texture_storage_ext = caps.texture_storage;
383 use_texture_format_bgra = caps.texture_format_bgra8888; 383 use_texture_format_bgra = caps.texture_format_bgra8888;
384 use_texture_usage_hint = caps.texture_usage; 384 use_texture_usage_hint = caps.texture_usage;
385 use_texture_buffer_chromium = caps.texture_buffer_chromium;
385 use_sync_query = caps.sync_query; 386 use_sync_query = caps.sync_query;
386 387
387 if (caps.disable_one_component_textures) { 388 if (caps.disable_one_component_textures) {
388 yuv_resource_format = yuv_highbit_resource_format = viz::RGBA_8888; 389 yuv_resource_format = yuv_highbit_resource_format = viz::RGBA_8888;
389 } else { 390 } else {
390 yuv_resource_format = caps.texture_rg ? viz::RED_8 : viz::LUMINANCE_8; 391 yuv_resource_format = caps.texture_rg ? viz::RED_8 : viz::LUMINANCE_8;
391 yuv_highbit_resource_format = caps.texture_half_float_linear 392 yuv_highbit_resource_format = caps.texture_half_float_linear
392 ? viz::LUMINANCE_F16 393 ? viz::LUMINANCE_F16
393 : yuv_resource_format; 394 : yuv_resource_format;
394 } 395 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 } 561 }
561 562
562 viz::ResourceId ResourceProvider::CreateResource( 563 viz::ResourceId ResourceProvider::CreateResource(
563 const gfx::Size& size, 564 const gfx::Size& size,
564 TextureHint hint, 565 TextureHint hint,
565 viz::ResourceFormat format, 566 viz::ResourceFormat format,
566 const gfx::ColorSpace& color_space) { 567 const gfx::ColorSpace& color_space) {
567 DCHECK(!size.IsEmpty()); 568 DCHECK(!size.IsEmpty());
568 switch (settings_.default_resource_type) { 569 switch (settings_.default_resource_type) {
569 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: 570 case RESOURCE_TYPE_GPU_MEMORY_BUFFER:
570 // GPU memory buffers don't support viz::LUMINANCE_F16 yet. 571 // GPU memory buffers don't support LUMINANCE_F16 yet.
571 if (format != viz::LUMINANCE_F16) { 572 if (format != viz::LUMINANCE_F16) {
572 return CreateGLTexture( 573 TextureHint new_hint =
573 size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, format, 574 static_cast<TextureHint>(hint | TEXTURE_HINT_IMAGE);
574 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, color_space); 575 return CreateGLTexture(size, new_hint, RESOURCE_TYPE_GL_TEXTURE, format,
576 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE,
577 color_space);
575 } 578 }
576 // Fall through and use a regular texture. 579 // Fall through and use a regular texture.
577 case RESOURCE_TYPE_GL_TEXTURE: 580 case RESOURCE_TYPE_GL_TEXTURE:
578 return CreateGLTexture(size, hint, RESOURCE_TYPE_GL_TEXTURE, format, 581 return CreateGLTexture(size, hint, RESOURCE_TYPE_GL_TEXTURE, format,
579 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, 582 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE,
580 color_space); 583 color_space);
581 584
582 case RESOURCE_TYPE_BITMAP: 585 case RESOURCE_TYPE_BITMAP:
583 DCHECK_EQ(viz::RGBA_8888, format); 586 DCHECK_EQ(viz::RGBA_8888, format);
584 return CreateBitmap(size, color_space); 587 return CreateBitmap(size, color_space);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 viz::ResourceFormat format, 620 viz::ResourceFormat format,
618 gfx::BufferUsage usage, 621 gfx::BufferUsage usage,
619 const gfx::ColorSpace& color_space) { 622 const gfx::ColorSpace& color_space) {
620 DCHECK_LE(size.width(), settings_.max_texture_size); 623 DCHECK_LE(size.width(), settings_.max_texture_size);
621 DCHECK_LE(size.height(), settings_.max_texture_size); 624 DCHECK_LE(size.height(), settings_.max_texture_size);
622 DCHECK(thread_checker_.CalledOnValidThread()); 625 DCHECK(thread_checker_.CalledOnValidThread());
623 626
624 // TODO(crbug.com/590317): We should not assume that all resources created by 627 // TODO(crbug.com/590317): We should not assume that all resources created by
625 // ResourceProvider are GPU_READ_CPU_READ_WRITE. We should determine this 628 // ResourceProvider are GPU_READ_CPU_READ_WRITE. We should determine this
626 // based on the current RasterBufferProvider's needs. 629 // based on the current RasterBufferProvider's needs.
627 GLenum target = type == RESOURCE_TYPE_GPU_MEMORY_BUFFER 630 GLenum target =
628 ? GetImageTextureTarget(usage, format) 631 type == RESOURCE_TYPE_GPU_MEMORY_BUFFER || (hint & TEXTURE_HINT_IMAGE)
629 : GL_TEXTURE_2D; 632 ? GetImageTextureTarget(usage, format)
633 : GL_TEXTURE_2D;
630 634
631 viz::ResourceId id = next_id_++; 635 viz::ResourceId id = next_id_++;
632 Resource* resource = 636 Resource* resource =
633 InsertResource(id, Resource(0, size, Resource::INTERNAL, target, 637 InsertResource(id, Resource(0, size, Resource::INTERNAL, target,
634 GL_LINEAR, hint, type, format)); 638 GL_LINEAR, hint, type, format));
635 resource->usage = usage; 639 resource->usage = usage;
636 resource->allocated = false; 640 resource->allocated = false;
637 resource->color_space = color_space; 641 resource->color_space = color_space;
638 return id; 642 return id;
639 } 643 }
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 if (resource->allocated) 1927 if (resource->allocated)
1924 return; 1928 return;
1925 LazyCreate(resource); 1929 LazyCreate(resource);
1926 if (!resource->gl_id) 1930 if (!resource->gl_id)
1927 return; 1931 return;
1928 resource->allocated = true; 1932 resource->allocated = true;
1929 GLES2Interface* gl = ContextGL(); 1933 GLES2Interface* gl = ContextGL();
1930 gfx::Size& size = resource->size; 1934 gfx::Size& size = resource->size;
1931 viz::ResourceFormat format = resource->format; 1935 viz::ResourceFormat format = resource->format;
1932 gl->BindTexture(resource->target, resource->gl_id); 1936 gl->BindTexture(resource->target, resource->gl_id);
1933 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { 1937 bool can_use_texture_storage =
1938 (settings_.use_texture_storage_ext &&
1939 IsFormatSupportedForStorage(format, settings_.use_texture_format_bgra) &&
1940 (resource->hint & TEXTURE_HINT_IMMUTABLE));
1941 bool can_use_texture_buffer =
1942 can_use_texture_storage && settings_.use_texture_buffer_chromium;
1943 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER ||
1944 ((resource->hint & TEXTURE_HINT_IMAGE) && !can_use_texture_buffer)) {
1934 resource->gpu_memory_buffer = 1945 resource->gpu_memory_buffer =
1935 gpu_memory_buffer_manager_->CreateGpuMemoryBuffer( 1946 gpu_memory_buffer_manager_->CreateGpuMemoryBuffer(
1936 size, BufferFormat(format), resource->usage, 1947 size, BufferFormat(format), resource->usage,
1937 gpu::kNullSurfaceHandle); 1948 gpu::kNullSurfaceHandle);
1938 // Note that this impacts overlay compositing, not rasterization. 1949 // Note that this impacts overlay compositing, not rasterization.
1939 if (resource->gpu_memory_buffer && 1950 if (resource->gpu_memory_buffer &&
1940 settings_.enable_color_correct_rasterization) { 1951 settings_.enable_color_correct_rasterization) {
1941 resource->gpu_memory_buffer->SetColorSpaceForScanout( 1952 resource->gpu_memory_buffer->SetColorSpaceForScanout(
1942 resource->color_space); 1953 resource->color_space);
1943 } 1954 }
1944 1955
1945 LazyCreateImage(resource); 1956 LazyCreateImage(resource);
1946 resource->dirty_image = true; 1957 resource->dirty_image = true;
1947 resource->is_overlay_candidate = true; 1958 resource->is_overlay_candidate = true;
1948 // GpuMemoryBuffer provides direct access to the memory used by the GPU. 1959 // GpuMemoryBuffer provides direct access to the memory used by the GPU.
1949 // Read lock fences are required to ensure that we're not trying to map a 1960 // Read lock fences are required to ensure that we're not trying to map a
1950 // buffer that is currently in-use by the GPU. 1961 // buffer that is currently in-use by the GPU.
1951 resource->read_lock_fences_enabled = true; 1962 resource->read_lock_fences_enabled = true;
1952 } else if (settings_.use_texture_storage_ext && 1963 } else if (can_use_texture_storage) {
1953 IsFormatSupportedForStorage(format,
1954 settings_.use_texture_format_bgra) &&
1955 (resource->hint & TEXTURE_HINT_IMMUTABLE)) {
1956 GLenum storage_format = TextureToStorageFormat(format); 1964 GLenum storage_format = TextureToStorageFormat(format);
1965 if (resource->hint & TEXTURE_HINT_IMAGE) {
1966 DCHECK(settings_.use_texture_buffer_chromium);
1967 gl->TexParameteri(resource->target, GL_TEXTURE_BUFFER_USAGE_CHROMIUM,
1968 GL_TEXTURE_BUFFER_SCANOUT_CHROMIUM);
1969 resource->is_overlay_candidate = true;
1970 }
1971
1957 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), 1972 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(),
1958 size.height()); 1973 size.height());
1974 if ((resource->hint & TEXTURE_HINT_IMAGE) &&
1975 settings_.enable_color_correct_rasterization) {
1976 gl->SetColorSpaceForScanoutCHROMIUM(
1977 resource->gl_id,
1978 reinterpret_cast<GLColorSpace>(&resource->color_space));
1979 }
1959 } else { 1980 } else {
1960 // viz::ETC1 does not support preallocation. 1981 // viz::ETC1 does not support preallocation.
1961 if (format != viz::ETC1) { 1982 if (format != viz::ETC1) {
1962 gl->TexImage2D(resource->target, 0, GLInternalFormat(format), 1983 gl->TexImage2D(resource->target, 0, GLInternalFormat(format),
1963 size.width(), size.height(), 0, GLDataFormat(format), 1984 size.width(), size.height(), 0, GLDataFormat(format),
1964 GLDataType(format), nullptr); 1985 GLDataType(format), nullptr);
1965 } 1986 }
1966 } 1987 }
1967 } 1988 }
1968 1989
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2133 } else { 2154 } else {
2134 pmd->CreateSharedGlobalAllocatorDump(guid); 2155 pmd->CreateSharedGlobalAllocatorDump(guid);
2135 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); 2156 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
2136 } 2157 }
2137 } 2158 }
2138 2159
2139 return true; 2160 return true;
2140 } 2161 }
2141 2162
2142 } // namespace cc 2163 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698