Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 #include "gpu/GLES2/gl2extchromium.h" | 22 #include "gpu/GLES2/gl2extchromium.h" | 
| 23 #include "gpu/command_buffer/client/gles2_interface.h" | 23 #include "gpu/command_buffer/client/gles2_interface.h" | 
| 24 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 24 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 
| 25 #include "third_party/khronos/GLES2/gl2.h" | 25 #include "third_party/khronos/GLES2/gl2.h" | 
| 26 #include "third_party/khronos/GLES2/gl2ext.h" | 26 #include "third_party/khronos/GLES2/gl2ext.h" | 
| 27 #include "third_party/skia/include/core/SkSurface.h" | 27 #include "third_party/skia/include/core/SkSurface.h" | 
| 28 #include "third_party/skia/include/gpu/GrContext.h" | 28 #include "third_party/skia/include/gpu/GrContext.h" | 
| 29 #include "third_party/skia/include/gpu/GrTextureProvider.h" | 29 #include "third_party/skia/include/gpu/GrTextureProvider.h" | 
| 30 #include "ui/gfx/geometry/rect.h" | 30 #include "ui/gfx/geometry/rect.h" | 
| 31 #include "ui/gfx/geometry/vector2d.h" | 31 #include "ui/gfx/geometry/vector2d.h" | 
| 32 #include "ui/gfx/gpu_memory_buffer.h" | |
| 33 | 32 | 
| 34 using gpu::gles2::GLES2Interface; | 33 using gpu::gles2::GLES2Interface; | 
| 35 | 34 | 
| 36 namespace cc { | 35 namespace cc { | 
| 37 | 36 | 
| 38 class IdAllocator { | 37 class IdAllocator { | 
| 39 public: | 38 public: | 
| 40 virtual ~IdAllocator() {} | 39 virtual ~IdAllocator() {} | 
| 41 | 40 | 
| 42 virtual GLuint NextId() = 0; | 41 virtual GLuint NextId() = 0; | 
| (...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 987 resource_provider_->use_persistent_map_for_gpu_memory_buffers() | 986 resource_provider_->use_persistent_map_for_gpu_memory_buffers() | 
| 988 ? gfx::GpuMemoryBuffer::PERSISTENT_MAP | 987 ? gfx::GpuMemoryBuffer::PERSISTENT_MAP | 
| 989 : gfx::GpuMemoryBuffer::MAP; | 988 : gfx::GpuMemoryBuffer::MAP; | 
| 990 scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer = | 989 scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer = | 
| 991 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | 990 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | 
| 992 size_, ToGpuMemoryBufferFormat(format_), usage); | 991 size_, ToGpuMemoryBufferFormat(format_), usage); | 
| 993 gpu_memory_buffer_ = gpu_memory_buffer.release(); | 992 gpu_memory_buffer_ = gpu_memory_buffer.release(); | 
| 994 return gpu_memory_buffer_; | 993 return gpu_memory_buffer_; | 
| 995 } | 994 } | 
| 996 | 995 | 
| 996 ResourceProvider::ScopedWriteLockGpuMemoryBufferForThread:: | |
| 997 ScopedWriteLockGpuMemoryBufferForThread(ResourceProvider* resource_provider, | |
| 998 ResourceId resource_id) | |
| 999 : resource_provider_(resource_provider), | |
| 1000 resource_(resource_provider_->GetResource(resource_id)), | |
| 1001 gpu_memory_buffer_manager_(resource_provider->gpu_memory_buffer_manager_), | |
| 1002 gpu_memory_buffer_(nullptr), | |
| 1003 size_(resource_->size), | |
| 1004 format_(resource_->format) { | |
| 1005 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource_->type); | |
| 1006 resource_provider_->LazyCreate(resource_); | |
| 1007 worker_context_ = | |
| 1008 resource_provider_->output_surface()->worker_context_provider(); | |
| 1009 image_id_ = resource_->image_id; | |
| 1010 did_bind_image_ = false; | |
| 1011 internal_format_ = GLInternalFormat(resource_->format); | |
| 1012 source_gl_id_ = resource_->gl_id; | |
| 1013 query_id_ = resource_->gl_read_lock_query_id; | |
| 1014 using_sync_query_ = resource_provider_->use_sync_query_; | |
| 1015 | |
| 1016 usage_ = resource_provider_->use_persistent_map_for_gpu_memory_buffers() | |
| 1017 ? gfx::GpuMemoryBuffer::PERSISTENT_MAP | |
| 1018 : gfx::GpuMemoryBuffer::MAP; | |
| 1019 std::swap(gpu_memory_buffer_, resource_->gpu_memory_buffer); | |
| 1020 } | |
| 1021 | |
| 1022 ResourceProvider::ScopedWriteLockGpuMemoryBufferForThread:: | |
| 1023 ~ScopedWriteLockGpuMemoryBufferForThread() { | |
| 1024 GLES2Interface* gl = | |
| 1025 resource_provider_->output_surface()->context_provider()->ContextGL(); | |
| 1026 if (!gpu_memory_buffer_) | |
| 1027 return; | |
| 1028 | |
| 1029 if (using_sync_query_ && query_id_) { | |
| 1030 resource_->gl_read_lock_query_id = query_id_; | |
| 1031 resource_->read_lock_fence = | |
| 1032 make_scoped_refptr(new CopyTextureFence(gl, query_id_)); | |
| 1033 } else { | |
| 1034 // Create a SynchronousFence when CHROMIUM_sync_query extension is missing. | |
| 1035 // Try to use one synchronous fence for as many CopyResource operations as | |
| 1036 // possible as that reduce the number of times we have to synchronize with | |
| 1037 // the GL. | |
| 1038 if (!resource_provider_->synchronous_fence_.get() || | |
| 1039 resource_provider_->synchronous_fence_->has_synchronized()) { | |
| 1040 resource_provider_->synchronous_fence_ = | |
| 1041 make_scoped_refptr(new SynchronousFence(gl)); | |
| 1042 } | |
| 1043 resource_->read_lock_fence = resource_provider_->synchronous_fence_; | |
| 1044 resource_->read_lock_fence->Set(); | |
| 1045 } | |
| 1046 | |
| 1047 std::swap(resource_->gpu_memory_buffer, gpu_memory_buffer_); | |
| 1048 if (did_bind_image_) { | |
| 1049 resource_->image_id = image_id_; | |
| 1050 resource_->allocated = true; | |
| 1051 resource_->dirty_image = true; | |
| 
 
piman
2015/07/10 02:25:09
= false
 
sohanjg
2015/07/10 13:34:31
Acknowledged.
 
 | |
| 1052 resource_->bound_image_id = bound_image_id_; | |
| 1053 resource_->read_lock_fences_enabled = true; | |
| 1054 } | |
| 1055 } | |
| 1056 | |
| 1057 gfx::GpuMemoryBuffer* ResourceProvider:: | |
| 1058 ScopedWriteLockGpuMemoryBufferForThread::GetGpuMemoryBuffer() { | |
| 1059 if (gpu_memory_buffer_) | |
| 1060 return gpu_memory_buffer_; | |
| 1061 scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer = | |
| 1062 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | |
| 1063 size_, ToGpuMemoryBufferFormat(format_), usage_); | |
| 1064 gpu_memory_buffer_ = gpu_memory_buffer.release(); | |
| 1065 return gpu_memory_buffer_; | |
| 1066 } | |
| 1067 | |
| 1068 void ResourceProvider::ScopedWriteLockGpuMemoryBufferForThread:: | |
| 1069 CreateAndBindImage() { | |
| 1070 GLES2Interface* gl = worker_context_->ContextGL(); | |
| 1071 image_id_ = | |
| 1072 gl->CreateImageCHROMIUM(gpu_memory_buffer_->AsClientBuffer(), | |
| 1073 size_.width(), size_.height(), internal_format_); | |
| 1074 | |
| 1075 gl->BindTexture(GL_TEXTURE_2D, source_gl_id_); | |
| 1076 if (bound_image_id_) | |
| 1077 gl->ReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, bound_image_id_); | |
| 1078 gl->BindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id_); | |
| 1079 bound_image_id_ = image_id_; | |
| 1080 did_bind_image_ = true; | |
| 1081 } | |
| 1082 | |
| 1083 void ResourceProvider::ScopedWriteLockGpuMemoryBufferForThread:: | |
| 1084 BeginCopyTexture() { | |
| 1085 GLES2Interface* gl = worker_context_->ContextGL(); | |
| 1086 if (using_sync_query_) { | |
| 1087 if (!query_id_) | |
| 1088 gl->GenQueriesEXT(1, &query_id_); | |
| 1089 #if defined(OS_CHROMEOS) | |
| 1090 // TODO(reveman): This avoids a performance problem on some ChromeOS | |
| 1091 // devices. This needs to be removed to support native GpuMemoryBuffer | |
| 1092 // implementations. crbug.com/436314 | |
| 1093 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, query_id_); | |
| 1094 #else | |
| 1095 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, query_id_); | |
| 1096 #endif | |
| 1097 } | |
| 1098 } | |
| 1099 | |
| 1100 void ResourceProvider::ScopedWriteLockGpuMemoryBufferForThread:: | |
| 1101 EndCopyTexture() { | |
| 1102 GLES2Interface* gl = worker_context_->ContextGL(); | |
| 1103 if (using_sync_query_ && query_id_) { | |
| 1104 // End query and create a read lock fence that will prevent access to | |
| 1105 // source resource until CopySubTextureCHROMIUM command has completed. | |
| 1106 #if defined(OS_CHROMEOS) | |
| 1107 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | |
| 1108 #else | |
| 1109 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | |
| 1110 #endif | |
| 1111 } | |
| 1112 } | |
| 1113 | |
| 997 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr( | 1114 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr( | 
| 998 ResourceProvider* resource_provider, | 1115 ResourceProvider* resource_provider, | 
| 999 ResourceId resource_id) | 1116 ResourceId resource_id) | 
| 1000 : resource_provider_(resource_provider), | 1117 : resource_provider_(resource_provider), | 
| 1001 resource_(resource_provider->LockForWrite(resource_id)) { | 1118 resource_(resource_provider->LockForWrite(resource_id)) { | 
| 1002 DCHECK(thread_checker_.CalledOnValidThread()); | 1119 DCHECK(thread_checker_.CalledOnValidThread()); | 
| 1003 resource_provider_->LazyAllocate(resource_); | 1120 resource_provider_->LazyAllocate(resource_); | 
| 1004 } | 1121 } | 
| 1005 | 1122 | 
| 1006 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { | 1123 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { | 
| (...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1872 source_resource->gl_read_lock_query_id); | 1989 source_resource->gl_read_lock_query_id); | 
| 1873 #else | 1990 #else | 
| 1874 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, | 1991 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, | 
| 1875 source_resource->gl_read_lock_query_id); | 1992 source_resource->gl_read_lock_query_id); | 
| 1876 #endif | 1993 #endif | 
| 1877 } | 1994 } | 
| 1878 DCHECK(!dest_resource->image_id); | 1995 DCHECK(!dest_resource->image_id); | 
| 1879 dest_resource->allocated = true; | 1996 dest_resource->allocated = true; | 
| 1880 gl->CopySubTextureCHROMIUM(dest_resource->target, source_resource->gl_id, | 1997 gl->CopySubTextureCHROMIUM(dest_resource->target, source_resource->gl_id, | 
| 1881 dest_resource->gl_id, rect.x(), rect.y(), rect.x(), | 1998 dest_resource->gl_id, rect.x(), rect.y(), rect.x(), | 
| 1882 rect.y(), rect.width(), rect.height(), | 1999 rect.y(), rect.width(), rect.height(), false, | 
| 1883 false, false, false); | 2000 false, false); | 
| 1884 if (source_resource->gl_read_lock_query_id) { | 2001 if (source_resource->gl_read_lock_query_id) { | 
| 1885 // End query and create a read lock fence that will prevent access to | 2002 // End query and create a read lock fence that will prevent access to | 
| 1886 // source resource until CopySubTextureCHROMIUM command has completed. | 2003 // source resource until CopySubTextureCHROMIUM command has completed. | 
| 1887 #if defined(OS_CHROMEOS) | 2004 #if defined(OS_CHROMEOS) | 
| 1888 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | 2005 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | 
| 1889 #else | 2006 #else | 
| 1890 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 2007 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 
| 1891 #endif | 2008 #endif | 
| 1892 source_resource->read_lock_fence = make_scoped_refptr( | 2009 source_resource->read_lock_fence = make_scoped_refptr( | 
| 1893 new CopyTextureFence(gl, source_resource->gl_read_lock_query_id)); | 2010 new CopyTextureFence(gl, source_resource->gl_read_lock_query_id)); | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1945 } | 2062 } | 
| 1946 | 2063 | 
| 1947 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | 2064 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | 
| 1948 ContextProvider* context_provider = | 2065 ContextProvider* context_provider = | 
| 1949 worker_context ? output_surface_->worker_context_provider() | 2066 worker_context ? output_surface_->worker_context_provider() | 
| 1950 : output_surface_->context_provider(); | 2067 : output_surface_->context_provider(); | 
| 1951 return context_provider ? context_provider->GrContext() : NULL; | 2068 return context_provider ? context_provider->GrContext() : NULL; | 
| 1952 } | 2069 } | 
| 1953 | 2070 | 
| 1954 } // namespace cc | 2071 } // namespace cc | 
| OLD | NEW |