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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 resource_provider_->UnlockForWrite(resource_); | 950 resource_provider_->UnlockForWrite(resource_); |
951 if (!gpu_memory_buffer_) | 951 if (!gpu_memory_buffer_) |
952 return; | 952 return; |
953 | 953 |
954 resource_provider_->LazyCreate(resource_); | 954 resource_provider_->LazyCreate(resource_); |
955 | 955 |
956 if (!resource_->image_id) { | 956 if (!resource_->image_id) { |
957 GLES2Interface* gl = resource_provider_->ContextGL(); | 957 GLES2Interface* gl = resource_provider_->ContextGL(); |
958 DCHECK(gl); | 958 DCHECK(gl); |
959 | 959 |
960 #if defined(OS_CHROMEOS) | |
961 // TODO(reveman): GL_COMMANDS_ISSUED_CHROMIUM is used for synchronization | |
962 // on ChromeOS to avoid some performance issues. This only works with | |
963 // shared memory backed buffers. crbug.com/436314 | |
964 DCHECK_EQ(gpu_memory_buffer_->GetHandle().type, gfx::SHARED_MEMORY_BUFFER); | |
965 #endif | |
966 | |
967 resource_->image_id = gl->CreateImageCHROMIUM( | 960 resource_->image_id = gl->CreateImageCHROMIUM( |
968 gpu_memory_buffer_->AsClientBuffer(), size_.width(), size_.height(), | 961 gpu_memory_buffer_->AsClientBuffer(), size_.width(), size_.height(), |
969 GLInternalFormat(resource_->format)); | 962 GLInternalFormat(resource_->format)); |
970 } | 963 } |
971 | 964 |
972 std::swap(resource_->gpu_memory_buffer, gpu_memory_buffer_); | 965 std::swap(resource_->gpu_memory_buffer, gpu_memory_buffer_); |
973 resource_->allocated = true; | 966 resource_->allocated = true; |
974 resource_->dirty_image = true; | 967 resource_->dirty_image = true; |
975 | 968 |
976 // GpuMemoryBuffer provides direct access to the memory used by the GPU. | 969 // GpuMemoryBuffer provides direct access to the memory used by the GPU. |
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 GLES2Interface* gl = ContextGL(); | 1852 GLES2Interface* gl = ContextGL(); |
1860 DCHECK(gl); | 1853 DCHECK(gl); |
1861 if (source_resource->image_id && source_resource->dirty_image) { | 1854 if (source_resource->image_id && source_resource->dirty_image) { |
1862 gl->BindTexture(source_resource->target, source_resource->gl_id); | 1855 gl->BindTexture(source_resource->target, source_resource->gl_id); |
1863 BindImageForSampling(source_resource); | 1856 BindImageForSampling(source_resource); |
1864 } | 1857 } |
1865 if (use_sync_query_) { | 1858 if (use_sync_query_) { |
1866 if (!source_resource->gl_read_lock_query_id) | 1859 if (!source_resource->gl_read_lock_query_id) |
1867 gl->GenQueriesEXT(1, &source_resource->gl_read_lock_query_id); | 1860 gl->GenQueriesEXT(1, &source_resource->gl_read_lock_query_id); |
1868 #if defined(OS_CHROMEOS) | 1861 #if defined(OS_CHROMEOS) |
1869 // TODO(reveman): This avoids a performance problem on some ChromeOS | 1862 // TODO(reveman): GL_COMMANDS_ISSUED_CHROMIUM is used for synchronization |
1870 // devices. This needs to be removed to support native GpuMemoryBuffer | 1863 // on ChromeOS to avoid some performance issues. This only works with |
1871 // implementations. crbug.com/436314 | 1864 // shared memory backed buffers. crbug.com/436314 |
1872 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, | 1865 if (source_resource->gpu_memory_buffer->GetHandle().type == |
1873 source_resource->gl_read_lock_query_id); | 1866 gfx::SHARED_MEMORY_BUFFER) |
1874 #else | 1867 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, |
| 1868 source_resource->gl_read_lock_query_id); |
| 1869 else |
| 1870 #endif |
1875 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, | 1871 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, |
1876 source_resource->gl_read_lock_query_id); | 1872 source_resource->gl_read_lock_query_id); |
1877 #endif | |
1878 } | 1873 } |
1879 DCHECK(!dest_resource->image_id); | 1874 DCHECK(!dest_resource->image_id); |
1880 dest_resource->allocated = true; | 1875 dest_resource->allocated = true; |
1881 gl->CopySubTextureCHROMIUM(dest_resource->target, source_resource->gl_id, | 1876 gl->CopySubTextureCHROMIUM(dest_resource->target, source_resource->gl_id, |
1882 dest_resource->gl_id, rect.x(), rect.y(), rect.x(), | 1877 dest_resource->gl_id, rect.x(), rect.y(), rect.x(), |
1883 rect.y(), rect.width(), rect.height(), | 1878 rect.y(), rect.width(), rect.height(), |
1884 false, false, false); | 1879 false, false, false); |
1885 if (source_resource->gl_read_lock_query_id) { | 1880 if (source_resource->gl_read_lock_query_id) { |
1886 // End query and create a read lock fence that will prevent access to | 1881 // End query and create a read lock fence that will prevent access to |
1887 // source resource until CopySubTextureCHROMIUM command has completed. | 1882 // source resource until CopySubTextureCHROMIUM command has completed. |
1888 #if defined(OS_CHROMEOS) | 1883 #if defined(OS_CHROMEOS) |
1889 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | 1884 if (source_resource->gpu_memory_buffer->GetHandle().type == |
1890 #else | 1885 gfx::SHARED_MEMORY_BUFFER) |
1891 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 1886 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
| 1887 else |
1892 #endif | 1888 #endif |
| 1889 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); |
1893 source_resource->read_lock_fence = make_scoped_refptr( | 1890 source_resource->read_lock_fence = make_scoped_refptr( |
1894 new CopyTextureFence(gl, source_resource->gl_read_lock_query_id)); | 1891 new CopyTextureFence(gl, source_resource->gl_read_lock_query_id)); |
1895 } else { | 1892 } else { |
1896 // Create a SynchronousFence when CHROMIUM_sync_query extension is missing. | 1893 // Create a SynchronousFence when CHROMIUM_sync_query extension is missing. |
1897 // Try to use one synchronous fence for as many CopyResource operations as | 1894 // Try to use one synchronous fence for as many CopyResource operations as |
1898 // possible as that reduce the number of times we have to synchronize with | 1895 // possible as that reduce the number of times we have to synchronize with |
1899 // the GL. | 1896 // the GL. |
1900 if (!synchronous_fence_.get() || synchronous_fence_->has_synchronized()) | 1897 if (!synchronous_fence_.get() || synchronous_fence_->has_synchronized()) |
1901 synchronous_fence_ = make_scoped_refptr(new SynchronousFence(gl)); | 1898 synchronous_fence_ = make_scoped_refptr(new SynchronousFence(gl)); |
1902 source_resource->read_lock_fence = synchronous_fence_; | 1899 source_resource->read_lock_fence = synchronous_fence_; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1946 } | 1943 } |
1947 | 1944 |
1948 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | 1945 class GrContext* ResourceProvider::GrContext(bool worker_context) const { |
1949 ContextProvider* context_provider = | 1946 ContextProvider* context_provider = |
1950 worker_context ? output_surface_->worker_context_provider() | 1947 worker_context ? output_surface_->worker_context_provider() |
1951 : output_surface_->context_provider(); | 1948 : output_surface_->context_provider(); |
1952 return context_provider ? context_provider->GrContext() : NULL; | 1949 return context_provider ? context_provider->GrContext() : NULL; |
1953 } | 1950 } |
1954 | 1951 |
1955 } // namespace cc | 1952 } // namespace cc |
OLD | NEW |