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/solid_color_draw_quad.h" | 9 #include "cc/quads/solid_color_draw_quad.h" |
10 #include "cc/quads/stream_video_draw_quad.h" | 10 #include "cc/quads/stream_video_draw_quad.h" |
11 #include "cc/quads/texture_draw_quad.h" | 11 #include "cc/quads/texture_draw_quad.h" |
12 #include "cc/resources/resource_provider.h" | 12 #include "cc/resources/resource_provider.h" |
13 #include "ui/gfx/geometry/point3_f.h" | 13 #include "ui/gfx/geometry/point3_f.h" |
14 #include "ui/gfx/geometry/rect_conversions.h" | 14 #include "ui/gfx/geometry/rect_conversions.h" |
15 #include "ui/gfx/transform.h" | 15 #include "ui/gfx/transform.h" |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 | 18 |
19 OverlayStrategyCommon::OverlayStrategyCommon( | 19 OverlayStrategyCommon::OverlayStrategyCommon() { |
20 OverlayCandidateValidator* capability_checker, | |
21 ResourceProvider* resource_provider) | |
22 : capability_checker_(capability_checker), | |
23 resource_provider_(resource_provider) { | |
24 } | 20 } |
25 | 21 |
26 OverlayStrategyCommon::~OverlayStrategyCommon() { | 22 OverlayStrategyCommon::~OverlayStrategyCommon() { |
27 } | 23 } |
28 | 24 |
29 bool OverlayStrategyCommon::IsOverlayQuad(const DrawQuad* draw_quad) { | 25 bool OverlayStrategyCommon::IsOverlayQuad(const DrawQuad* draw_quad) { |
30 unsigned int resource_id; | |
31 switch (draw_quad->material) { | 26 switch (draw_quad->material) { |
32 case DrawQuad::TEXTURE_CONTENT: | 27 case DrawQuad::TEXTURE_CONTENT: |
33 resource_id = TextureDrawQuad::MaterialCast(draw_quad)->resource_id(); | 28 return TextureDrawQuad::MaterialCast(draw_quad)->allow_overlay(); |
34 break; | |
35 case DrawQuad::STREAM_VIDEO_CONTENT: | 29 case DrawQuad::STREAM_VIDEO_CONTENT: |
36 resource_id = StreamVideoDrawQuad::MaterialCast(draw_quad)->resource_id(); | 30 return StreamVideoDrawQuad::MaterialCast(draw_quad)->allow_overlay(); |
37 break; | |
38 default: | 31 default: |
39 return false; | 32 return false; |
40 } | 33 } |
41 return resource_provider_->AllowOverlay(resource_id); | |
42 } | 34 } |
43 | 35 |
44 bool OverlayStrategyCommon::IsInvisibleQuad(const DrawQuad* draw_quad) { | 36 bool OverlayStrategyCommon::IsInvisibleQuad(const DrawQuad* draw_quad) { |
45 if (draw_quad->material == DrawQuad::SOLID_COLOR) { | 37 if (draw_quad->material == DrawQuad::SOLID_COLOR) { |
46 const SolidColorDrawQuad* solid_quad = | 38 const SolidColorDrawQuad* solid_quad = |
47 SolidColorDrawQuad::MaterialCast(draw_quad); | 39 SolidColorDrawQuad::MaterialCast(draw_quad); |
48 SkColor color = solid_quad->color; | 40 SkColor color = solid_quad->color; |
49 float opacity = solid_quad->shared_quad_state->opacity; | 41 float opacity = solid_quad->shared_quad_state->opacity; |
50 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; | 42 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; |
51 return solid_quad->ShouldDrawWithBlending() && | 43 return solid_quad->ShouldDrawWithBlending() && |
52 alpha < std::numeric_limits<float>::epsilon(); | 44 alpha < std::numeric_limits<float>::epsilon(); |
53 } | 45 } |
54 return false; | 46 return false; |
55 } | 47 } |
56 | 48 |
57 bool OverlayStrategyCommon::GetTextureQuadInfo(const TextureDrawQuad& quad, | 49 bool OverlayStrategyCommon::GetTextureQuadInfo(const TextureDrawQuad& quad, |
58 OverlayCandidate* quad_info) { | 50 OverlayCandidate* quad_info) { |
59 gfx::OverlayTransform overlay_transform = | 51 gfx::OverlayTransform overlay_transform = |
60 OverlayCandidate::GetOverlayTransform( | 52 OverlayCandidate::GetOverlayTransform( |
61 quad.shared_quad_state->content_to_target_transform, quad.y_flipped); | 53 quad.shared_quad_state->content_to_target_transform, quad.y_flipped); |
62 if (quad.background_color != SK_ColorTRANSPARENT || | 54 if (quad.background_color != SK_ColorTRANSPARENT || |
63 quad.premultiplied_alpha || | 55 quad.premultiplied_alpha || |
64 overlay_transform == gfx::OVERLAY_TRANSFORM_INVALID) | 56 overlay_transform == gfx::OVERLAY_TRANSFORM_INVALID) |
65 return false; | 57 return false; |
66 quad_info->resource_id = quad.resource_id(); | 58 quad_info->resource_id = quad.resource_id(); |
| 59 quad_info->resource_size_in_pixels = quad.resource_size_in_pixels(); |
67 quad_info->transform = overlay_transform; | 60 quad_info->transform = overlay_transform; |
68 quad_info->uv_rect = BoundingRect(quad.uv_top_left, quad.uv_bottom_right); | 61 quad_info->uv_rect = BoundingRect(quad.uv_top_left, quad.uv_bottom_right); |
69 return true; | 62 return true; |
70 } | 63 } |
71 | 64 |
72 bool OverlayStrategyCommon::GetVideoQuadInfo(const StreamVideoDrawQuad& quad, | 65 bool OverlayStrategyCommon::GetVideoQuadInfo(const StreamVideoDrawQuad& quad, |
73 OverlayCandidate* quad_info) { | 66 OverlayCandidate* quad_info) { |
74 gfx::OverlayTransform overlay_transform = | 67 gfx::OverlayTransform overlay_transform = |
75 OverlayCandidate::GetOverlayTransform( | 68 OverlayCandidate::GetOverlayTransform( |
76 quad.shared_quad_state->content_to_target_transform, false); | 69 quad.shared_quad_state->content_to_target_transform, false); |
77 if (overlay_transform == gfx::OVERLAY_TRANSFORM_INVALID) | 70 if (overlay_transform == gfx::OVERLAY_TRANSFORM_INVALID) |
78 return false; | 71 return false; |
79 if (!quad.matrix.IsScaleOrTranslation()) { | 72 if (!quad.matrix.IsScaleOrTranslation()) { |
80 // We cannot handle anything other than scaling & translation for texture | 73 // We cannot handle anything other than scaling & translation for texture |
81 // coordinates yet. | 74 // coordinates yet. |
82 return false; | 75 return false; |
83 } | 76 } |
84 quad_info->resource_id = quad.resource_id(); | 77 quad_info->resource_id = quad.resource_id(); |
| 78 quad_info->resource_size_in_pixels = quad.resource_size_in_pixels(); |
85 quad_info->transform = overlay_transform; | 79 quad_info->transform = overlay_transform; |
86 | 80 |
87 gfx::Point3F uv0 = gfx::Point3F(0, 0, 0); | 81 gfx::Point3F uv0 = gfx::Point3F(0, 0, 0); |
88 gfx::Point3F uv1 = gfx::Point3F(1, 1, 0); | 82 gfx::Point3F uv1 = gfx::Point3F(1, 1, 0); |
89 quad.matrix.TransformPoint(&uv0); | 83 quad.matrix.TransformPoint(&uv0); |
90 quad.matrix.TransformPoint(&uv1); | 84 quad.matrix.TransformPoint(&uv1); |
91 gfx::Vector3dF delta = uv1 - uv0; | 85 gfx::Vector3dF delta = uv1 - uv0; |
92 if (delta.x() < 0) { | 86 if (delta.x() < 0) { |
93 quad_info->transform = OverlayCandidate::ModifyTransform( | 87 quad_info->transform = OverlayCandidate::ModifyTransform( |
94 quad_info->transform, gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL); | 88 quad_info->transform, gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 return false; | 123 return false; |
130 } | 124 } |
131 | 125 |
132 quad_info->format = RGBA_8888; | 126 quad_info->format = RGBA_8888; |
133 quad_info->display_rect = OverlayCandidate::GetOverlayRect( | 127 quad_info->display_rect = OverlayCandidate::GetOverlayRect( |
134 draw_quad.shared_quad_state->content_to_target_transform, draw_quad.rect); | 128 draw_quad.shared_quad_state->content_to_target_transform, draw_quad.rect); |
135 return true; | 129 return true; |
136 } | 130 } |
137 | 131 |
138 } // namespace cc | 132 } // namespace cc |
OLD | NEW |