Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/exo/buffer.h" | 5 #include "components/exo/buffer.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
| 8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
| 9 #include <GLES2/gl2extchromium.h> | 9 #include <GLES2/gl2extchromium.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "base/trace_event/trace_event.h" | 22 #include "base/trace_event/trace_event.h" |
| 23 #include "base/trace_event/trace_event_argument.h" | 23 #include "base/trace_event/trace_event_argument.h" |
| 24 #include "cc/output/context_provider.h" | 24 #include "cc/output/context_provider.h" |
| 25 #include "cc/resources/single_release_callback.h" | 25 #include "cc/resources/single_release_callback.h" |
| 26 #include "cc/resources/texture_mailbox.h" | 26 #include "cc/resources/texture_mailbox.h" |
| 27 #include "gpu/command_buffer/client/context_support.h" | 27 #include "gpu/command_buffer/client/context_support.h" |
| 28 #include "gpu/command_buffer/client/gles2_interface.h" | 28 #include "gpu/command_buffer/client/gles2_interface.h" |
| 29 #include "ui/aura/env.h" | 29 #include "ui/aura/env.h" |
| 30 #include "ui/compositor/compositor.h" | 30 #include "ui/compositor/compositor.h" |
| 31 #include "ui/gfx/gpu_fence.h" | |
| 31 #include "ui/gfx/gpu_memory_buffer.h" | 32 #include "ui/gfx/gpu_memory_buffer.h" |
| 32 | 33 |
| 33 namespace exo { | 34 namespace exo { |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 36 // The amount of time before we wait for release queries using | 37 // The amount of time before we wait for release queries using |
| 37 // GetQueryObjectuivEXT(GL_QUERY_RESULT_EXT). | 38 // GetQueryObjectuivEXT(GL_QUERY_RESULT_EXT). |
| 38 const int kWaitForReleaseDelayMs = 500; | 39 const int kWaitForReleaseDelayMs = 500; |
| 39 | 40 |
| 40 GLenum GLInternalFormat(gfx::BufferFormat format) { | 41 GLenum GLInternalFormat(gfx::BufferFormat format) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 // Returns true if GLES2 resources for texture have been lost. | 110 // Returns true if GLES2 resources for texture have been lost. |
| 110 bool IsLost(); | 111 bool IsLost(); |
| 111 | 112 |
| 112 // Allow texture to be reused after |sync_token| has passed and runs | 113 // Allow texture to be reused after |sync_token| has passed and runs |
| 113 // |callback|. | 114 // |callback|. |
| 114 void Release(const base::Closure& callback, | 115 void Release(const base::Closure& callback, |
| 115 const gpu::SyncToken& sync_token, | 116 const gpu::SyncToken& sync_token, |
| 116 bool is_lost); | 117 bool is_lost); |
| 117 | 118 |
| 118 // Binds the contents referenced by |image_id_| to the texture returned by | 119 // Binds the contents referenced by |image_id_| to the texture returned by |
| 119 // mailbox(). Returns a sync token that can be used when accessing texture | 120 // mailbox(), using the fence from |fence| for synchronization. Returns a |
| 120 // from a different context. | 121 // sync token that can be used when accessing texture from a different |
| 121 gpu::SyncToken BindTexImage(); | 122 // context. |
| 123 gpu::SyncToken BindTexImage(gfx::GpuFence* fence); | |
| 122 | 124 |
| 123 // Releases the contents referenced by |image_id_| after |sync_token| has | 125 // Releases the contents referenced by |image_id_| after |sync_token| has |
| 124 // passed and runs |callback| when completed. | 126 // passed and runs |callback| when completed. |
| 125 void ReleaseTexImage(const base::Closure& callback, | 127 void ReleaseTexImage(const base::Closure& callback, |
| 126 const gpu::SyncToken& sync_token, | 128 const gpu::SyncToken& sync_token, |
| 127 bool is_lost); | 129 bool is_lost); |
| 128 | 130 |
| 129 // Copy the contents of texture to |destination| and runs |callback| when | 131 // Copy the contents of texture to |destination| and runs |callback| when |
| 130 // completed. Returns a sync token that can be used when accessing texture | 132 // completed. Returns a sync token that can be used when accessing texture |
| 131 // from a different context. | 133 // from a different context. |
| 132 gpu::SyncToken CopyTexImage(Texture* destination, | 134 gpu::SyncToken CopyTexImage(gfx::GpuFence* fence, |
| 135 Texture* destination, | |
| 133 const base::Closure& callback); | 136 const base::Closure& callback); |
| 134 | 137 |
| 135 // Returns the mailbox for this texture. | 138 // Returns the mailbox for this texture. |
| 136 gpu::Mailbox mailbox() const { return mailbox_; } | 139 gpu::Mailbox mailbox() const { return mailbox_; } |
| 137 | 140 |
| 138 private: | 141 private: |
| 139 void DestroyResources(); | 142 void DestroyResources(); |
| 140 void ReleaseWhenQueryResultIsAvailable(const base::Closure& callback); | 143 void ReleaseWhenQueryResultIsAvailable(const base::Closure& callback); |
| 141 void Released(); | 144 void Released(); |
| 142 void ScheduleWaitForRelease(base::TimeDelta delay); | 145 void ScheduleWaitForRelease(base::TimeDelta delay); |
| 143 void WaitForRelease(); | 146 void WaitForRelease(); |
| 144 | 147 |
| 145 ui::ContextFactory* context_factory_; | 148 ui::ContextFactory* context_factory_; |
| 146 scoped_refptr<cc::ContextProvider> context_provider_; | 149 scoped_refptr<cc::ContextProvider> context_provider_; |
| 147 const unsigned texture_target_; | 150 const unsigned texture_target_; |
| 148 const unsigned query_type_; | 151 const unsigned query_type_; |
| 149 const GLenum internalformat_; | 152 const GLenum internalformat_; |
| 150 unsigned image_id_ = 0; | 153 unsigned image_id_ = 0; |
| 151 unsigned query_id_ = 0; | 154 unsigned query_id_ = 0; |
| 152 unsigned texture_id_ = 0; | 155 unsigned texture_id_ = 0; |
| 156 unsigned fence_id_ = 0; | |
| 153 gpu::Mailbox mailbox_; | 157 gpu::Mailbox mailbox_; |
| 154 base::Closure release_callback_; | 158 base::Closure release_callback_; |
| 155 base::TimeTicks wait_for_release_time_; | 159 base::TimeTicks wait_for_release_time_; |
| 156 bool wait_for_release_pending_ = false; | 160 bool wait_for_release_pending_ = false; |
| 157 base::WeakPtrFactory<Texture> weak_ptr_factory_; | 161 base::WeakPtrFactory<Texture> weak_ptr_factory_; |
| 158 | 162 |
| 159 DISALLOW_COPY_AND_ASSIGN(Texture); | 163 DISALLOW_COPY_AND_ASSIGN(Texture); |
| 160 }; | 164 }; |
| 161 | 165 |
| 162 Buffer::Texture::Texture(ui::ContextFactory* context_factory, | 166 Buffer::Texture::Texture(ui::ContextFactory* context_factory, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); | 228 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); |
| 225 if (sync_token.HasData()) | 229 if (sync_token.HasData()) |
| 226 gles2->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); | 230 gles2->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
| 227 } | 231 } |
| 228 | 232 |
| 229 // Run callback as texture can be reused immediately after waiting for sync | 233 // Run callback as texture can be reused immediately after waiting for sync |
| 230 // token. | 234 // token. |
| 231 callback.Run(); | 235 callback.Run(); |
| 232 } | 236 } |
| 233 | 237 |
| 234 gpu::SyncToken Buffer::Texture::BindTexImage() { | 238 gpu::SyncToken Buffer::Texture::BindTexImage(gfx::GpuFence* fence) { |
| 235 gpu::SyncToken sync_token; | 239 gpu::SyncToken sync_token; |
| 236 if (context_provider_) { | 240 if (context_provider_) { |
| 237 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); | 241 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); |
| 238 gles2->ActiveTexture(GL_TEXTURE0); | 242 gles2->ActiveTexture(GL_TEXTURE0); |
| 239 gles2->BindTexture(texture_target_, texture_id_); | 243 gles2->BindTexture(texture_target_, texture_id_); |
| 240 DCHECK_NE(image_id_, 0u); | 244 DCHECK_NE(image_id_, 0u); |
| 241 gles2->BindTexImage2DCHROMIUM(texture_target_, image_id_, 0); | 245 if (fence) { |
| 246 fence_id_ = gles2->CreateFenceCHROMIUM(fence->AsClientFence()); | |
| 247 DCHECK_NE(fence_id_, 0u); | |
| 248 } | |
| 249 gles2->BindTexImage2DCHROMIUM(texture_target_, image_id_, fence_id_); | |
| 242 // Generate a crypto-secure random mailbox name if not already done. | 250 // Generate a crypto-secure random mailbox name if not already done. |
| 243 if (mailbox_.IsZero()) | 251 if (mailbox_.IsZero()) |
| 244 CreateGLTextureMailbox(gles2, texture_id_, texture_target_, &mailbox_); | 252 CreateGLTextureMailbox(gles2, texture_id_, texture_target_, &mailbox_); |
| 245 // Create and return a sync token that can be used to ensure that the | 253 // Create and return a sync token that can be used to ensure that the |
| 246 // BindTexImage2DCHROMIUM call is processed before issuing any commands | 254 // BindTexImage2DCHROMIUM call is processed before issuing any commands |
| 247 // that will read from the texture on a different context. | 255 // that will read from the texture on a different context. |
| 248 uint64_t fence_sync = gles2->InsertFenceSyncCHROMIUM(); | 256 uint64_t fence_sync = gles2->InsertFenceSyncCHROMIUM(); |
| 249 gles2->OrderingBarrierCHROMIUM(); | 257 gles2->OrderingBarrierCHROMIUM(); |
| 250 gles2->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 258 gles2->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
| 251 } | 259 } |
| 252 return sync_token; | 260 return sync_token; |
| 253 } | 261 } |
| 254 | 262 |
| 255 void Buffer::Texture::ReleaseTexImage(const base::Closure& callback, | 263 void Buffer::Texture::ReleaseTexImage(const base::Closure& callback, |
| 256 const gpu::SyncToken& sync_token, | 264 const gpu::SyncToken& sync_token, |
| 257 bool is_lost) { | 265 bool is_lost) { |
| 258 if (context_provider_) { | 266 if (context_provider_) { |
| 259 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); | 267 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); |
| 260 if (sync_token.HasData()) | 268 if (sync_token.HasData()) |
| 261 gles2->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); | 269 gles2->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
| 262 gles2->ActiveTexture(GL_TEXTURE0); | 270 gles2->ActiveTexture(GL_TEXTURE0); |
| 263 gles2->BindTexture(texture_target_, texture_id_); | 271 gles2->BindTexture(texture_target_, texture_id_); |
| 264 DCHECK_NE(query_id_, 0u); | 272 DCHECK_NE(query_id_, 0u); |
| 265 gles2->BeginQueryEXT(query_type_, query_id_); | 273 gles2->BeginQueryEXT(query_type_, query_id_); |
| 266 gles2->ReleaseTexImage2DCHROMIUM(texture_target_, image_id_); | 274 gles2->ReleaseTexImage2DCHROMIUM(texture_target_, image_id_); |
| 275 if (fence_id_) { | |
| 276 gles2->DestroyFenceCHROMIUM(fence_id_); | |
| 277 fence_id_ = 0; | |
| 278 } | |
| 267 gles2->EndQueryEXT(query_type_); | 279 gles2->EndQueryEXT(query_type_); |
| 268 // Run callback when query result is available and ReleaseTexImage has been | 280 // Run callback when query result is available and ReleaseTexImage has been |
| 269 // handled if sync token has data and buffer has been used. If buffer was | 281 // handled if sync token has data and buffer has been used. If buffer was |
| 270 // never used then run the callback immediately. | 282 // never used then run the callback immediately. |
| 271 if (sync_token.HasData()) { | 283 if (sync_token.HasData()) { |
| 272 ReleaseWhenQueryResultIsAvailable(callback); | 284 ReleaseWhenQueryResultIsAvailable(callback); |
| 273 return; | 285 return; |
| 274 } | 286 } |
| 275 } | 287 } |
| 276 callback.Run(); | 288 callback.Run(); |
| 277 } | 289 } |
| 278 | 290 |
| 279 gpu::SyncToken Buffer::Texture::CopyTexImage(Texture* destination, | 291 gpu::SyncToken Buffer::Texture::CopyTexImage(gfx::GpuFence* fence, |
| 292 Texture* destination, | |
| 280 const base::Closure& callback) { | 293 const base::Closure& callback) { |
| 281 gpu::SyncToken sync_token; | 294 gpu::SyncToken sync_token; |
| 282 if (context_provider_) { | 295 if (context_provider_) { |
| 283 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); | 296 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); |
| 284 gles2->ActiveTexture(GL_TEXTURE0); | 297 gles2->ActiveTexture(GL_TEXTURE0); |
| 285 gles2->BindTexture(texture_target_, texture_id_); | 298 gles2->BindTexture(texture_target_, texture_id_); |
| 286 DCHECK_NE(image_id_, 0u); | 299 DCHECK_NE(image_id_, 0u); |
| 287 gles2->BindTexImage2DCHROMIUM(texture_target_, image_id_, 0); | 300 if (fence) { |
| 301 fence_id_ = gles2->CreateFenceCHROMIUM(fence->AsClientFence()); | |
| 302 DCHECK_NE(fence_id_, 0u); | |
| 303 } | |
| 304 gles2->BindTexImage2DCHROMIUM(texture_target_, image_id_, fence_id_); | |
| 288 gles2->CopyTextureCHROMIUM(texture_id_, destination->texture_id_, | 305 gles2->CopyTextureCHROMIUM(texture_id_, destination->texture_id_, |
| 289 internalformat_, GL_UNSIGNED_BYTE, false, false, | 306 internalformat_, GL_UNSIGNED_BYTE, false, false, |
| 290 false); | 307 false); |
| 291 DCHECK_NE(query_id_, 0u); | 308 DCHECK_NE(query_id_, 0u); |
| 292 gles2->BeginQueryEXT(query_type_, query_id_); | 309 gles2->BeginQueryEXT(query_type_, query_id_); |
| 293 gles2->ReleaseTexImage2DCHROMIUM(texture_target_, image_id_); | 310 gles2->ReleaseTexImage2DCHROMIUM(texture_target_, image_id_); |
| 311 if (fence_id_) { | |
| 312 gles2->DestroyFenceCHROMIUM(fence_id_); | |
| 313 fence_id_ = 0; | |
| 314 } | |
| 294 gles2->EndQueryEXT(query_type_); | 315 gles2->EndQueryEXT(query_type_); |
| 295 // Run callback when query result is available and ReleaseTexImage has been | 316 // Run callback when query result is available and ReleaseTexImage has been |
| 296 // handled. | 317 // handled. |
| 297 ReleaseWhenQueryResultIsAvailable(callback); | 318 ReleaseWhenQueryResultIsAvailable(callback); |
| 298 // Create and return a sync token that can be used to ensure that the | 319 // Create and return a sync token that can be used to ensure that the |
| 299 // CopyTextureCHROMIUM call is processed before issuing any commands | 320 // CopyTextureCHROMIUM call is processed before issuing any commands |
| 300 // that will read from the target texture on a different context. | 321 // that will read from the target texture on a different context. |
| 301 uint64_t fence_sync = gles2->InsertFenceSyncCHROMIUM(); | 322 uint64_t fence_sync = gles2->InsertFenceSyncCHROMIUM(); |
| 302 gles2->OrderingBarrierCHROMIUM(); | 323 gles2->OrderingBarrierCHROMIUM(); |
| 303 gles2->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 324 gles2->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
| 304 } | 325 } |
| 305 return sync_token; | 326 return sync_token; |
| 306 } | 327 } |
| 307 | 328 |
| 308 void Buffer::Texture::DestroyResources() { | 329 void Buffer::Texture::DestroyResources() { |
| 309 if (context_provider_) { | 330 if (context_provider_) { |
| 310 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); | 331 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); |
| 311 gles2->DeleteTextures(1, &texture_id_); | 332 gles2->DeleteTextures(1, &texture_id_); |
| 312 if (query_id_) | 333 if (query_id_) |
| 313 gles2->DeleteQueriesEXT(1, &query_id_); | 334 gles2->DeleteQueriesEXT(1, &query_id_); |
| 314 if (image_id_) | 335 if (image_id_) |
| 315 gles2->DestroyImageCHROMIUM(image_id_); | 336 gles2->DestroyImageCHROMIUM(image_id_); |
| 337 if (fence_id_) | |
| 338 gles2->DestroyFenceCHROMIUM(fence_id_); | |
| 316 } | 339 } |
| 317 } | 340 } |
| 318 | 341 |
| 319 void Buffer::Texture::ReleaseWhenQueryResultIsAvailable( | 342 void Buffer::Texture::ReleaseWhenQueryResultIsAvailable( |
| 320 const base::Closure& callback) { | 343 const base::Closure& callback) { |
| 321 DCHECK(context_provider_); | 344 DCHECK(context_provider_); |
| 322 DCHECK(release_callback_.is_null()); | 345 DCHECK(release_callback_.is_null()); |
| 323 release_callback_ = callback; | 346 release_callback_ = callback; |
| 324 base::TimeDelta wait_for_release_delay = | 347 base::TimeDelta wait_for_release_delay = |
| 325 base::TimeDelta::FromMilliseconds(kWaitForReleaseDelayMs); | 348 base::TimeDelta::FromMilliseconds(kWaitForReleaseDelayMs); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 : gpu_memory_buffer_(std::move(gpu_memory_buffer)), | 416 : gpu_memory_buffer_(std::move(gpu_memory_buffer)), |
| 394 texture_target_(texture_target), | 417 texture_target_(texture_target), |
| 395 query_type_(query_type), | 418 query_type_(query_type), |
| 396 use_zero_copy_(use_zero_copy), | 419 use_zero_copy_(use_zero_copy), |
| 397 is_overlay_candidate_(is_overlay_candidate) {} | 420 is_overlay_candidate_(is_overlay_candidate) {} |
| 398 | 421 |
| 399 Buffer::~Buffer() {} | 422 Buffer::~Buffer() {} |
| 400 | 423 |
| 401 std::unique_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox( | 424 std::unique_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox( |
| 402 cc::TextureMailbox* texture_mailbox, | 425 cc::TextureMailbox* texture_mailbox, |
| 426 gfx::GpuFence* fence, | |
| 403 bool secure_output_only, | 427 bool secure_output_only, |
| 404 bool client_usage) { | 428 bool client_usage) { |
| 405 DCHECK(attach_count_); | 429 DCHECK(attach_count_); |
| 406 DLOG_IF(WARNING, use_count_ && client_usage) | 430 DLOG_IF(WARNING, use_count_ && client_usage) |
| 407 << "Producing a texture mailbox for a buffer that has not been released"; | 431 << "Producing a texture mailbox for a buffer that has not been released"; |
| 408 | 432 |
| 409 // Some clients think that they can reuse a buffer before it's released by | 433 // Some clients think that they can reuse a buffer before it's released by |
| 410 // performing a fast blit into the buffer. This behavior is bad as it prevents | 434 // performing a fast blit into the buffer. This behavior is bad as it prevents |
| 411 // the client from knowing when the buffer is actually released (e.g. the | 435 // the client from knowing when the buffer is actually released (e.g. the |
| 412 // release notification for the previous use of buffer can arrive after the | 436 // release notification for the previous use of buffer can arrive after the |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 443 contents_texture_ = base::MakeUnique<Texture>( | 467 contents_texture_ = base::MakeUnique<Texture>( |
| 444 context_factory, context_provider.get(), gpu_memory_buffer_.get(), | 468 context_factory, context_provider.get(), gpu_memory_buffer_.get(), |
| 445 texture_target_, query_type_); | 469 texture_target_, query_type_); |
| 446 } | 470 } |
| 447 | 471 |
| 448 if (use_zero_copy_) { | 472 if (use_zero_copy_) { |
| 449 // Zero-copy means using the contents texture directly. | 473 // Zero-copy means using the contents texture directly. |
| 450 Texture* texture = contents_texture_.get(); | 474 Texture* texture = contents_texture_.get(); |
| 451 | 475 |
| 452 // This binds the latest contents of this buffer to |texture|. | 476 // This binds the latest contents of this buffer to |texture|. |
| 453 gpu::SyncToken sync_token = texture->BindTexImage(); | 477 gpu::SyncToken sync_token = texture->BindTexImage(std::move(fence)); |
|
reveman
2016/10/13 17:13:51
nit: not need for std::move here anymore now that
| |
| 454 | 478 |
| 455 *texture_mailbox = | 479 *texture_mailbox = |
| 456 cc::TextureMailbox(texture->mailbox(), sync_token, texture_target_, | 480 cc::TextureMailbox(texture->mailbox(), sync_token, texture_target_, |
| 457 gpu_memory_buffer_->GetSize(), is_overlay_candidate_, | 481 gpu_memory_buffer_->GetSize(), is_overlay_candidate_, |
| 458 secure_output_only); | 482 secure_output_only); |
| 459 // The contents texture will be released when no longer used by the | 483 // The contents texture will be released when no longer used by the |
| 460 // compositor. | 484 // compositor. |
| 461 return cc::SingleReleaseCallback::Create( | 485 return cc::SingleReleaseCallback::Create( |
| 462 base::Bind(&Buffer::Texture::ReleaseTexImage, base::Unretained(texture), | 486 base::Bind(&Buffer::Texture::ReleaseTexImage, base::Unretained(texture), |
| 463 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), | 487 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), |
| 464 base::Passed(&contents_texture_)))); | 488 base::Passed(&contents_texture_)))); |
| 465 } | 489 } |
| 466 | 490 |
| 467 // Create a mailbox texture that we copy the buffer contents to. | 491 // Create a mailbox texture that we copy the buffer contents to. |
| 468 if (!texture_) { | 492 if (!texture_) { |
| 469 texture_ = | 493 texture_ = |
| 470 base::MakeUnique<Texture>(context_factory, context_provider.get()); | 494 base::MakeUnique<Texture>(context_factory, context_provider.get()); |
| 471 } | 495 } |
| 472 | 496 |
| 473 // Copy the contents of |contents_texture| to |texture| and produce a | 497 // Copy the contents of |contents_texture| to |texture| and produce a |
| 474 // texture mailbox from the result in |texture|. | 498 // texture mailbox from the result in |texture|. |
| 475 Texture* contents_texture = contents_texture_.get(); | 499 Texture* contents_texture = contents_texture_.get(); |
| 476 Texture* texture = texture_.get(); | 500 Texture* texture = texture_.get(); |
| 477 | 501 |
| 478 // The contents texture will be released when copy has completed. | 502 // The contents texture will be released when copy has completed. |
| 479 gpu::SyncToken sync_token = contents_texture->CopyTexImage( | 503 gpu::SyncToken sync_token = contents_texture->CopyTexImage( |
| 480 texture, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), | 504 std::move(fence), texture, |
|
reveman
2016/10/13 17:13:51
nit: same here
| |
| 481 base::Passed(&contents_texture_))); | 505 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), |
| 506 base::Passed(&contents_texture_))); | |
| 482 *texture_mailbox = | 507 *texture_mailbox = |
| 483 cc::TextureMailbox(texture->mailbox(), sync_token, GL_TEXTURE_2D, | 508 cc::TextureMailbox(texture->mailbox(), sync_token, GL_TEXTURE_2D, |
| 484 gpu_memory_buffer_->GetSize(), | 509 gpu_memory_buffer_->GetSize(), |
| 485 false /* is_overlay_candidate */, secure_output_only); | 510 false /* is_overlay_candidate */, secure_output_only); |
| 486 // The mailbox texture will be released when no longer used by the | 511 // The mailbox texture will be released when no longer used by the |
| 487 // compositor. | 512 // compositor. |
| 488 return cc::SingleReleaseCallback::Create( | 513 return cc::SingleReleaseCallback::Create( |
| 489 base::Bind(&Buffer::Texture::Release, base::Unretained(texture), | 514 base::Bind(&Buffer::Texture::Release, base::Unretained(texture), |
| 490 base::Bind(&Buffer::ReleaseTexture, AsWeakPtr(), | 515 base::Bind(&Buffer::ReleaseTexture, AsWeakPtr(), |
| 491 base::Passed(&texture_)))); | 516 base::Passed(&texture_)))); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 } | 566 } |
| 542 | 567 |
| 543 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { | 568 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { |
| 544 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); | 569 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); |
| 545 | 570 |
| 546 contents_texture_ = std::move(texture); | 571 contents_texture_ = std::move(texture); |
| 547 Release(); | 572 Release(); |
| 548 } | 573 } |
| 549 | 574 |
| 550 } // namespace exo | 575 } // namespace exo |
| OLD | NEW |