| 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 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 ~ScopedWriteLockGpuMemoryBuffer() { | 1042 ~ScopedWriteLockGpuMemoryBuffer() { |
| 1043 DCHECK(thread_checker_.CalledOnValidThread()); | 1043 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1044 resource_provider_->UnlockForWrite(resource_); | 1044 resource_provider_->UnlockForWrite(resource_); |
| 1045 if (!gpu_memory_buffer_) | 1045 if (!gpu_memory_buffer_) |
| 1046 return; | 1046 return; |
| 1047 | 1047 |
| 1048 if (!resource_->image_id) { | 1048 if (!resource_->image_id) { |
| 1049 GLES2Interface* gl = resource_provider_->ContextGL(); | 1049 GLES2Interface* gl = resource_provider_->ContextGL(); |
| 1050 DCHECK(gl); | 1050 DCHECK(gl); |
| 1051 | 1051 |
| 1052 #if defined(OS_CHROMEOS) |
| 1053 // TODO(reveman): GL_COMMANDS_ISSUED_CHROMIUM is used for synchronization |
| 1054 // on ChromeOS to avoid some performance issues. This only works with |
| 1055 // shared memory backed buffers. crbug.com/436314 |
| 1056 DCHECK_EQ(gpu_memory_buffer_->GetHandle().type, gfx::SHARED_MEMORY_BUFFER); |
| 1057 #endif |
| 1058 |
| 1052 resource_->image_id = | 1059 resource_->image_id = |
| 1053 gl->CreateImageCHROMIUM(gpu_memory_buffer_->AsClientBuffer(), | 1060 gl->CreateImageCHROMIUM(gpu_memory_buffer_->AsClientBuffer(), |
| 1054 size_.width(), | 1061 size_.width(), |
| 1055 size_.height(), | 1062 size_.height(), |
| 1056 GL_RGBA); | 1063 GL_RGBA); |
| 1057 } | 1064 } |
| 1058 | 1065 |
| 1059 std::swap(resource_->gpu_memory_buffer, gpu_memory_buffer_); | 1066 std::swap(resource_->gpu_memory_buffer, gpu_memory_buffer_); |
| 1060 resource_->allocated = true; | 1067 resource_->allocated = true; |
| 1061 resource_->dirty_image = true; | 1068 resource_->dirty_image = true; |
| (...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2063 | 2070 |
| 2064 GLES2Interface* gl = ContextGL(); | 2071 GLES2Interface* gl = ContextGL(); |
| 2065 DCHECK(gl); | 2072 DCHECK(gl); |
| 2066 if (source_resource->image_id && source_resource->dirty_image) { | 2073 if (source_resource->image_id && source_resource->dirty_image) { |
| 2067 gl->BindTexture(source_resource->target, source_resource->gl_id); | 2074 gl->BindTexture(source_resource->target, source_resource->gl_id); |
| 2068 BindImageForSampling(source_resource); | 2075 BindImageForSampling(source_resource); |
| 2069 } | 2076 } |
| 2070 if (use_sync_query_) { | 2077 if (use_sync_query_) { |
| 2071 if (!source_resource->gl_read_lock_query_id) | 2078 if (!source_resource->gl_read_lock_query_id) |
| 2072 gl->GenQueriesEXT(1, &source_resource->gl_read_lock_query_id); | 2079 gl->GenQueriesEXT(1, &source_resource->gl_read_lock_query_id); |
| 2080 #if defined(OS_CHROMEOS) |
| 2081 // TODO(reveman): This avoids a performance problem on some ChromeOS |
| 2082 // devices. This needs to be removed to support native GpuMemoryBuffer |
| 2083 // implementations. crbug.com/436314 |
| 2084 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, |
| 2085 source_resource->gl_read_lock_query_id); |
| 2086 #else |
| 2073 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, | 2087 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, |
| 2074 source_resource->gl_read_lock_query_id); | 2088 source_resource->gl_read_lock_query_id); |
| 2089 #endif |
| 2075 } | 2090 } |
| 2076 DCHECK(!dest_resource->image_id); | 2091 DCHECK(!dest_resource->image_id); |
| 2077 dest_resource->allocated = true; | 2092 dest_resource->allocated = true; |
| 2078 gl->CopyTextureCHROMIUM(dest_resource->target, | 2093 gl->CopyTextureCHROMIUM(dest_resource->target, |
| 2079 source_resource->gl_id, | 2094 source_resource->gl_id, |
| 2080 dest_resource->gl_id, | 2095 dest_resource->gl_id, |
| 2081 0, | 2096 0, |
| 2082 GLInternalFormat(dest_resource->format), | 2097 GLInternalFormat(dest_resource->format), |
| 2083 GLDataType(dest_resource->format)); | 2098 GLDataType(dest_resource->format)); |
| 2084 if (source_resource->gl_read_lock_query_id) { | 2099 if (source_resource->gl_read_lock_query_id) { |
| 2085 // End query and create a read lock fence that will prevent access to | 2100 // End query and create a read lock fence that will prevent access to |
| 2086 // source resource until CopyTextureCHROMIUM command has completed. | 2101 // source resource until CopyTextureCHROMIUM command has completed. |
| 2102 #if defined(OS_CHROMEOS) |
| 2103 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
| 2104 #else |
| 2087 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 2105 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); |
| 2106 #endif |
| 2088 source_resource->read_lock_fence = make_scoped_refptr( | 2107 source_resource->read_lock_fence = make_scoped_refptr( |
| 2089 new CopyTextureFence(gl, source_resource->gl_read_lock_query_id)); | 2108 new CopyTextureFence(gl, source_resource->gl_read_lock_query_id)); |
| 2090 } else { | 2109 } else { |
| 2091 // Create a SynchronousFence when CHROMIUM_sync_query extension is missing. | 2110 // Create a SynchronousFence when CHROMIUM_sync_query extension is missing. |
| 2092 // Try to use one synchronous fence for as many CopyResource operations as | 2111 // Try to use one synchronous fence for as many CopyResource operations as |
| 2093 // possible as that reduce the number of times we have to synchronize with | 2112 // possible as that reduce the number of times we have to synchronize with |
| 2094 // the GL. | 2113 // the GL. |
| 2095 if (!synchronous_fence_.get() || synchronous_fence_->has_synchronized()) | 2114 if (!synchronous_fence_.get() || synchronous_fence_->has_synchronized()) |
| 2096 synchronous_fence_ = make_scoped_refptr(new SynchronousFence(gl)); | 2115 synchronous_fence_ = make_scoped_refptr(new SynchronousFence(gl)); |
| 2097 source_resource->read_lock_fence = synchronous_fence_; | 2116 source_resource->read_lock_fence = synchronous_fence_; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2133 ContextProvider* context_provider = output_surface_->context_provider(); | 2152 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2134 return context_provider ? context_provider->ContextGL() : NULL; | 2153 return context_provider ? context_provider->ContextGL() : NULL; |
| 2135 } | 2154 } |
| 2136 | 2155 |
| 2137 class GrContext* ResourceProvider::GrContext() const { | 2156 class GrContext* ResourceProvider::GrContext() const { |
| 2138 ContextProvider* context_provider = output_surface_->context_provider(); | 2157 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2139 return context_provider ? context_provider->GrContext() : NULL; | 2158 return context_provider ? context_provider->GrContext() : NULL; |
| 2140 } | 2159 } |
| 2141 | 2160 |
| 2142 } // namespace cc | 2161 } // namespace cc |
| OLD | NEW |