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