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