OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 std::unique_ptr<ScopedGpuRaster> scoped_gpu_raster_; | 264 std::unique_ptr<ScopedGpuRaster> scoped_gpu_raster_; |
265 GLRenderer* renderer_; | 265 GLRenderer* renderer_; |
266 | 266 |
267 DISALLOW_COPY_AND_ASSIGN(ScopedUseGrContext); | 267 DISALLOW_COPY_AND_ASSIGN(ScopedUseGrContext); |
268 }; | 268 }; |
269 | 269 |
270 struct GLRenderer::PendingAsyncReadPixels { | 270 struct GLRenderer::PendingAsyncReadPixels { |
271 PendingAsyncReadPixels() : buffer(0) {} | 271 PendingAsyncReadPixels() : buffer(0) {} |
272 | 272 |
273 std::unique_ptr<CopyOutputRequest> copy_request; | 273 std::unique_ptr<CopyOutputRequest> copy_request; |
274 base::CancelableClosure finished_read_pixels_callback; | |
275 unsigned buffer; | 274 unsigned buffer; |
276 | 275 |
277 private: | 276 private: |
278 DISALLOW_COPY_AND_ASSIGN(PendingAsyncReadPixels); | 277 DISALLOW_COPY_AND_ASSIGN(PendingAsyncReadPixels); |
279 }; | 278 }; |
280 | 279 |
281 class GLRenderer::SyncQuery { | 280 class GLRenderer::SyncQuery { |
282 public: | 281 public: |
283 explicit SyncQuery(gpu::gles2::GLES2Interface* gl) | 282 explicit SyncQuery(gpu::gles2::GLES2Interface* gl) |
284 : gl_(gl), query_id_(0u), is_pending_(false), weak_ptr_factory_(this) { | 283 : gl_(gl), query_id_(0u), is_pending_(false), weak_ptr_factory_(this) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 texture_mailbox_deleter_(texture_mailbox_deleter), | 382 texture_mailbox_deleter_(texture_mailbox_deleter), |
384 is_scissor_enabled_(false), | 383 is_scissor_enabled_(false), |
385 stencil_shadow_(false), | 384 stencil_shadow_(false), |
386 blend_shadow_(false), | 385 blend_shadow_(false), |
387 highp_threshold_min_(highp_threshold_min), | 386 highp_threshold_min_(highp_threshold_min), |
388 highp_threshold_cache_(0), | 387 highp_threshold_cache_(0), |
389 use_sync_query_(false), | 388 use_sync_query_(false), |
390 gl_composited_texture_quad_border_( | 389 gl_composited_texture_quad_border_( |
391 settings->gl_composited_texture_quad_border), | 390 settings->gl_composited_texture_quad_border), |
392 bound_geometry_(NO_BINDING), | 391 bound_geometry_(NO_BINDING), |
393 color_lut_cache_(gl_) { | 392 color_lut_cache_(gl_), |
| 393 weak_ptr_factory_(this) { |
394 DCHECK(gl_); | 394 DCHECK(gl_); |
395 DCHECK(context_support_); | 395 DCHECK(context_support_); |
396 | 396 |
397 const auto& context_caps = | 397 const auto& context_caps = |
398 output_surface_->context_provider()->ContextCapabilities(); | 398 output_surface_->context_provider()->ContextCapabilities(); |
399 DCHECK(!context_caps.iosurface || context_caps.texture_rectangle); | 399 DCHECK(!context_caps.iosurface || context_caps.texture_rectangle); |
400 | 400 |
401 use_discard_framebuffer_ = context_caps.discard_framebuffer; | 401 use_discard_framebuffer_ = context_caps.discard_framebuffer; |
402 use_sync_query_ = context_caps.sync_query; | 402 use_sync_query_ = context_caps.sync_query; |
403 use_blend_equation_advanced_ = context_caps.blend_equation_advanced; | 403 use_blend_equation_advanced_ = context_caps.blend_equation_advanced; |
404 use_blend_equation_advanced_coherent_ = | 404 use_blend_equation_advanced_coherent_ = |
405 context_caps.blend_equation_advanced_coherent; | 405 context_caps.blend_equation_advanced_coherent; |
406 | 406 |
407 InitializeSharedObjects(); | 407 InitializeSharedObjects(); |
408 } | 408 } |
409 | 409 |
410 GLRenderer::~GLRenderer() { | 410 GLRenderer::~GLRenderer() { |
411 while (!pending_async_read_pixels_.empty()) { | |
412 PendingAsyncReadPixels* pending_read = | |
413 pending_async_read_pixels_.back().get(); | |
414 pending_read->finished_read_pixels_callback.Cancel(); | |
415 pending_async_read_pixels_.pop_back(); | |
416 } | |
417 | |
418 CleanupSharedObjects(); | 411 CleanupSharedObjects(); |
419 | 412 |
420 if (context_visibility_) { | 413 if (context_visibility_) { |
421 auto* context_provider = output_surface_->context_provider(); | 414 auto* context_provider = output_surface_->context_provider(); |
422 auto* cache_controller = context_provider->CacheController(); | 415 auto* cache_controller = context_provider->CacheController(); |
423 cache_controller->ClientBecameNotVisible(std::move(context_visibility_)); | 416 cache_controller->ClientBecameNotVisible(std::move(context_visibility_)); |
424 } | 417 } |
425 } | 418 } |
426 | 419 |
427 bool GLRenderer::CanPartialSwap() { | 420 bool GLRenderer::CanPartialSwap() { |
(...skipping 2649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3077 | 3070 |
3078 GLuint query = 0; | 3071 GLuint query = 0; |
3079 gl_->GenQueriesEXT(1, &query); | 3072 gl_->GenQueriesEXT(1, &query); |
3080 gl_->BeginQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, query); | 3073 gl_->BeginQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, query); |
3081 | 3074 |
3082 gl_->ReadPixels(window_rect.x(), window_rect.y(), window_rect.width(), | 3075 gl_->ReadPixels(window_rect.x(), window_rect.y(), window_rect.width(), |
3083 window_rect.height(), GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 3076 window_rect.height(), GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
3084 | 3077 |
3085 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); | 3078 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); |
3086 | 3079 |
3087 base::Closure finished_callback = base::Bind(&GLRenderer::FinishedReadback, | |
3088 base::Unretained(this), | |
3089 buffer, | |
3090 query, | |
3091 window_rect.size()); | |
3092 // Save the finished_callback so it can be cancelled. | |
3093 pending_async_read_pixels_.front()->finished_read_pixels_callback.Reset( | |
3094 finished_callback); | |
3095 base::Closure cancelable_callback = | |
3096 pending_async_read_pixels_.front()-> | |
3097 finished_read_pixels_callback.callback(); | |
3098 | |
3099 // Save the buffer to verify the callbacks happen in the expected order. | 3080 // Save the buffer to verify the callbacks happen in the expected order. |
3100 pending_async_read_pixels_.front()->buffer = buffer; | 3081 pending_async_read_pixels_.front()->buffer = buffer; |
3101 | 3082 |
3102 gl_->EndQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM); | 3083 gl_->EndQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM); |
3103 context_support_->SignalQuery(query, cancelable_callback); | 3084 context_support_->SignalQuery( |
| 3085 query, |
| 3086 base::Bind(&GLRenderer::FinishedReadback, weak_ptr_factory_.GetWeakPtr(), |
| 3087 buffer, query, window_rect.size())); |
3104 } | 3088 } |
3105 | 3089 |
3106 void GLRenderer::FinishedReadback(unsigned source_buffer, | 3090 void GLRenderer::FinishedReadback(unsigned source_buffer, |
3107 unsigned query, | 3091 unsigned query, |
3108 const gfx::Size& size) { | 3092 const gfx::Size& size) { |
3109 DCHECK(!pending_async_read_pixels_.empty()); | 3093 DCHECK(!pending_async_read_pixels_.empty()); |
3110 | 3094 |
3111 if (query != 0) { | 3095 if (query != 0) { |
3112 gl_->DeleteQueriesEXT(1, &query); | 3096 gl_->DeleteQueriesEXT(1, &query); |
3113 } | 3097 } |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4080 // The alpha has already been applied when copying the RPDQ to an IOSurface. | 4064 // The alpha has already been applied when copying the RPDQ to an IOSurface. |
4081 GLfloat alpha = 1; | 4065 GLfloat alpha = 1; |
4082 gl_->ScheduleCALayerSharedStateCHROMIUM(alpha, is_clipped, clip_rect, | 4066 gl_->ScheduleCALayerSharedStateCHROMIUM(alpha, is_clipped, clip_rect, |
4083 sorting_context_id, gl_transform); | 4067 sorting_context_id, gl_transform); |
4084 gl_->ScheduleCALayerCHROMIUM( | 4068 gl_->ScheduleCALayerCHROMIUM( |
4085 texture_id, contents_rect, ca_layer_overlay->background_color, | 4069 texture_id, contents_rect, ca_layer_overlay->background_color, |
4086 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); | 4070 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); |
4087 } | 4071 } |
4088 | 4072 |
4089 } // namespace cc | 4073 } // namespace cc |
OLD | NEW |