OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/output/overlay_strategy_single_on_top.h" |
| 6 |
| 7 #include "cc/output/output_surface.h" |
| 8 #include "cc/quads/draw_quad.h" |
| 9 #include "cc/quads/texture_draw_quad.h" |
| 10 #include "ui/gfx/rect_conversions.h" |
| 11 #include "ui/gfx/transform.h" |
| 12 |
| 13 namespace cc { |
| 14 |
| 15 OverlayStrategySingleOnTop::OverlayStrategySingleOnTop( |
| 16 OverlayCandidateValidator* capability_checker, |
| 17 ResourceProvider* resource_provider) |
| 18 : capability_checker_(capability_checker), |
| 19 resource_provider_(resource_provider) {} |
| 20 |
| 21 bool OverlayStrategySingleOnTop::Attempt( |
| 22 RenderPassList* render_passes_in_draw_order) { |
| 23 // Only attempt to handle very simple case for now. |
| 24 if (!capability_checker_) |
| 25 return false; |
| 26 |
| 27 RenderPass* root_render_pass = render_passes_in_draw_order->back(); |
| 28 DCHECK(root_render_pass); |
| 29 |
| 30 QuadList& quad_list = root_render_pass->quad_list; |
| 31 const DrawQuad* candidate_quad = quad_list.front(); |
| 32 if (candidate_quad->material != DrawQuad::TEXTURE_CONTENT) |
| 33 return false; |
| 34 |
| 35 const TextureDrawQuad& quad = *TextureDrawQuad::MaterialCast(candidate_quad); |
| 36 if (!resource_provider_->AllowOverlay(quad.resource_id)) |
| 37 return false; |
| 38 |
| 39 // Simple quads only. |
| 40 if (!quad.quadTransform().IsIdentityOrTranslation() || quad.needs_blending || |
| 41 quad.shared_quad_state->opacity != 1.f || |
| 42 quad.shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode || |
| 43 quad.premultiplied_alpha || quad.background_color != SK_ColorTRANSPARENT) |
| 44 return false; |
| 45 |
| 46 // Add our primary surface. |
| 47 OverlayCandidateValidator::OverlayCandidateList candidates; |
| 48 OverlayCandidate main_image; |
| 49 main_image.display_rect = root_render_pass->output_rect; |
| 50 main_image.format = RGBA_8888; |
| 51 candidates.push_back(main_image); |
| 52 |
| 53 // Add the overlay. |
| 54 OverlayCandidate candidate; |
| 55 gfx::RectF float_rect(quad.rect); |
| 56 quad.quadTransform().TransformRect(&float_rect); |
| 57 candidate.transform = |
| 58 quad.flipped ? OverlayCandidate::FLIP_VERTICAL : OverlayCandidate::NONE; |
| 59 candidate.display_rect = gfx::ToNearestRect(float_rect); |
| 60 candidate.uv_rect = BoundingRect(quad.uv_top_left, quad.uv_bottom_right); |
| 61 candidate.format = RGBA_8888; |
| 62 candidates.push_back(candidate); |
| 63 |
| 64 // Check for support. |
| 65 capability_checker_->CheckOverlaySupport(&candidates); |
| 66 |
| 67 // If the candidate can be handled by an overlay, create a pass for it. |
| 68 if (candidates[1].overlay_handled) { |
| 69 scoped_ptr<RenderPass> overlay_pass = RenderPass::Create(); |
| 70 overlay_pass->overlay_state = RenderPass::SIMPLE_OVERLAY; |
| 71 |
| 72 scoped_ptr<DrawQuad> overlay_quad = quad_list.take(quad_list.begin()); |
| 73 quad_list.erase(quad_list.begin()); |
| 74 overlay_pass->quad_list.push_back(overlay_quad.Pass()); |
| 75 render_passes_in_draw_order->insert(render_passes_in_draw_order->begin(), |
| 76 overlay_pass.Pass()); |
| 77 } |
| 78 return candidates[1].overlay_handled; |
| 79 } |
| 80 |
| 81 } // namespace cc |
OLD | NEW |