| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/raster/one_copy_raster_buffer_provider.h" | 5 #include "cc/raster/one_copy_raster_buffer_provider.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "cc/base/math_util.h" | 14 #include "cc/base/math_util.h" |
| 15 #include "cc/resources/platform_color.h" | 15 #include "cc/resources/platform_color.h" |
| 16 #include "cc/resources/resource_format.h" | 16 #include "cc/resources/resource_format.h" |
| 17 #include "cc/resources/resource_util.h" | 17 #include "cc/resources/resource_util.h" |
| 18 #include "cc/resources/scoped_resource.h" | 18 #include "cc/resources/scoped_resource.h" |
| 19 #include "gpu/GLES2/gl2extchromium.h" | 19 #include "gpu/GLES2/gl2extchromium.h" |
| 20 #include "gpu/command_buffer/client/gles2_interface.h" | 20 #include "gpu/command_buffer/client/gles2_interface.h" |
| 21 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 21 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
| 22 #include "ui/gfx/buffer_format_util.h" | 22 #include "ui/gfx/buffer_format_util.h" |
| 23 | 23 |
| 24 namespace cc { | 24 namespace cc { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 class RasterBufferImpl : public RasterBuffer { | |
| 28 public: | |
| 29 RasterBufferImpl(OneCopyRasterBufferProvider* worker_pool, | |
| 30 ResourceProvider* resource_provider, | |
| 31 ResourceFormat resource_format, | |
| 32 const Resource* resource, | |
| 33 uint64_t previous_content_id) | |
| 34 : worker_pool_(worker_pool), | |
| 35 resource_(resource), | |
| 36 lock_(resource_provider, resource->id()), | |
| 37 previous_content_id_(previous_content_id) {} | |
| 38 | |
| 39 ~RasterBufferImpl() override {} | |
| 40 | |
| 41 // Overridden from RasterBuffer: | |
| 42 void Playback( | |
| 43 const RasterSource* raster_source, | |
| 44 const gfx::Rect& raster_full_rect, | |
| 45 const gfx::Rect& raster_dirty_rect, | |
| 46 uint64_t new_content_id, | |
| 47 float scale, | |
| 48 const RasterSource::PlaybackSettings& playback_settings) override { | |
| 49 TRACE_EVENT0("cc", "OneCopyRasterBuffer::Playback"); | |
| 50 worker_pool_->PlaybackAndCopyOnWorkerThread( | |
| 51 resource_, &lock_, raster_source, raster_full_rect, raster_dirty_rect, | |
| 52 scale, playback_settings, previous_content_id_, new_content_id); | |
| 53 } | |
| 54 | |
| 55 private: | |
| 56 OneCopyRasterBufferProvider* worker_pool_; | |
| 57 const Resource* resource_; | |
| 58 ResourceProvider::ScopedWriteLockGL lock_; | |
| 59 uint64_t previous_content_id_; | |
| 60 | |
| 61 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | |
| 62 }; | |
| 63 | |
| 64 // 4MiB is the size of 4 512x512 tiles, which has proven to be a good | 27 // 4MiB is the size of 4 512x512 tiles, which has proven to be a good |
| 65 // default batch size for copy operations. | 28 // default batch size for copy operations. |
| 66 const int kMaxBytesPerCopyOperation = 1024 * 1024 * 4; | 29 const int kMaxBytesPerCopyOperation = 1024 * 1024 * 4; |
| 67 | 30 |
| 68 } // namespace | 31 } // namespace |
| 69 | 32 |
| 33 OneCopyRasterBufferProvider::RasterBufferImpl::RasterBufferImpl( |
| 34 OneCopyRasterBufferProvider* client, |
| 35 ResourceProvider* resource_provider, |
| 36 const Resource* resource, |
| 37 uint64_t previous_content_id, |
| 38 bool async_worker_context_enabled) |
| 39 : client_(client), |
| 40 resource_(resource), |
| 41 lock_(resource_provider, resource->id(), async_worker_context_enabled), |
| 42 previous_content_id_(previous_content_id) { |
| 43 client_->pending_raster_buffers_.insert(this); |
| 44 } |
| 45 |
| 46 OneCopyRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { |
| 47 client_->pending_raster_buffers_.erase(this); |
| 48 } |
| 49 |
| 50 void OneCopyRasterBufferProvider::RasterBufferImpl::Playback( |
| 51 const RasterSource* raster_source, |
| 52 const gfx::Rect& raster_full_rect, |
| 53 const gfx::Rect& raster_dirty_rect, |
| 54 uint64_t new_content_id, |
| 55 float scale, |
| 56 const RasterSource::PlaybackSettings& playback_settings) { |
| 57 TRACE_EVENT0("cc", "OneCopyRasterBuffer::Playback"); |
| 58 client_->PlaybackAndCopyOnWorkerThread( |
| 59 resource_, &lock_, sync_token_, raster_source, raster_full_rect, |
| 60 raster_dirty_rect, scale, playback_settings, previous_content_id_, |
| 61 new_content_id); |
| 62 } |
| 63 |
| 70 OneCopyRasterBufferProvider::OneCopyRasterBufferProvider( | 64 OneCopyRasterBufferProvider::OneCopyRasterBufferProvider( |
| 71 base::SequencedTaskRunner* task_runner, | 65 base::SequencedTaskRunner* task_runner, |
| 72 ContextProvider* compositor_context_provider, | 66 ContextProvider* compositor_context_provider, |
| 73 ContextProvider* worker_context_provider, | 67 ContextProvider* worker_context_provider, |
| 74 ResourceProvider* resource_provider, | 68 ResourceProvider* resource_provider, |
| 75 int max_copy_texture_chromium_size, | 69 int max_copy_texture_chromium_size, |
| 76 bool use_partial_raster, | 70 bool use_partial_raster, |
| 77 int max_staging_buffer_usage_in_bytes, | 71 int max_staging_buffer_usage_in_bytes, |
| 78 ResourceFormat preferred_tile_format) | 72 ResourceFormat preferred_tile_format, |
| 73 bool async_worker_context_enabled) |
| 79 : compositor_context_provider_(compositor_context_provider), | 74 : compositor_context_provider_(compositor_context_provider), |
| 80 worker_context_provider_(worker_context_provider), | 75 worker_context_provider_(worker_context_provider), |
| 81 resource_provider_(resource_provider), | 76 resource_provider_(resource_provider), |
| 82 max_bytes_per_copy_operation_( | 77 max_bytes_per_copy_operation_( |
| 83 max_copy_texture_chromium_size | 78 max_copy_texture_chromium_size |
| 84 ? std::min(kMaxBytesPerCopyOperation, | 79 ? std::min(kMaxBytesPerCopyOperation, |
| 85 max_copy_texture_chromium_size) | 80 max_copy_texture_chromium_size) |
| 86 : kMaxBytesPerCopyOperation), | 81 : kMaxBytesPerCopyOperation), |
| 87 use_partial_raster_(use_partial_raster), | 82 use_partial_raster_(use_partial_raster), |
| 88 bytes_scheduled_since_last_flush_(0), | 83 bytes_scheduled_since_last_flush_(0), |
| 89 preferred_tile_format_(preferred_tile_format), | 84 preferred_tile_format_(preferred_tile_format), |
| 90 staging_pool_(task_runner, | 85 staging_pool_(task_runner, |
| 91 worker_context_provider, | 86 worker_context_provider, |
| 92 resource_provider, | 87 resource_provider, |
| 93 use_partial_raster, | 88 use_partial_raster, |
| 94 max_staging_buffer_usage_in_bytes) { | 89 max_staging_buffer_usage_in_bytes), |
| 95 DCHECK(compositor_context_provider_); | 90 async_worker_context_enabled_(async_worker_context_enabled) { |
| 91 DCHECK(compositor_context_provider); |
| 96 DCHECK(worker_context_provider); | 92 DCHECK(worker_context_provider); |
| 97 } | 93 } |
| 98 | 94 |
| 99 OneCopyRasterBufferProvider::~OneCopyRasterBufferProvider() {} | 95 OneCopyRasterBufferProvider::~OneCopyRasterBufferProvider() { |
| 96 DCHECK(pending_raster_buffers_.empty()); |
| 97 } |
| 100 | 98 |
| 101 std::unique_ptr<RasterBuffer> | 99 std::unique_ptr<RasterBuffer> |
| 102 OneCopyRasterBufferProvider::AcquireBufferForRaster( | 100 OneCopyRasterBufferProvider::AcquireBufferForRaster( |
| 103 const Resource* resource, | 101 const Resource* resource, |
| 104 uint64_t resource_content_id, | 102 uint64_t resource_content_id, |
| 105 uint64_t previous_content_id) { | 103 uint64_t previous_content_id) { |
| 106 // TODO(danakj): If resource_content_id != 0, we only need to copy/upload | 104 // TODO(danakj): If resource_content_id != 0, we only need to copy/upload |
| 107 // the dirty rect. | 105 // the dirty rect. |
| 108 return base::WrapUnique<RasterBuffer>( | 106 return base::WrapUnique(new RasterBufferImpl(this, resource_provider_, |
| 109 new RasterBufferImpl(this, resource_provider_, resource->format(), | 107 resource, previous_content_id, |
| 110 resource, previous_content_id)); | 108 async_worker_context_enabled_)); |
| 111 } | 109 } |
| 112 | 110 |
| 113 void OneCopyRasterBufferProvider::ReleaseBufferForRaster( | 111 void OneCopyRasterBufferProvider::ReleaseBufferForRaster( |
| 114 std::unique_ptr<RasterBuffer> buffer) { | 112 std::unique_ptr<RasterBuffer> buffer) { |
| 115 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 113 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
| 116 } | 114 } |
| 117 | 115 |
| 118 void OneCopyRasterBufferProvider::OrderingBarrier() { | 116 void OneCopyRasterBufferProvider::OrderingBarrier() { |
| 119 TRACE_EVENT0("cc", "OneCopyRasterBufferProvider::OrderingBarrier"); | 117 TRACE_EVENT0("cc", "OneCopyRasterBufferProvider::OrderingBarrier"); |
| 120 compositor_context_provider_->ContextGL()->OrderingBarrierCHROMIUM(); | 118 |
| 119 gpu::gles2::GLES2Interface* gl = compositor_context_provider_->ContextGL(); |
| 120 if (async_worker_context_enabled_) { |
| 121 GLuint64 fence = gl->InsertFenceSyncCHROMIUM(); |
| 122 gl->OrderingBarrierCHROMIUM(); |
| 123 |
| 124 gpu::SyncToken sync_token; |
| 125 gl->GenUnverifiedSyncTokenCHROMIUM(fence, sync_token.GetData()); |
| 126 |
| 127 DCHECK(sync_token.HasData() || |
| 128 gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR); |
| 129 |
| 130 for (RasterBufferImpl* buffer : pending_raster_buffers_) |
| 131 buffer->set_sync_token(sync_token); |
| 132 } else { |
| 133 gl->OrderingBarrierCHROMIUM(); |
| 134 } |
| 135 pending_raster_buffers_.clear(); |
| 121 } | 136 } |
| 122 | 137 |
| 123 ResourceFormat OneCopyRasterBufferProvider::GetResourceFormat( | 138 ResourceFormat OneCopyRasterBufferProvider::GetResourceFormat( |
| 124 bool must_support_alpha) const { | 139 bool must_support_alpha) const { |
| 125 if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && | 140 if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && |
| 126 (DoesResourceFormatSupportAlpha(preferred_tile_format_) || | 141 (DoesResourceFormatSupportAlpha(preferred_tile_format_) || |
| 127 !must_support_alpha)) { | 142 !must_support_alpha)) { |
| 128 return preferred_tile_format_; | 143 return preferred_tile_format_; |
| 129 } | 144 } |
| 130 | 145 |
| 131 return resource_provider_->best_texture_format(); | 146 return resource_provider_->best_texture_format(); |
| 132 } | 147 } |
| 133 | 148 |
| 134 bool OneCopyRasterBufferProvider::GetResourceRequiresSwizzle( | 149 bool OneCopyRasterBufferProvider::GetResourceRequiresSwizzle( |
| 135 bool must_support_alpha) const { | 150 bool must_support_alpha) const { |
| 136 return ResourceFormatRequiresSwizzle(GetResourceFormat(must_support_alpha)); | 151 return ResourceFormatRequiresSwizzle(GetResourceFormat(must_support_alpha)); |
| 137 } | 152 } |
| 138 | 153 |
| 139 void OneCopyRasterBufferProvider::Shutdown() { | 154 void OneCopyRasterBufferProvider::Shutdown() { |
| 140 staging_pool_.Shutdown(); | 155 staging_pool_.Shutdown(); |
| 156 pending_raster_buffers_.clear(); |
| 141 } | 157 } |
| 142 | 158 |
| 143 void OneCopyRasterBufferProvider::PlaybackAndCopyOnWorkerThread( | 159 void OneCopyRasterBufferProvider::PlaybackAndCopyOnWorkerThread( |
| 144 const Resource* resource, | 160 const Resource* resource, |
| 145 ResourceProvider::ScopedWriteLockGL* resource_lock, | 161 ResourceProvider::ScopedWriteLockGL* resource_lock, |
| 162 const gpu::SyncToken& sync_token, |
| 146 const RasterSource* raster_source, | 163 const RasterSource* raster_source, |
| 147 const gfx::Rect& raster_full_rect, | 164 const gfx::Rect& raster_full_rect, |
| 148 const gfx::Rect& raster_dirty_rect, | 165 const gfx::Rect& raster_dirty_rect, |
| 149 float scale, | 166 float scale, |
| 150 const RasterSource::PlaybackSettings& playback_settings, | 167 const RasterSource::PlaybackSettings& playback_settings, |
| 151 uint64_t previous_content_id, | 168 uint64_t previous_content_id, |
| 152 uint64_t new_content_id) { | 169 uint64_t new_content_id) { |
| 170 if (async_worker_context_enabled_) { |
| 171 // Early out if sync token is invalid. This happens if the compositor |
| 172 // context was lost before ScheduleTasks was called. |
| 173 if (!sync_token.HasData()) |
| 174 return; |
| 175 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); |
| 176 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
| 177 DCHECK(gl); |
| 178 // Synchronize with compositor. |
| 179 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
| 180 } |
| 181 |
| 153 std::unique_ptr<StagingBuffer> staging_buffer = | 182 std::unique_ptr<StagingBuffer> staging_buffer = |
| 154 staging_pool_.AcquireStagingBuffer(resource, previous_content_id); | 183 staging_pool_.AcquireStagingBuffer(resource, previous_content_id); |
| 155 | 184 |
| 156 PlaybackToStagingBuffer(staging_buffer.get(), resource, raster_source, | 185 PlaybackToStagingBuffer(staging_buffer.get(), resource, raster_source, |
| 157 raster_full_rect, raster_dirty_rect, scale, | 186 raster_full_rect, raster_dirty_rect, scale, |
| 158 playback_settings, previous_content_id, | 187 playback_settings, previous_content_id, |
| 159 new_content_id); | 188 new_content_id); |
| 160 | 189 |
| 161 CopyOnWorkerThread(staging_buffer.get(), resource, resource_lock, | 190 CopyOnWorkerThread(staging_buffer.get(), resource_lock, sync_token, |
| 162 raster_source, previous_content_id, new_content_id); | 191 raster_source, previous_content_id, new_content_id); |
| 163 | 192 |
| 164 staging_pool_.ReleaseStagingBuffer(std::move(staging_buffer)); | 193 staging_pool_.ReleaseStagingBuffer(std::move(staging_buffer)); |
| 165 } | 194 } |
| 166 | 195 |
| 167 void OneCopyRasterBufferProvider::PlaybackToStagingBuffer( | 196 void OneCopyRasterBufferProvider::PlaybackToStagingBuffer( |
| 168 StagingBuffer* staging_buffer, | 197 StagingBuffer* staging_buffer, |
| 169 const Resource* resource, | 198 const Resource* resource, |
| 170 const RasterSource* raster_source, | 199 const RasterSource* raster_source, |
| 171 const gfx::Rect& raster_full_rect, | 200 const gfx::Rect& raster_full_rect, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 buffer->memory(0), resource->format(), staging_buffer->size, | 239 buffer->memory(0), resource->format(), staging_buffer->size, |
| 211 buffer->stride(0), raster_source, raster_full_rect, playback_rect, | 240 buffer->stride(0), raster_source, raster_full_rect, playback_rect, |
| 212 scale, playback_settings); | 241 scale, playback_settings); |
| 213 buffer->Unmap(); | 242 buffer->Unmap(); |
| 214 staging_buffer->content_id = new_content_id; | 243 staging_buffer->content_id = new_content_id; |
| 215 } | 244 } |
| 216 } | 245 } |
| 217 | 246 |
| 218 void OneCopyRasterBufferProvider::CopyOnWorkerThread( | 247 void OneCopyRasterBufferProvider::CopyOnWorkerThread( |
| 219 StagingBuffer* staging_buffer, | 248 StagingBuffer* staging_buffer, |
| 220 const Resource* resource, | |
| 221 ResourceProvider::ScopedWriteLockGL* resource_lock, | 249 ResourceProvider::ScopedWriteLockGL* resource_lock, |
| 250 const gpu::SyncToken& sync_token, |
| 222 const RasterSource* raster_source, | 251 const RasterSource* raster_source, |
| 223 uint64_t previous_content_id, | 252 uint64_t previous_content_id, |
| 224 uint64_t new_content_id) { | 253 uint64_t new_content_id) { |
| 225 { | 254 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); |
| 226 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); | 255 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
| 256 DCHECK(gl); |
| 227 | 257 |
| 228 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); | 258 // Create texture after synchronizing with compositor. |
| 229 DCHECK(gl); | 259 ResourceProvider::ScopedTextureProvider scoped_texture( |
| 260 gl, resource_lock, async_worker_context_enabled_); |
| 230 | 261 |
| 231 unsigned image_target = | 262 unsigned resource_texture_id = scoped_texture.texture_id(); |
| 232 resource_provider_->GetImageTextureTarget(resource->format()); | 263 unsigned image_target = |
| 264 resource_provider_->GetImageTextureTarget(resource_lock->format()); |
| 233 | 265 |
| 234 // Create and bind staging texture. | 266 // Create and bind staging texture. |
| 235 if (!staging_buffer->texture_id) { | 267 if (!staging_buffer->texture_id) { |
| 236 gl->GenTextures(1, &staging_buffer->texture_id); | 268 gl->GenTextures(1, &staging_buffer->texture_id); |
| 237 gl->BindTexture(image_target, staging_buffer->texture_id); | 269 gl->BindTexture(image_target, staging_buffer->texture_id); |
| 238 gl->TexParameteri(image_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 270 gl->TexParameteri(image_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 239 gl->TexParameteri(image_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 271 gl->TexParameteri(image_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 240 gl->TexParameteri(image_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 272 gl->TexParameteri(image_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 241 gl->TexParameteri(image_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 273 gl->TexParameteri(image_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 242 } else { | 274 } else { |
| 243 gl->BindTexture(image_target, staging_buffer->texture_id); | 275 gl->BindTexture(image_target, staging_buffer->texture_id); |
| 244 } | 276 } |
| 245 | 277 |
| 246 // Create and bind image. | 278 // Create and bind image. |
| 247 if (!staging_buffer->image_id) { | 279 if (!staging_buffer->image_id) { |
| 248 if (staging_buffer->gpu_memory_buffer) { | 280 if (staging_buffer->gpu_memory_buffer) { |
| 249 staging_buffer->image_id = gl->CreateImageCHROMIUM( | 281 staging_buffer->image_id = gl->CreateImageCHROMIUM( |
| 250 staging_buffer->gpu_memory_buffer->AsClientBuffer(), | 282 staging_buffer->gpu_memory_buffer->AsClientBuffer(), |
| 251 staging_buffer->size.width(), staging_buffer->size.height(), | 283 staging_buffer->size.width(), staging_buffer->size.height(), |
| 252 GLInternalFormat(resource->format())); | 284 GLInternalFormat(resource_lock->format())); |
| 253 gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id); | |
| 254 } | |
| 255 } else { | |
| 256 gl->ReleaseTexImage2DCHROMIUM(image_target, staging_buffer->image_id); | |
| 257 gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id); | 285 gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id); |
| 258 } | 286 } |
| 287 } else { |
| 288 gl->ReleaseTexImage2DCHROMIUM(image_target, staging_buffer->image_id); |
| 289 gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id); |
| 290 } |
| 259 | 291 |
| 260 // Unbind staging texture. | 292 // Unbind staging texture. |
| 261 gl->BindTexture(image_target, 0); | 293 gl->BindTexture(image_target, 0); |
| 262 | 294 |
| 263 if (resource_provider_->use_sync_query()) { | 295 if (resource_provider_->use_sync_query()) { |
| 264 if (!staging_buffer->query_id) | 296 if (!staging_buffer->query_id) |
| 265 gl->GenQueriesEXT(1, &staging_buffer->query_id); | 297 gl->GenQueriesEXT(1, &staging_buffer->query_id); |
| 266 | 298 |
| 267 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) | 299 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) |
| 268 // TODO(reveman): This avoids a performance problem on ARM ChromeOS | 300 // TODO(reveman): This avoids a performance problem on ARM ChromeOS |
| 269 // devices. crbug.com/580166 | 301 // devices. crbug.com/580166 |
| 270 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, staging_buffer->query_id); | 302 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, staging_buffer->query_id); |
| 271 #else | 303 #else |
| 272 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, | 304 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, staging_buffer->query_id); |
| 273 staging_buffer->query_id); | |
| 274 #endif | 305 #endif |
| 275 } | 306 } |
| 276 | 307 |
| 277 // Since compressed texture's cannot be pre-allocated we might have an | 308 // Since compressed texture's cannot be pre-allocated we might have an |
| 278 // unallocated resource in which case we need to perform a full size copy. | 309 // unallocated resource in which case we need to perform a full size copy. |
| 279 if (IsResourceFormatCompressed(resource->format())) { | 310 if (IsResourceFormatCompressed(resource_lock->format())) { |
| 280 gl->CompressedCopyTextureCHROMIUM(staging_buffer->texture_id, | 311 gl->CompressedCopyTextureCHROMIUM(staging_buffer->texture_id, |
| 281 resource_lock->texture_id()); | 312 resource_texture_id); |
| 282 } else { | 313 } else { |
| 283 int bytes_per_row = ResourceUtil::UncheckedWidthInBytes<int>( | 314 int bytes_per_row = ResourceUtil::UncheckedWidthInBytes<int>( |
| 284 resource->size().width(), resource->format()); | 315 resource_lock->size().width(), resource_lock->format()); |
| 285 int chunk_size_in_rows = | 316 int chunk_size_in_rows = |
| 286 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); | 317 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); |
| 287 // Align chunk size to 4. Required to support compressed texture formats. | 318 // Align chunk size to 4. Required to support compressed texture formats. |
| 288 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); | 319 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); |
| 289 int y = 0; | 320 int y = 0; |
| 290 int height = resource->size().height(); | 321 int height = resource_lock->size().height(); |
| 291 while (y < height) { | 322 while (y < height) { |
| 292 // Copy at most |chunk_size_in_rows|. | 323 // Copy at most |chunk_size_in_rows|. |
| 293 int rows_to_copy = std::min(chunk_size_in_rows, height - y); | 324 int rows_to_copy = std::min(chunk_size_in_rows, height - y); |
| 294 DCHECK_GT(rows_to_copy, 0); | 325 DCHECK_GT(rows_to_copy, 0); |
| 295 | 326 |
| 296 gl->CopySubTextureCHROMIUM( | 327 gl->CopySubTextureCHROMIUM( |
| 297 staging_buffer->texture_id, resource_lock->texture_id(), 0, y, 0, y, | 328 staging_buffer->texture_id, resource_texture_id, 0, y, 0, y, |
| 298 resource->size().width(), rows_to_copy, false, false, false); | 329 resource_lock->size().width(), rows_to_copy, false, false, false); |
| 299 y += rows_to_copy; | 330 y += rows_to_copy; |
| 300 | 331 |
| 301 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory | 332 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory |
| 302 // used for this copy operation. | 333 // used for this copy operation. |
| 303 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; | 334 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; |
| 304 | 335 |
| 305 if (bytes_scheduled_since_last_flush_ >= | 336 if (bytes_scheduled_since_last_flush_ >= max_bytes_per_copy_operation_) { |
| 306 max_bytes_per_copy_operation_) { | 337 gl->ShallowFlushCHROMIUM(); |
| 307 gl->ShallowFlushCHROMIUM(); | 338 bytes_scheduled_since_last_flush_ = 0; |
| 308 bytes_scheduled_since_last_flush_ = 0; | |
| 309 } | |
| 310 } | 339 } |
| 311 } | 340 } |
| 341 } |
| 312 | 342 |
| 313 if (resource_provider_->use_sync_query()) { | 343 if (resource_provider_->use_sync_query()) { |
| 314 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) | 344 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) |
| 315 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | 345 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
| 316 #else | 346 #else |
| 317 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 347 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); |
| 318 #endif | 348 #endif |
| 319 } | 349 } |
| 320 | 350 |
| 321 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | 351 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
| 322 | 352 |
| 323 // Barrier to sync worker context output to cc context. | 353 // Barrier to sync worker context output to cc context. |
| 324 gl->OrderingBarrierCHROMIUM(); | 354 gl->OrderingBarrierCHROMIUM(); |
| 325 | 355 |
| 326 // Generate sync token after the barrier for cross context synchronization. | 356 // Generate sync token after the barrier for cross context synchronization. |
| 327 gpu::SyncToken sync_token; | 357 gpu::SyncToken resource_sync_token; |
| 328 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 358 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData()); |
| 329 resource_lock->UpdateResourceSyncToken(sync_token); | 359 resource_lock->set_sync_token(resource_sync_token); |
| 330 } | 360 resource_lock->set_synchronized(!async_worker_context_enabled_); |
| 331 } | 361 } |
| 332 | 362 |
| 333 } // namespace cc | 363 } // namespace cc |
| OLD | NEW |