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 unsigned dest_texture_id) | |
| 1000 : resource_provider_(resource_provider), | |
| 1001 resource_(resource_provider_->GetResource(resource_id)), | |
| 1002 gpu_memory_buffer_manager_(resource_provider->gpu_memory_buffer_manager_), | |
| 1003 gpu_memory_buffer_(nullptr), | |
| 1004 size_(resource_->size), | |
| 1005 format_(resource_->format) { | |
| 1006 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource_->type); | |
| 1007 resource_provider_->LazyCreate(resource_); | |
| 1008 worker_context_ = | |
| 1009 resource_provider_->output_surface()->worker_context_provider(); | |
| 1010 image_id_ = resource_->image_id; | |
| 1011 allocated_ = resource_->allocated; | |
| 1012 dirty_image_ = resource_->dirty_image; | |
| 1013 read_lock_fences_enabled_ = resource_->read_lock_fences_enabled; | |
| 1014 did_bind_image_ = false; | |
| 1015 internal_format_ = GLInternalFormat(resource_->format); | |
| 1016 source_gl_id_ = resource_->gl_id; | |
| 1017 dest_gl_id_ = dest_texture_id; | |
|
piman
2015/07/08 23:12:13
I don't think this belongs to the ScopedWriteLockG
sohanjg
2015/07/09 10:04:56
Done.
| |
| 1018 if (resource_provider_->use_sync_query_) { | |
| 1019 query_id_ = 0; | |
|
piman
2015/07/08 23:12:13
nit: always initialize all fields (i.e. you want t
sohanjg
2015/07/09 10:04:56
Done.
| |
| 1020 using_sync_query_ = true; | |
|
piman
2015/07/08 23:12:13
In particular, this one needs to be initialized to
sohanjg
2015/07/09 10:04:56
Done.
| |
| 1021 } | |
| 1022 usage_ = resource_provider_->use_persistent_map_for_gpu_memory_buffers() | |
| 1023 ? gfx::GpuMemoryBuffer::PERSISTENT_MAP | |
| 1024 : gfx::GpuMemoryBuffer::MAP; | |
| 1025 std::swap(gpu_memory_buffer_, resource_->gpu_memory_buffer); | |
| 1026 } | |
| 1027 | |
| 1028 ResourceProvider::ScopedWriteLockGpuMemoryBufferForThread:: | |
| 1029 ~ScopedWriteLockGpuMemoryBufferForThread() { | |
| 1030 GLES2Interface* gl = | |
| 1031 resource_provider_->output_surface()->context_provider()->ContextGL(); | |
| 1032 if (!gpu_memory_buffer_) | |
| 1033 return; | |
| 1034 | |
| 1035 if (using_sync_query_ && query_id_) { | |
| 1036 resource_->read_lock_fence = | |
| 1037 make_scoped_refptr(new CopyTextureFence(gl, query_id_)); | |
|
piman
2015/07/08 23:12:13
As mentioned above, you need to save the query for
sohanjg
2015/07/09 10:04:56
Done.
| |
| 1038 } else { | |
| 1039 // Create a SynchronousFence when CHROMIUM_sync_query extension is missing. | |
| 1040 // Try to use one synchronous fence for as many CopyResource operations as | |
| 1041 // possible as that reduce the number of times we have to synchronize with | |
| 1042 // the GL. | |
| 1043 if (!resource_provider_->synchronous_fence_.get() || | |
| 1044 resource_provider_->synchronous_fence_->has_synchronized()) | |
|
piman
2015/07/08 23:12:13
nit: needs {} per style guide
sohanjg
2015/07/09 10:04:56
Done.
| |
| 1045 resource_provider_->synchronous_fence_ = | |
| 1046 make_scoped_refptr(new SynchronousFence(gl)); | |
| 1047 resource_->read_lock_fence = resource_provider_->synchronous_fence_; | |
| 1048 resource_->read_lock_fence->Set(); | |
| 1049 } | |
| 1050 | |
| 1051 std::swap(resource_->gpu_memory_buffer, gpu_memory_buffer_); | |
| 1052 if (did_bind_image_) { | |
| 1053 resource_->image_id = image_id_; | |
| 1054 resource_->allocated = allocated_; | |
| 1055 resource_->dirty_image = dirty_image_; | |
| 1056 resource_->bound_image_id = bound_image_id_; | |
| 1057 | |
| 1058 resource_->read_lock_fences_enabled = read_lock_fences_enabled_; | |
| 1059 } | |
| 1060 } | |
| 1061 | |
| 1062 gfx::GpuMemoryBuffer* ResourceProvider:: | |
| 1063 ScopedWriteLockGpuMemoryBufferForThread::GetGpuMemoryBuffer() { | |
| 1064 if (gpu_memory_buffer_) | |
| 1065 return gpu_memory_buffer_; | |
| 1066 scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer = | |
| 1067 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | |
| 1068 size_, ToGpuMemoryBufferFormat(format_), usage_); | |
| 1069 gpu_memory_buffer_ = gpu_memory_buffer.release(); | |
| 1070 return gpu_memory_buffer_; | |
| 1071 } | |
| 1072 | |
| 1073 void ResourceProvider::ScopedWriteLockGpuMemoryBufferForThread:: | |
| 1074 CreateAndBindImage() { | |
| 1075 GLES2Interface* gl = worker_context_->ContextGL(); | |
| 1076 image_id_ = | |
| 1077 gl->CreateImageCHROMIUM(gpu_memory_buffer_->AsClientBuffer(), | |
| 1078 size_.width(), size_.height(), internal_format_); | |
| 1079 | |
| 1080 allocated_ = true; | |
| 1081 read_lock_fences_enabled_ = true; | |
|
piman
2015/07/08 23:12:13
You don't need those 2 as a field, you can just se
sohanjg
2015/07/09 10:04:56
Done.
| |
| 1082 gl->BindTexture(GL_TEXTURE_2D, source_gl_id_); | |
| 1083 if (bound_image_id_) | |
| 1084 gl->ReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, bound_image_id_); | |
| 1085 gl->BindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id_); | |
| 1086 bound_image_id_ = image_id_; | |
| 1087 dirty_image_ = false; | |
|
piman
2015/07/08 23:12:13
Same for this, don't need it as a field, you can j
sohanjg
2015/07/09 10:04:56
Done.
| |
| 1088 did_bind_image_ = true; | |
| 1089 } | |
| 1090 | |
| 1091 void ResourceProvider::ScopedWriteLockGpuMemoryBufferForThread:: | |
| 1092 BeginCopyTexture() { | |
| 1093 GLES2Interface* gl = worker_context_->ContextGL(); | |
| 1094 if (using_sync_query_) { | |
| 1095 if (!query_id_) | |
| 1096 gl->GenQueriesEXT(1, &query_id_); | |
| 1097 #if defined(OS_CHROMEOS) | |
| 1098 // TODO(reveman): This avoids a performance problem on some ChromeOS | |
| 1099 // devices. This needs to be removed to support native GpuMemoryBuffer | |
| 1100 // implementations. crbug.com/436314 | |
| 1101 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, query_id_); | |
| 1102 #else | |
| 1103 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, query_id_); | |
| 1104 #endif | |
| 1105 } | |
| 1106 } | |
| 1107 | |
| 1108 void ResourceProvider::ScopedWriteLockGpuMemoryBufferForThread:: | |
| 1109 EndCopyTexture() { | |
| 1110 GLES2Interface* gl = worker_context_->ContextGL(); | |
| 1111 if (using_sync_query_ && query_id_) { | |
| 1112 // End query and create a read lock fence that will prevent access to | |
| 1113 // source resource until CopySubTextureCHROMIUM command has completed. | |
| 1114 #if defined(OS_CHROMEOS) | |
| 1115 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | |
| 1116 #else | |
| 1117 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | |
| 1118 #endif | |
| 1119 } | |
| 1120 } | |
| 1121 | |
| 997 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr( | 1122 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr( |
| 998 ResourceProvider* resource_provider, | 1123 ResourceProvider* resource_provider, |
| 999 ResourceId resource_id) | 1124 ResourceId resource_id) |
| 1000 : resource_provider_(resource_provider), | 1125 : resource_provider_(resource_provider), |
| 1001 resource_(resource_provider->LockForWrite(resource_id)) { | 1126 resource_(resource_provider->LockForWrite(resource_id)) { |
| 1002 DCHECK(thread_checker_.CalledOnValidThread()); | 1127 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1003 resource_provider_->LazyAllocate(resource_); | 1128 resource_provider_->LazyAllocate(resource_); |
| 1004 } | 1129 } |
| 1005 | 1130 |
| 1006 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { | 1131 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { |
| (...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1872 source_resource->gl_read_lock_query_id); | 1997 source_resource->gl_read_lock_query_id); |
| 1873 #else | 1998 #else |
| 1874 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, | 1999 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, |
| 1875 source_resource->gl_read_lock_query_id); | 2000 source_resource->gl_read_lock_query_id); |
| 1876 #endif | 2001 #endif |
| 1877 } | 2002 } |
| 1878 DCHECK(!dest_resource->image_id); | 2003 DCHECK(!dest_resource->image_id); |
| 1879 dest_resource->allocated = true; | 2004 dest_resource->allocated = true; |
| 1880 gl->CopySubTextureCHROMIUM(dest_resource->target, source_resource->gl_id, | 2005 gl->CopySubTextureCHROMIUM(dest_resource->target, source_resource->gl_id, |
| 1881 dest_resource->gl_id, rect.x(), rect.y(), rect.x(), | 2006 dest_resource->gl_id, rect.x(), rect.y(), rect.x(), |
| 1882 rect.y(), rect.width(), rect.height(), | 2007 rect.y(), rect.width(), rect.height(), false, |
| 1883 false, false, false); | 2008 false, false); |
| 1884 if (source_resource->gl_read_lock_query_id) { | 2009 if (source_resource->gl_read_lock_query_id) { |
| 1885 // End query and create a read lock fence that will prevent access to | 2010 // End query and create a read lock fence that will prevent access to |
| 1886 // source resource until CopySubTextureCHROMIUM command has completed. | 2011 // source resource until CopySubTextureCHROMIUM command has completed. |
| 1887 #if defined(OS_CHROMEOS) | 2012 #if defined(OS_CHROMEOS) |
| 1888 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | 2013 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
| 1889 #else | 2014 #else |
| 1890 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 2015 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); |
| 1891 #endif | 2016 #endif |
| 1892 source_resource->read_lock_fence = make_scoped_refptr( | 2017 source_resource->read_lock_fence = make_scoped_refptr( |
| 1893 new CopyTextureFence(gl, source_resource->gl_read_lock_query_id)); | 2018 new CopyTextureFence(gl, source_resource->gl_read_lock_query_id)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1945 } | 2070 } |
| 1946 | 2071 |
| 1947 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | 2072 class GrContext* ResourceProvider::GrContext(bool worker_context) const { |
| 1948 ContextProvider* context_provider = | 2073 ContextProvider* context_provider = |
| 1949 worker_context ? output_surface_->worker_context_provider() | 2074 worker_context ? output_surface_->worker_context_provider() |
| 1950 : output_surface_->context_provider(); | 2075 : output_surface_->context_provider(); |
| 1951 return context_provider ? context_provider->GrContext() : NULL; | 2076 return context_provider ? context_provider->GrContext() : NULL; |
| 1952 } | 2077 } |
| 1953 | 2078 |
| 1954 } // namespace cc | 2079 } // namespace cc |
| OLD | NEW |