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 "cc/output/overlay_strategy_common.h" | 5 #include "cc/output/overlay_strategy_common.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "cc/quads/io_surface_draw_quad.h" | 9 #include "cc/quads/io_surface_draw_quad.h" |
10 #include "cc/quads/solid_color_draw_quad.h" | 10 #include "cc/quads/solid_color_draw_quad.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 | 27 |
28 bool OverlayStrategyCommon::Attempt(RenderPassList* render_passes_in_draw_order, | 28 bool OverlayStrategyCommon::Attempt(RenderPassList* render_passes_in_draw_order, |
29 OverlayCandidateList* candidate_list, | 29 OverlayCandidateList* candidate_list, |
30 float device_scale_factor) { | 30 float device_scale_factor) { |
31 if (!capability_checker_) | 31 if (!capability_checker_) |
32 return false; | 32 return false; |
33 RenderPass* root_render_pass = render_passes_in_draw_order->back(); | 33 RenderPass* root_render_pass = render_passes_in_draw_order->back(); |
34 DCHECK(root_render_pass); | 34 DCHECK(root_render_pass); |
35 | 35 |
| 36 // Add our primary surface. |
| 37 OverlayCandidate main_image; |
| 38 main_image.display_rect = gfx::RectF(root_render_pass->output_rect); |
| 39 DCHECK(candidate_list->empty()); |
| 40 candidate_list->push_back(main_image); |
| 41 |
| 42 bool created_overlay = false; |
36 QuadList& quad_list = root_render_pass->quad_list; | 43 QuadList& quad_list = root_render_pass->quad_list; |
37 for (auto it = quad_list.begin(); it != quad_list.end(); ++it) { | 44 for (auto it = quad_list.begin(); it != quad_list.end();) { |
38 OverlayCandidate candidate; | 45 OverlayCandidate candidate; |
39 const DrawQuad* draw_quad = *it; | 46 if (!GetCandidateQuadInfo(**it, &candidate)) { |
40 if (IsOverlayQuad(draw_quad) && | 47 ++it; |
41 GetCandidateQuadInfo(*draw_quad, &candidate) && | 48 continue; |
42 delegate_->TryOverlay(capability_checker_, render_passes_in_draw_order, | 49 } |
43 candidate_list, candidate, it, | 50 |
44 device_scale_factor)) | 51 OverlayResult result = delegate_->TryOverlay( |
45 return true; | 52 capability_checker_, render_passes_in_draw_order, candidate_list, |
| 53 candidate, &it, device_scale_factor); |
| 54 switch (result) { |
| 55 case DID_NOT_CREATE_OVERLAY: |
| 56 ++it; |
| 57 break; |
| 58 case CREATED_OVERLAY_STOP_LOOKING: |
| 59 return true; |
| 60 case CREATED_OVERLAY_KEEP_LOOKING: |
| 61 created_overlay = true; |
| 62 break; |
| 63 } |
46 } | 64 } |
47 return false; | |
48 } | |
49 | 65 |
50 bool OverlayStrategyCommon::IsOverlayQuad(const DrawQuad* draw_quad) { | 66 if (!created_overlay) { |
51 switch (draw_quad->material) { | 67 DCHECK_EQ(1u, candidate_list->size()); |
52 case DrawQuad::TEXTURE_CONTENT: | 68 candidate_list->clear(); |
53 return TextureDrawQuad::MaterialCast(draw_quad)->allow_overlay(); | |
54 case DrawQuad::STREAM_VIDEO_CONTENT: | |
55 return StreamVideoDrawQuad::MaterialCast(draw_quad)->allow_overlay(); | |
56 case DrawQuad::IO_SURFACE_CONTENT: | |
57 return IOSurfaceDrawQuad::MaterialCast(draw_quad)->allow_overlay; | |
58 default: | |
59 return false; | |
60 } | 69 } |
| 70 |
| 71 return created_overlay; |
61 } | 72 } |
62 | 73 |
63 // static | 74 // static |
64 bool OverlayStrategyCommon::IsInvisibleQuad(const DrawQuad* draw_quad) { | 75 bool OverlayStrategyCommon::IsInvisibleQuad(const DrawQuad* draw_quad) { |
65 if (draw_quad->material == DrawQuad::SOLID_COLOR) { | 76 if (draw_quad->material == DrawQuad::SOLID_COLOR) { |
66 const SolidColorDrawQuad* solid_quad = | 77 const SolidColorDrawQuad* solid_quad = |
67 SolidColorDrawQuad::MaterialCast(draw_quad); | 78 SolidColorDrawQuad::MaterialCast(draw_quad); |
68 SkColor color = solid_quad->color; | 79 SkColor color = solid_quad->color; |
69 float opacity = solid_quad->shared_quad_state->opacity; | 80 float opacity = solid_quad->shared_quad_state->opacity; |
70 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; | 81 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; |
71 return solid_quad->ShouldDrawWithBlending() && | 82 return solid_quad->ShouldDrawWithBlending() && |
72 alpha < std::numeric_limits<float>::epsilon(); | 83 alpha < std::numeric_limits<float>::epsilon(); |
73 } | 84 } |
74 return false; | 85 return false; |
75 } | 86 } |
76 | 87 |
77 bool OverlayStrategyCommon::GetTextureQuadInfo(const TextureDrawQuad& quad, | 88 bool OverlayStrategyCommon::GetTextureQuadInfo(const TextureDrawQuad& quad, |
78 OverlayCandidate* quad_info) { | 89 OverlayCandidate* quad_info) { |
| 90 if (!quad.allow_overlay()) |
| 91 return false; |
79 gfx::OverlayTransform overlay_transform = | 92 gfx::OverlayTransform overlay_transform = |
80 OverlayCandidate::GetOverlayTransform( | 93 OverlayCandidate::GetOverlayTransform( |
81 quad.shared_quad_state->quad_to_target_transform, quad.y_flipped); | 94 quad.shared_quad_state->quad_to_target_transform, quad.y_flipped); |
82 if (quad.background_color != SK_ColorTRANSPARENT || | 95 if (quad.background_color != SK_ColorTRANSPARENT || |
83 quad.premultiplied_alpha || | 96 quad.premultiplied_alpha || |
84 overlay_transform == gfx::OVERLAY_TRANSFORM_INVALID) | 97 overlay_transform == gfx::OVERLAY_TRANSFORM_INVALID) |
85 return false; | 98 return false; |
86 quad_info->resource_id = quad.resource_id(); | 99 quad_info->resource_id = quad.resource_id(); |
87 quad_info->resource_size_in_pixels = quad.resource_size_in_pixels(); | 100 quad_info->resource_size_in_pixels = quad.resource_size_in_pixels(); |
88 quad_info->transform = overlay_transform; | 101 quad_info->transform = overlay_transform; |
89 quad_info->uv_rect = BoundingRect(quad.uv_top_left, quad.uv_bottom_right); | 102 quad_info->uv_rect = BoundingRect(quad.uv_top_left, quad.uv_bottom_right); |
90 return true; | 103 return true; |
91 } | 104 } |
92 | 105 |
93 bool OverlayStrategyCommon::GetVideoQuadInfo(const StreamVideoDrawQuad& quad, | 106 bool OverlayStrategyCommon::GetVideoQuadInfo(const StreamVideoDrawQuad& quad, |
94 OverlayCandidate* quad_info) { | 107 OverlayCandidate* quad_info) { |
| 108 if (!quad.allow_overlay()) |
| 109 return false; |
95 gfx::OverlayTransform overlay_transform = | 110 gfx::OverlayTransform overlay_transform = |
96 OverlayCandidate::GetOverlayTransform( | 111 OverlayCandidate::GetOverlayTransform( |
97 quad.shared_quad_state->quad_to_target_transform, false); | 112 quad.shared_quad_state->quad_to_target_transform, false); |
98 if (overlay_transform == gfx::OVERLAY_TRANSFORM_INVALID) | 113 if (overlay_transform == gfx::OVERLAY_TRANSFORM_INVALID) |
99 return false; | 114 return false; |
100 if (!quad.matrix.IsScaleOrTranslation()) { | 115 if (!quad.matrix.IsScaleOrTranslation()) { |
101 // We cannot handle anything other than scaling & translation for texture | 116 // We cannot handle anything other than scaling & translation for texture |
102 // coordinates yet. | 117 // coordinates yet. |
103 return false; | 118 return false; |
104 } | 119 } |
(...skipping 23 matching lines...) Expand all Loading... |
128 } else { | 143 } else { |
129 quad_info->transform = OverlayCandidate::ModifyTransform( | 144 quad_info->transform = OverlayCandidate::ModifyTransform( |
130 quad_info->transform, gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL); | 145 quad_info->transform, gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL); |
131 quad_info->uv_rect = gfx::RectF(uv0.x(), uv0.y(), delta.x(), delta.y()); | 146 quad_info->uv_rect = gfx::RectF(uv0.x(), uv0.y(), delta.x(), delta.y()); |
132 } | 147 } |
133 return true; | 148 return true; |
134 } | 149 } |
135 | 150 |
136 bool OverlayStrategyCommon::GetIOSurfaceQuadInfo(const IOSurfaceDrawQuad& quad, | 151 bool OverlayStrategyCommon::GetIOSurfaceQuadInfo(const IOSurfaceDrawQuad& quad, |
137 OverlayCandidate* quad_info) { | 152 OverlayCandidate* quad_info) { |
| 153 if (!quad.allow_overlay) |
| 154 return false; |
138 gfx::OverlayTransform overlay_transform = | 155 gfx::OverlayTransform overlay_transform = |
139 OverlayCandidate::GetOverlayTransform( | 156 OverlayCandidate::GetOverlayTransform( |
140 quad.shared_quad_state->quad_to_target_transform, false); | 157 quad.shared_quad_state->quad_to_target_transform, false); |
141 if (overlay_transform != gfx::OVERLAY_TRANSFORM_NONE) | 158 if (overlay_transform != gfx::OVERLAY_TRANSFORM_NONE) |
142 return false; | 159 return false; |
143 quad_info->resource_id = quad.io_surface_resource_id(); | 160 quad_info->resource_id = quad.io_surface_resource_id(); |
144 quad_info->resource_size_in_pixels = quad.io_surface_size; | 161 quad_info->resource_size_in_pixels = quad.io_surface_size; |
145 quad_info->transform = overlay_transform; | 162 quad_info->transform = overlay_transform; |
146 quad_info->uv_rect = gfx::RectF(1.f, 1.f); | 163 quad_info->uv_rect = gfx::RectF(1.f, 1.f); |
147 return true; | 164 return true; |
(...skipping 26 matching lines...) Expand all Loading... |
174 return false; | 191 return false; |
175 } | 192 } |
176 | 193 |
177 quad_info->format = RGBA_8888; | 194 quad_info->format = RGBA_8888; |
178 quad_info->display_rect = OverlayCandidate::GetOverlayRect( | 195 quad_info->display_rect = OverlayCandidate::GetOverlayRect( |
179 draw_quad.shared_quad_state->quad_to_target_transform, draw_quad.rect); | 196 draw_quad.shared_quad_state->quad_to_target_transform, draw_quad.rect); |
180 return true; | 197 return true; |
181 } | 198 } |
182 | 199 |
183 } // namespace cc | 200 } // namespace cc |
OLD | NEW |