Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: components/exo/buffer.cc

Issue 2404513002: exo: Implement zcr_linux_explicit_synchronization_v1
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(). Returns a sync token that can be used when accessing texture
120 // from a different context. 121 // from a different context.
121 gpu::SyncToken BindTexImage(); 122 gpu::SyncToken BindTexImage(std::unique_ptr<gfx::GpuFence> acquire_fence);
122 123
123 // Releases the contents referenced by |image_id_| after |sync_token| has 124 // Releases the contents referenced by |image_id_| after |sync_token| has
124 // passed and runs |callback| when completed. 125 // passed and runs |callback| when completed.
125 void ReleaseTexImage(const base::Closure& callback, 126 void ReleaseTexImage(const base::Closure& callback,
126 const gpu::SyncToken& sync_token, 127 const gpu::SyncToken& sync_token,
127 bool is_lost); 128 bool is_lost);
128 129
129 // Copy the contents of texture to |destination| and runs |callback| when 130 // Copy the contents of texture to |destination| and runs |callback| when
130 // completed. Returns a sync token that can be used when accessing texture 131 // completed. Returns a sync token that can be used when accessing texture
131 // from a different context. 132 // from a different context.
132 gpu::SyncToken CopyTexImage(Texture* destination, 133 gpu::SyncToken CopyTexImage(std::unique_ptr<gfx::GpuFence> acquire_fence,
134 Texture* destination,
133 const base::Closure& callback); 135 const base::Closure& callback);
134 136
135 // Returns the mailbox for this texture. 137 // Returns the mailbox for this texture.
136 gpu::Mailbox mailbox() const { return mailbox_; } 138 gpu::Mailbox mailbox() const { return mailbox_; }
137 139
138 private: 140 private:
139 void DestroyResources(); 141 void DestroyResources();
140 void ReleaseWhenQueryResultIsAvailable(const base::Closure& callback); 142 void ReleaseWhenQueryResultIsAvailable(const base::Closure& callback);
141 void Released(); 143 void Released();
142 void ScheduleWaitForRelease(base::TimeDelta delay); 144 void ScheduleWaitForRelease(base::TimeDelta delay);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); 226 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL();
225 if (sync_token.HasData()) 227 if (sync_token.HasData())
226 gles2->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); 228 gles2->WaitSyncTokenCHROMIUM(sync_token.GetConstData());
227 } 229 }
228 230
229 // Run callback as texture can be reused immediately after waiting for sync 231 // Run callback as texture can be reused immediately after waiting for sync
230 // token. 232 // token.
231 callback.Run(); 233 callback.Run();
232 } 234 }
233 235
234 gpu::SyncToken Buffer::Texture::BindTexImage() { 236 gpu::SyncToken Buffer::Texture::BindTexImage(std::unique_ptr<gfx::GpuFence> acqu ire_fence) {
235 gpu::SyncToken sync_token; 237 gpu::SyncToken sync_token;
236 if (context_provider_) { 238 if (context_provider_) {
239 GLuint fence_id = 0;
237 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); 240 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL();
238 gles2->ActiveTexture(GL_TEXTURE0); 241 gles2->ActiveTexture(GL_TEXTURE0);
239 gles2->BindTexture(texture_target_, texture_id_); 242 gles2->BindTexture(texture_target_, texture_id_);
240 DCHECK_NE(image_id_, 0u); 243 DCHECK_NE(image_id_, 0u);
241 gles2->BindTexImage2DCHROMIUM(texture_target_, image_id_, 0); 244 if (acquire_fence) {
245 fence_id = glCreateFenceCHROMIUM(acquire_fence->AsClientFence());
reveman 2016/10/09 19:03:16 Please use gles2->CreateFenceCHROMIUM here and it
fooishbar 2016/10/12 15:41:55 Oops, yes. Where would we defer it though? I can h
246 DCHECK_NE(fence_id, 0u);
247 }
248 gles2->BindTexImage2DCHROMIUM(texture_target_, image_id_, fence_id);
242 // Generate a crypto-secure random mailbox name if not already done. 249 // Generate a crypto-secure random mailbox name if not already done.
243 if (mailbox_.IsZero()) 250 if (mailbox_.IsZero())
244 CreateGLTextureMailbox(gles2, texture_id_, texture_target_, &mailbox_); 251 CreateGLTextureMailbox(gles2, texture_id_, texture_target_, &mailbox_);
245 // Create and return a sync token that can be used to ensure that the 252 // Create and return a sync token that can be used to ensure that the
246 // BindTexImage2DCHROMIUM call is processed before issuing any commands 253 // BindTexImage2DCHROMIUM call is processed before issuing any commands
247 // that will read from the texture on a different context. 254 // that will read from the texture on a different context.
248 uint64_t fence_sync = gles2->InsertFenceSyncCHROMIUM(); 255 uint64_t fence_sync = gles2->InsertFenceSyncCHROMIUM();
249 gles2->OrderingBarrierCHROMIUM(); 256 gles2->OrderingBarrierCHROMIUM();
250 gles2->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); 257 gles2->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData());
251 } 258 }
(...skipping 17 matching lines...) Expand all
269 // handled if sync token has data and buffer has been used. If buffer was 276 // handled if sync token has data and buffer has been used. If buffer was
270 // never used then run the callback immediately. 277 // never used then run the callback immediately.
271 if (sync_token.HasData()) { 278 if (sync_token.HasData()) {
272 ReleaseWhenQueryResultIsAvailable(callback); 279 ReleaseWhenQueryResultIsAvailable(callback);
273 return; 280 return;
274 } 281 }
275 } 282 }
276 callback.Run(); 283 callback.Run();
277 } 284 }
278 285
279 gpu::SyncToken Buffer::Texture::CopyTexImage(Texture* destination, 286 gpu::SyncToken Buffer::Texture::CopyTexImage(std::unique_ptr<gfx::GpuFence> acqu ire_fence,
287 Texture* destination,
280 const base::Closure& callback) { 288 const base::Closure& callback) {
281 gpu::SyncToken sync_token; 289 gpu::SyncToken sync_token;
282 if (context_provider_) { 290 if (context_provider_) {
291 GLuint fence_id = 0;
283 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); 292 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL();
284 gles2->ActiveTexture(GL_TEXTURE0); 293 gles2->ActiveTexture(GL_TEXTURE0);
285 gles2->BindTexture(texture_target_, texture_id_); 294 gles2->BindTexture(texture_target_, texture_id_);
286 DCHECK_NE(image_id_, 0u); 295 DCHECK_NE(image_id_, 0u);
287 gles2->BindTexImage2DCHROMIUM(texture_target_, image_id_, 0); 296 if (acquire_fence) {
297 fence_id = glCreateFenceCHROMIUM(acquire_fence->AsClientFence());
reveman 2016/10/09 19:03:16 ditto
298 DCHECK_NE(fence_id, 0u);
299 }
300 gles2->BindTexImage2DCHROMIUM(texture_target_, image_id_, fence_id);
288 gles2->CopyTextureCHROMIUM(texture_id_, destination->texture_id_, 301 gles2->CopyTextureCHROMIUM(texture_id_, destination->texture_id_,
289 internalformat_, GL_UNSIGNED_BYTE, false, false, 302 internalformat_, GL_UNSIGNED_BYTE, false, false,
290 false); 303 false);
291 DCHECK_NE(query_id_, 0u); 304 DCHECK_NE(query_id_, 0u);
292 gles2->BeginQueryEXT(query_type_, query_id_); 305 gles2->BeginQueryEXT(query_type_, query_id_);
293 gles2->ReleaseTexImage2DCHROMIUM(texture_target_, image_id_); 306 gles2->ReleaseTexImage2DCHROMIUM(texture_target_, image_id_);
294 gles2->EndQueryEXT(query_type_); 307 gles2->EndQueryEXT(query_type_);
295 // Run callback when query result is available and ReleaseTexImage has been 308 // Run callback when query result is available and ReleaseTexImage has been
296 // handled. 309 // handled.
297 ReleaseWhenQueryResultIsAvailable(callback); 310 ReleaseWhenQueryResultIsAvailable(callback);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 : gpu_memory_buffer_(std::move(gpu_memory_buffer)), 406 : gpu_memory_buffer_(std::move(gpu_memory_buffer)),
394 texture_target_(texture_target), 407 texture_target_(texture_target),
395 query_type_(query_type), 408 query_type_(query_type),
396 use_zero_copy_(use_zero_copy), 409 use_zero_copy_(use_zero_copy),
397 is_overlay_candidate_(is_overlay_candidate) {} 410 is_overlay_candidate_(is_overlay_candidate) {}
398 411
399 Buffer::~Buffer() {} 412 Buffer::~Buffer() {}
400 413
401 std::unique_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox( 414 std::unique_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox(
402 cc::TextureMailbox* texture_mailbox, 415 cc::TextureMailbox* texture_mailbox,
416 std::unique_ptr<gfx::GpuFence> acquire_fence,
403 bool secure_output_only, 417 bool secure_output_only,
404 bool client_usage) { 418 bool client_usage) {
405 DCHECK(attach_count_); 419 DCHECK(attach_count_);
406 DLOG_IF(WARNING, use_count_ && client_usage) 420 DLOG_IF(WARNING, use_count_ && client_usage)
407 << "Producing a texture mailbox for a buffer that has not been released"; 421 << "Producing a texture mailbox for a buffer that has not been released";
408 422
409 // Some clients think that they can reuse a buffer before it's released by 423 // 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 424 // 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 425 // 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 426 // release notification for the previous use of buffer can arrive after the
(...skipping 30 matching lines...) Expand all
443 contents_texture_ = base::MakeUnique<Texture>( 457 contents_texture_ = base::MakeUnique<Texture>(
444 context_factory, context_provider.get(), gpu_memory_buffer_.get(), 458 context_factory, context_provider.get(), gpu_memory_buffer_.get(),
445 texture_target_, query_type_); 459 texture_target_, query_type_);
446 } 460 }
447 461
448 if (use_zero_copy_) { 462 if (use_zero_copy_) {
449 // Zero-copy means using the contents texture directly. 463 // Zero-copy means using the contents texture directly.
450 Texture* texture = contents_texture_.get(); 464 Texture* texture = contents_texture_.get();
451 465
452 // This binds the latest contents of this buffer to |texture|. 466 // This binds the latest contents of this buffer to |texture|.
453 gpu::SyncToken sync_token = texture->BindTexImage(); 467 gpu::SyncToken sync_token = texture->BindTexImage(std::move(acquire_fence));
454 468
455 *texture_mailbox = 469 *texture_mailbox =
456 cc::TextureMailbox(texture->mailbox(), sync_token, texture_target_, 470 cc::TextureMailbox(texture->mailbox(), sync_token, texture_target_,
457 gpu_memory_buffer_->GetSize(), is_overlay_candidate_, 471 gpu_memory_buffer_->GetSize(), is_overlay_candidate_,
458 secure_output_only); 472 secure_output_only);
459 // The contents texture will be released when no longer used by the 473 // The contents texture will be released when no longer used by the
460 // compositor. 474 // compositor.
461 return cc::SingleReleaseCallback::Create( 475 return cc::SingleReleaseCallback::Create(
462 base::Bind(&Buffer::Texture::ReleaseTexImage, base::Unretained(texture), 476 base::Bind(&Buffer::Texture::ReleaseTexImage, base::Unretained(texture),
463 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), 477 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(),
464 base::Passed(&contents_texture_)))); 478 base::Passed(&contents_texture_))));
465 } 479 }
466 480
467 // Create a mailbox texture that we copy the buffer contents to. 481 // Create a mailbox texture that we copy the buffer contents to.
468 if (!texture_) { 482 if (!texture_) {
469 texture_ = 483 texture_ =
470 base::MakeUnique<Texture>(context_factory, context_provider.get()); 484 base::MakeUnique<Texture>(context_factory, context_provider.get());
471 } 485 }
472 486
473 // Copy the contents of |contents_texture| to |texture| and produce a 487 // Copy the contents of |contents_texture| to |texture| and produce a
474 // texture mailbox from the result in |texture|. 488 // texture mailbox from the result in |texture|.
475 Texture* contents_texture = contents_texture_.get(); 489 Texture* contents_texture = contents_texture_.get();
476 Texture* texture = texture_.get(); 490 Texture* texture = texture_.get();
477 491
478 // The contents texture will be released when copy has completed. 492 // The contents texture will be released when copy has completed.
479 gpu::SyncToken sync_token = contents_texture->CopyTexImage( 493 gpu::SyncToken sync_token = contents_texture->CopyTexImage(std::move(acquire_f ence),
480 texture, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), 494 texture, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(),
481 base::Passed(&contents_texture_))); 495 base::Passed(&contents_texture_)));
482 *texture_mailbox = 496 *texture_mailbox =
483 cc::TextureMailbox(texture->mailbox(), sync_token, GL_TEXTURE_2D, 497 cc::TextureMailbox(texture->mailbox(), sync_token, GL_TEXTURE_2D,
484 gpu_memory_buffer_->GetSize(), 498 gpu_memory_buffer_->GetSize(),
485 false /* is_overlay_candidate */, secure_output_only); 499 false /* is_overlay_candidate */, secure_output_only);
486 // The mailbox texture will be released when no longer used by the 500 // The mailbox texture will be released when no longer used by the
487 // compositor. 501 // compositor.
488 return cc::SingleReleaseCallback::Create( 502 return cc::SingleReleaseCallback::Create(
489 base::Bind(&Buffer::Texture::Release, base::Unretained(texture), 503 base::Bind(&Buffer::Texture::Release, base::Unretained(texture),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } 555 }
542 556
543 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { 557 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) {
544 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); 558 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture");
545 559
546 contents_texture_ = std::move(texture); 560 contents_texture_ = std::move(texture);
547 Release(); 561 Release();
548 } 562 }
549 563
550 } // namespace exo 564 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698