Chromium Code Reviews| 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 (render_passes_in_draw_order->size() != 1 || !capability_checker_) | |
|
piman
2014/03/18 23:46:08
nit: actually, do we even care about the render pa
| |
| 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 ResourceProvider::ResourceId resource_id = | |
| 36 TextureDrawQuad::MaterialCast(candidate_quad)->resource_id; | |
| 37 if (!resource_provider_->AllowOverlay(resource_id)) | |
| 38 return false; | |
| 39 | |
| 40 // Add our primary surface. | |
| 41 OverlayCandidateValidator::OverlayCandidateList candidates; | |
| 42 OverlayCandidate main_image; | |
| 43 main_image.display_rect = root_render_pass->output_rect; | |
| 44 main_image.format = RGBA_8888; | |
| 45 candidates.push_back(main_image); | |
| 46 | |
| 47 // Add the overlay. | |
| 48 OverlayCandidate candidate; | |
| 49 const TextureDrawQuad& quad = *TextureDrawQuad::MaterialCast(candidate_quad); | |
|
piman
2014/03/18 23:46:08
nit: we could do this only once above, before we g
| |
| 50 if (!quad.quadTransform().IsIdentityOrTranslation()) | |
|
piman
2014/03/18 23:46:08
Should we also reject if quad.shared_quad_state->o
| |
| 51 return false; | |
| 52 gfx::RectF float_rect(quad.rect); | |
| 53 quad.quadTransform().TransformRect(&float_rect); | |
| 54 candidate.display_rect = gfx::ToNearestRect(float_rect); | |
| 55 candidate.uv_rect = BoundingRect(quad.uv_top_left, quad.uv_bottom_right); | |
| 56 candidate.format = RGBA_8888; | |
| 57 candidates.push_back(candidate); | |
| 58 | |
| 59 // Check for support. | |
| 60 capability_checker_->CheckOverlaySupport(&candidates); | |
| 61 | |
| 62 // If the candidate can be handled by an overlay, create a pass for it. | |
| 63 if (candidates[1].overlay_handled) { | |
| 64 scoped_ptr<RenderPass> overlay_pass = RenderPass::Create(); | |
| 65 overlay_pass->overlay_state = RenderPass::SIMPLE_OVERLAY; | |
| 66 | |
| 67 scoped_ptr<DrawQuad> overlay_quad = quad_list.take(quad_list.begin()); | |
| 68 quad_list.erase(quad_list.begin()); | |
| 69 overlay_pass->quad_list.push_back(overlay_quad.Pass()); | |
| 70 render_passes_in_draw_order->insert(render_passes_in_draw_order->begin(), | |
| 71 overlay_pass.Pass()); | |
| 72 } | |
| 73 return candidates[1].overlay_handled; | |
| 74 } | |
| 75 | |
| 76 } // namespace cc | |
| OLD | NEW |