| 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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 best_texture_format = viz::RGBA_8888; | 384 best_texture_format = viz::RGBA_8888; |
| 385 return; | 385 return; |
| 386 } | 386 } |
| 387 | 387 |
| 388 DCHECK(IsGpuResourceType(default_resource_type)); | 388 DCHECK(IsGpuResourceType(default_resource_type)); |
| 389 | 389 |
| 390 const auto& caps = compositor_context_provider->ContextCapabilities(); | 390 const auto& caps = compositor_context_provider->ContextCapabilities(); |
| 391 use_texture_storage_ext = caps.texture_storage; | 391 use_texture_storage_ext = caps.texture_storage; |
| 392 use_texture_format_bgra = caps.texture_format_bgra8888; | 392 use_texture_format_bgra = caps.texture_format_bgra8888; |
| 393 use_texture_usage_hint = caps.texture_usage; | 393 use_texture_usage_hint = caps.texture_usage; |
| 394 use_texture_buffer_chromium = caps.texture_buffer_chromium; |
| 394 use_sync_query = caps.sync_query; | 395 use_sync_query = caps.sync_query; |
| 395 | 396 |
| 396 if (caps.disable_one_component_textures) { | 397 if (caps.disable_one_component_textures) { |
| 397 yuv_resource_format = yuv_highbit_resource_format = viz::RGBA_8888; | 398 yuv_resource_format = yuv_highbit_resource_format = viz::RGBA_8888; |
| 398 } else { | 399 } else { |
| 399 yuv_resource_format = caps.texture_rg ? viz::RED_8 : viz::LUMINANCE_8; | 400 yuv_resource_format = caps.texture_rg ? viz::RED_8 : viz::LUMINANCE_8; |
| 400 yuv_highbit_resource_format = caps.texture_half_float_linear | 401 yuv_highbit_resource_format = caps.texture_half_float_linear |
| 401 ? viz::LUMINANCE_F16 | 402 ? viz::LUMINANCE_F16 |
| 402 : yuv_resource_format; | 403 : yuv_resource_format; |
| 403 } | 404 } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 } | 570 } |
| 570 | 571 |
| 571 viz::ResourceId ResourceProvider::CreateResource( | 572 viz::ResourceId ResourceProvider::CreateResource( |
| 572 const gfx::Size& size, | 573 const gfx::Size& size, |
| 573 TextureHint hint, | 574 TextureHint hint, |
| 574 viz::ResourceFormat format, | 575 viz::ResourceFormat format, |
| 575 const gfx::ColorSpace& color_space) { | 576 const gfx::ColorSpace& color_space) { |
| 576 DCHECK(!size.IsEmpty()); | 577 DCHECK(!size.IsEmpty()); |
| 577 switch (settings_.default_resource_type) { | 578 switch (settings_.default_resource_type) { |
| 578 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: | 579 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: |
| 579 // GPU memory buffers don't support viz::LUMINANCE_F16 yet. | 580 // GPU memory buffers don't support LUMINANCE_F16 yet. |
| 580 if (format != viz::LUMINANCE_F16) { | 581 if (format != viz::LUMINANCE_F16) { |
| 581 return CreateGLTexture( | 582 TextureHint new_hint = |
| 582 size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, format, | 583 static_cast<TextureHint>(hint | TEXTURE_HINT_IMAGE); |
| 583 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); |
| 584 } | 587 } |
| 585 // Fall through and use a regular texture. | 588 // Fall through and use a regular texture. |
| 586 case RESOURCE_TYPE_GL_TEXTURE: | 589 case RESOURCE_TYPE_GL_TEXTURE: |
| 587 return CreateGLTexture(size, hint, RESOURCE_TYPE_GL_TEXTURE, format, | 590 return CreateGLTexture(size, hint, RESOURCE_TYPE_GL_TEXTURE, format, |
| 588 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | 591 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, |
| 589 color_space); | 592 color_space); |
| 590 | 593 |
| 591 case RESOURCE_TYPE_BITMAP: | 594 case RESOURCE_TYPE_BITMAP: |
| 592 DCHECK_EQ(viz::RGBA_8888, format); | 595 DCHECK_EQ(viz::RGBA_8888, format); |
| 593 return CreateBitmap(size, color_space); | 596 return CreateBitmap(size, color_space); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 viz::ResourceFormat format, | 629 viz::ResourceFormat format, |
| 627 gfx::BufferUsage usage, | 630 gfx::BufferUsage usage, |
| 628 const gfx::ColorSpace& color_space) { | 631 const gfx::ColorSpace& color_space) { |
| 629 DCHECK_LE(size.width(), settings_.max_texture_size); | 632 DCHECK_LE(size.width(), settings_.max_texture_size); |
| 630 DCHECK_LE(size.height(), settings_.max_texture_size); | 633 DCHECK_LE(size.height(), settings_.max_texture_size); |
| 631 DCHECK(thread_checker_.CalledOnValidThread()); | 634 DCHECK(thread_checker_.CalledOnValidThread()); |
| 632 | 635 |
| 633 // 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 |
| 634 // ResourceProvider are GPU_READ_CPU_READ_WRITE. We should determine this | 637 // ResourceProvider are GPU_READ_CPU_READ_WRITE. We should determine this |
| 635 // based on the current RasterBufferProvider's needs. | 638 // based on the current RasterBufferProvider's needs. |
| 636 GLenum target = type == RESOURCE_TYPE_GPU_MEMORY_BUFFER | 639 GLenum target = |
| 637 ? GetImageTextureTarget(usage, format) | 640 type == RESOURCE_TYPE_GPU_MEMORY_BUFFER || (hint & TEXTURE_HINT_IMAGE) |
| 638 : GL_TEXTURE_2D; | 641 ? GetImageTextureTarget(usage, format) |
| 642 : GL_TEXTURE_2D; |
| 639 | 643 |
| 640 viz::ResourceId id = next_id_++; | 644 viz::ResourceId id = next_id_++; |
| 641 Resource* resource = | 645 Resource* resource = |
| 642 InsertResource(id, Resource(0, size, Resource::INTERNAL, target, | 646 InsertResource(id, Resource(0, size, Resource::INTERNAL, target, |
| 643 GL_LINEAR, hint, type, format)); | 647 GL_LINEAR, hint, type, format)); |
| 644 resource->usage = usage; | 648 resource->usage = usage; |
| 645 resource->allocated = false; | 649 resource->allocated = false; |
| 646 resource->color_space = color_space; | 650 resource->color_space = color_space; |
| 647 return id; | 651 return id; |
| 648 } | 652 } |
| (...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1935 if (resource->allocated) | 1939 if (resource->allocated) |
| 1936 return; | 1940 return; |
| 1937 LazyCreate(resource); | 1941 LazyCreate(resource); |
| 1938 if (!resource->gl_id) | 1942 if (!resource->gl_id) |
| 1939 return; | 1943 return; |
| 1940 resource->allocated = true; | 1944 resource->allocated = true; |
| 1941 GLES2Interface* gl = ContextGL(); | 1945 GLES2Interface* gl = ContextGL(); |
| 1942 gfx::Size& size = resource->size; | 1946 gfx::Size& size = resource->size; |
| 1943 viz::ResourceFormat format = resource->format; | 1947 viz::ResourceFormat format = resource->format; |
| 1944 gl->BindTexture(resource->target, resource->gl_id); | 1948 gl->BindTexture(resource->target, resource->gl_id); |
| 1945 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { | 1949 bool can_use_texture_storage = |
| 1950 (settings_.use_texture_storage_ext && |
| 1951 IsFormatSupportedForStorage(format, settings_.use_texture_format_bgra) && |
| 1952 (resource->hint & TEXTURE_HINT_IMMUTABLE)); |
| 1953 bool can_use_texture_buffer = |
| 1954 can_use_texture_storage && settings_.use_texture_buffer_chromium; |
| 1955 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER || |
| 1956 ((resource->hint & TEXTURE_HINT_IMAGE) && !can_use_texture_buffer)) { |
| 1946 resource->gpu_memory_buffer = | 1957 resource->gpu_memory_buffer = |
| 1947 gpu_memory_buffer_manager_->CreateGpuMemoryBuffer( | 1958 gpu_memory_buffer_manager_->CreateGpuMemoryBuffer( |
| 1948 size, BufferFormat(format), resource->usage, | 1959 size, BufferFormat(format), resource->usage, |
| 1949 gpu::kNullSurfaceHandle); | 1960 gpu::kNullSurfaceHandle); |
| 1950 // Note that this impacts overlay compositing, not rasterization. | 1961 // Note that this impacts overlay compositing, not rasterization. |
| 1951 if (resource->gpu_memory_buffer && | 1962 if (resource->gpu_memory_buffer && |
| 1952 settings_.enable_color_correct_rasterization) { | 1963 settings_.enable_color_correct_rasterization) { |
| 1953 resource->gpu_memory_buffer->SetColorSpaceForScanout( | 1964 resource->gpu_memory_buffer->SetColorSpaceForScanout( |
| 1954 resource->color_space); | 1965 resource->color_space); |
| 1955 } | 1966 } |
| 1956 | 1967 |
| 1957 LazyCreateImage(resource); | 1968 LazyCreateImage(resource); |
| 1958 resource->dirty_image = true; | 1969 resource->dirty_image = true; |
| 1959 resource->is_overlay_candidate = true; | 1970 resource->is_overlay_candidate = true; |
| 1960 // GpuMemoryBuffer provides direct access to the memory used by the GPU. | 1971 // GpuMemoryBuffer provides direct access to the memory used by the GPU. |
| 1961 // Read lock fences are required to ensure that we're not trying to map a | 1972 // Read lock fences are required to ensure that we're not trying to map a |
| 1962 // buffer that is currently in-use by the GPU. | 1973 // buffer that is currently in-use by the GPU. |
| 1963 resource->read_lock_fences_enabled = true; | 1974 resource->read_lock_fences_enabled = true; |
| 1964 } else if (settings_.use_texture_storage_ext && | 1975 } else if (can_use_texture_storage) { |
| 1965 IsFormatSupportedForStorage(format, | |
| 1966 settings_.use_texture_format_bgra) && | |
| 1967 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { | |
| 1968 GLenum storage_format = TextureToStorageFormat(format); | 1976 GLenum storage_format = TextureToStorageFormat(format); |
| 1977 if (resource->hint & TEXTURE_HINT_IMAGE) { |
| 1978 DCHECK(settings_.use_texture_buffer_chromium); |
| 1979 gl->TexParameteri(resource->target, GL_TEXTURE_BUFFER_USAGE_CHROMIUM, |
| 1980 GL_TEXTURE_BUFFER_SCANOUT_CHROMIUM); |
| 1981 resource->is_overlay_candidate = true; |
| 1982 } |
| 1983 |
| 1969 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), | 1984 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), |
| 1970 size.height()); | 1985 size.height()); |
| 1986 if ((resource->hint & TEXTURE_HINT_IMAGE) && |
| 1987 settings_.enable_color_correct_rasterization) { |
| 1988 gl->SetColorSpaceForScanoutCHROMIUM( |
| 1989 resource->gl_id, |
| 1990 reinterpret_cast<GLColorSpace>(&resource->color_space)); |
| 1991 } |
| 1971 } else { | 1992 } else { |
| 1972 // viz::ETC1 does not support preallocation. | 1993 // viz::ETC1 does not support preallocation. |
| 1973 if (format != viz::ETC1) { | 1994 if (format != viz::ETC1) { |
| 1974 gl->TexImage2D(resource->target, 0, GLInternalFormat(format), | 1995 gl->TexImage2D(resource->target, 0, GLInternalFormat(format), |
| 1975 size.width(), size.height(), 0, GLDataFormat(format), | 1996 size.width(), size.height(), 0, GLDataFormat(format), |
| 1976 GLDataType(format), nullptr); | 1997 GLDataType(format), nullptr); |
| 1977 } | 1998 } |
| 1978 } | 1999 } |
| 1979 } | 2000 } |
| 1980 | 2001 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2145 } else { | 2166 } else { |
| 2146 pmd->CreateSharedGlobalAllocatorDump(guid); | 2167 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 2147 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2168 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 2148 } | 2169 } |
| 2149 } | 2170 } |
| 2150 | 2171 |
| 2151 return true; | 2172 return true; |
| 2152 } | 2173 } |
| 2153 | 2174 |
| 2154 } // namespace cc | 2175 } // namespace cc |
| OLD | NEW |