| 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 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 resource_provider_->UnlockForWrite(resource_); | 1050 resource_provider_->UnlockForWrite(resource_); |
| 1051 if (!gpu_memory_buffer_) | 1051 if (!gpu_memory_buffer_) |
| 1052 return; | 1052 return; |
| 1053 | 1053 |
| 1054 resource_provider_->LazyCreate(resource_); | 1054 resource_provider_->LazyCreate(resource_); |
| 1055 | 1055 |
| 1056 if (!resource_->image_id) { | 1056 if (!resource_->image_id) { |
| 1057 GLES2Interface* gl = resource_provider_->ContextGL(); | 1057 GLES2Interface* gl = resource_provider_->ContextGL(); |
| 1058 DCHECK(gl); | 1058 DCHECK(gl); |
| 1059 | 1059 |
| 1060 #if defined(OS_CHROMEOS) | |
| 1061 // TODO(reveman): GL_COMMANDS_ISSUED_CHROMIUM is used for synchronization | |
| 1062 // on ChromeOS to avoid some performance issues. This only works with | |
| 1063 // shared memory backed buffers. crbug.com/436314 | |
| 1064 DCHECK_EQ(gpu_memory_buffer_->GetHandle().type, gfx::SHARED_MEMORY_BUFFER); | |
| 1065 #endif | |
| 1066 | |
| 1067 resource_->image_id = gl->CreateImageCHROMIUM( | 1060 resource_->image_id = gl->CreateImageCHROMIUM( |
| 1068 gpu_memory_buffer_->AsClientBuffer(), size_.width(), size_.height(), | 1061 gpu_memory_buffer_->AsClientBuffer(), size_.width(), size_.height(), |
| 1069 GLInternalFormat(resource_->format)); | 1062 GLInternalFormat(resource_->format)); |
| 1070 } | 1063 } |
| 1071 | 1064 |
| 1072 std::swap(resource_->gpu_memory_buffer, gpu_memory_buffer_); | 1065 std::swap(resource_->gpu_memory_buffer, gpu_memory_buffer_); |
| 1073 resource_->allocated = true; | 1066 resource_->allocated = true; |
| 1074 resource_->dirty_image = true; | 1067 resource_->dirty_image = true; |
| 1075 | 1068 |
| 1076 // GpuMemoryBuffer provides direct access to the memory used by the GPU. | 1069 // GpuMemoryBuffer provides direct access to the memory used by the GPU. |
| (...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1961 GLES2Interface* gl = ContextGL(); | 1954 GLES2Interface* gl = ContextGL(); |
| 1962 DCHECK(gl); | 1955 DCHECK(gl); |
| 1963 if (source_resource->image_id && source_resource->dirty_image) { | 1956 if (source_resource->image_id && source_resource->dirty_image) { |
| 1964 gl->BindTexture(source_resource->target, source_resource->gl_id); | 1957 gl->BindTexture(source_resource->target, source_resource->gl_id); |
| 1965 BindImageForSampling(source_resource); | 1958 BindImageForSampling(source_resource); |
| 1966 } | 1959 } |
| 1967 if (use_sync_query_) { | 1960 if (use_sync_query_) { |
| 1968 if (!source_resource->gl_read_lock_query_id) | 1961 if (!source_resource->gl_read_lock_query_id) |
| 1969 gl->GenQueriesEXT(1, &source_resource->gl_read_lock_query_id); | 1962 gl->GenQueriesEXT(1, &source_resource->gl_read_lock_query_id); |
| 1970 #if defined(OS_CHROMEOS) | 1963 #if defined(OS_CHROMEOS) |
| 1971 // TODO(reveman): This avoids a performance problem on some ChromeOS | 1964 // TODO(reveman): GL_COMMANDS_ISSUED_CHROMIUM is used for synchronization |
| 1972 // devices. This needs to be removed to support native GpuMemoryBuffer | 1965 // on ChromeOS to avoid some performance issues. This only works with |
| 1973 // implementations. crbug.com/436314 | 1966 // shared memory backed buffers. crbug.com/436314 |
| 1974 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, | 1967 if (source_resource->gpu_memory_buffer->GetHandle().type == |
| 1975 source_resource->gl_read_lock_query_id); | 1968 gfx::SHARED_MEMORY_BUFFER) |
| 1976 #else | 1969 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, |
| 1970 source_resource->gl_read_lock_query_id); |
| 1971 else |
| 1972 #endif |
| 1977 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, | 1973 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, |
| 1978 source_resource->gl_read_lock_query_id); | 1974 source_resource->gl_read_lock_query_id); |
| 1979 #endif | |
| 1980 } | 1975 } |
| 1981 DCHECK(!dest_resource->image_id); | 1976 DCHECK(!dest_resource->image_id); |
| 1982 dest_resource->allocated = true; | 1977 dest_resource->allocated = true; |
| 1983 gl->CopySubTextureCHROMIUM(dest_resource->target, source_resource->gl_id, | 1978 gl->CopySubTextureCHROMIUM(dest_resource->target, source_resource->gl_id, |
| 1984 dest_resource->gl_id, rect.x(), rect.y(), rect.x(), | 1979 dest_resource->gl_id, rect.x(), rect.y(), rect.x(), |
| 1985 rect.y(), rect.width(), rect.height()); | 1980 rect.y(), rect.width(), rect.height()); |
| 1986 if (source_resource->gl_read_lock_query_id) { | 1981 if (source_resource->gl_read_lock_query_id) { |
| 1987 // End query and create a read lock fence that will prevent access to | 1982 // End query and create a read lock fence that will prevent access to |
| 1988 // source resource until CopySubTextureCHROMIUM command has completed. | 1983 // source resource until CopySubTextureCHROMIUM command has completed. |
| 1989 #if defined(OS_CHROMEOS) | 1984 #if defined(OS_CHROMEOS) |
| 1990 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | 1985 if (source_resource->gpu_memory_buffer->GetHandle().type == |
| 1991 #else | 1986 gfx::SHARED_MEMORY_BUFFER) |
| 1992 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 1987 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
| 1988 else |
| 1993 #endif | 1989 #endif |
| 1990 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); |
| 1994 source_resource->read_lock_fence = make_scoped_refptr( | 1991 source_resource->read_lock_fence = make_scoped_refptr( |
| 1995 new CopyTextureFence(gl, source_resource->gl_read_lock_query_id)); | 1992 new CopyTextureFence(gl, source_resource->gl_read_lock_query_id)); |
| 1996 } else { | 1993 } else { |
| 1997 // Create a SynchronousFence when CHROMIUM_sync_query extension is missing. | 1994 // Create a SynchronousFence when CHROMIUM_sync_query extension is missing. |
| 1998 // Try to use one synchronous fence for as many CopyResource operations as | 1995 // Try to use one synchronous fence for as many CopyResource operations as |
| 1999 // possible as that reduce the number of times we have to synchronize with | 1996 // possible as that reduce the number of times we have to synchronize with |
| 2000 // the GL. | 1997 // the GL. |
| 2001 if (!synchronous_fence_.get() || synchronous_fence_->has_synchronized()) | 1998 if (!synchronous_fence_.get() || synchronous_fence_->has_synchronized()) |
| 2002 synchronous_fence_ = make_scoped_refptr(new SynchronousFence(gl)); | 1999 synchronous_fence_ = make_scoped_refptr(new SynchronousFence(gl)); |
| 2003 source_resource->read_lock_fence = synchronous_fence_; | 2000 source_resource->read_lock_fence = synchronous_fence_; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2047 } | 2044 } |
| 2048 | 2045 |
| 2049 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | 2046 class GrContext* ResourceProvider::GrContext(bool worker_context) const { |
| 2050 ContextProvider* context_provider = | 2047 ContextProvider* context_provider = |
| 2051 worker_context ? output_surface_->worker_context_provider() | 2048 worker_context ? output_surface_->worker_context_provider() |
| 2052 : output_surface_->context_provider(); | 2049 : output_surface_->context_provider(); |
| 2053 return context_provider ? context_provider->GrContext() : NULL; | 2050 return context_provider ? context_provider->GrContext() : NULL; |
| 2054 } | 2051 } |
| 2055 | 2052 |
| 2056 } // namespace cc | 2053 } // namespace cc |
| OLD | NEW |