Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_candidate.h" | 5 #include "cc/output/overlay_candidate.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
| 11 #include "cc/quads/io_surface_draw_quad.h" | |
| 12 #include "cc/quads/solid_color_draw_quad.h" | |
| 13 #include "cc/quads/stream_video_draw_quad.h" | |
| 14 #include "cc/quads/texture_draw_quad.h" | |
| 11 #include "ui/gfx/geometry/rect_conversions.h" | 15 #include "ui/gfx/geometry/rect_conversions.h" |
| 12 #include "ui/gfx/geometry/vector3d_f.h" | 16 #include "ui/gfx/geometry/vector3d_f.h" |
| 13 | 17 |
| 14 namespace cc { | 18 namespace cc { |
| 15 | 19 |
| 16 namespace { | 20 namespace { |
| 17 // Tolerance for considering axis vector elements to be zero. | 21 // Tolerance for considering axis vector elements to be zero. |
| 18 const SkMScalar kEpsilon = std::numeric_limits<float>::epsilon(); | 22 const SkMScalar kEpsilon = std::numeric_limits<float>::epsilon(); |
| 19 | 23 |
| 20 enum Axis { NONE, AXIS_POS_X, AXIS_NEG_X, AXIS_POS_Y, AXIS_NEG_Y }; | 24 enum Axis { NONE, AXIS_POS_X, AXIS_NEG_X, AXIS_POS_Y, AXIS_NEG_Y }; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 40 uv_rect(0.f, 0.f, 1.f, 1.f), | 44 uv_rect(0.f, 0.f, 1.f, 1.f), |
| 41 is_clipped(false), | 45 is_clipped(false), |
| 42 use_output_surface_for_resource(false), | 46 use_output_surface_for_resource(false), |
| 43 resource_id(0), | 47 resource_id(0), |
| 44 plane_z_order(0), | 48 plane_z_order(0), |
| 45 overlay_handled(false) {} | 49 overlay_handled(false) {} |
| 46 | 50 |
| 47 OverlayCandidate::~OverlayCandidate() {} | 51 OverlayCandidate::~OverlayCandidate() {} |
| 48 | 52 |
| 49 // static | 53 // static |
| 54 bool OverlayCandidate::FromDrawQuad(const DrawQuad* quad, | |
| 55 OverlayCandidate* candidate) { | |
| 56 if (quad->needs_blending || quad->shared_quad_state->opacity != 1.f || | |
| 57 quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode) | |
| 58 return false; | |
| 59 | |
| 60 candidate->format = RGBA_8888; | |
| 61 candidate->display_rect = GetOverlayRect( | |
|
ccameron
2015/09/29 23:29:55
Remove GetOverlayRect as a function and make it in
Andre
2015/09/30 00:18:38
Done.
| |
| 62 quad->shared_quad_state->quad_to_target_transform, quad->rect); | |
| 63 candidate->quad_rect_in_target_space = MathUtil::MapEnclosingClippedRect( | |
| 64 quad->shared_quad_state->quad_to_target_transform, quad->rect); | |
| 65 candidate->clip_rect = quad->shared_quad_state->clip_rect; | |
| 66 candidate->is_clipped = quad->shared_quad_state->is_clipped; | |
| 67 | |
| 68 switch (quad->material) { | |
| 69 case DrawQuad::TEXTURE_CONTENT: | |
| 70 return FromTextureQuad(TextureDrawQuad::MaterialCast(quad), candidate); | |
| 71 case DrawQuad::STREAM_VIDEO_CONTENT: | |
| 72 return FromStreamVideoQuad(StreamVideoDrawQuad::MaterialCast(quad), | |
| 73 candidate); | |
| 74 case DrawQuad::IO_SURFACE_CONTENT: | |
| 75 return FromIOSurfaceQuad(IOSurfaceDrawQuad::MaterialCast(quad), | |
| 76 candidate); | |
| 77 default: | |
| 78 break; | |
| 79 } | |
| 80 | |
| 81 return false; | |
| 82 } | |
| 83 | |
| 84 // static | |
| 85 bool OverlayCandidate::FromTextureQuad(const TextureDrawQuad* quad, | |
| 86 OverlayCandidate* candidate) { | |
| 87 if (!quad->allow_overlay()) | |
| 88 return false; | |
| 89 gfx::OverlayTransform overlay_transform = GetOverlayTransform( | |
| 90 quad->shared_quad_state->quad_to_target_transform, quad->y_flipped); | |
| 91 if (quad->background_color != SK_ColorTRANSPARENT || | |
| 92 quad->premultiplied_alpha || | |
| 93 overlay_transform == gfx::OVERLAY_TRANSFORM_INVALID) | |
| 94 return false; | |
| 95 candidate->resource_id = quad->resource_id(); | |
| 96 candidate->resource_size_in_pixels = quad->resource_size_in_pixels(); | |
| 97 candidate->transform = overlay_transform; | |
| 98 candidate->uv_rect = BoundingRect(quad->uv_top_left, quad->uv_bottom_right); | |
| 99 return true; | |
| 100 } | |
| 101 | |
| 102 // static | |
| 103 bool OverlayCandidate::FromStreamVideoQuad(const StreamVideoDrawQuad* quad, | |
| 104 OverlayCandidate* candidate) { | |
| 105 if (!quad->allow_overlay()) | |
| 106 return false; | |
| 107 gfx::OverlayTransform overlay_transform = GetOverlayTransform( | |
| 108 quad->shared_quad_state->quad_to_target_transform, false); | |
| 109 if (overlay_transform == gfx::OVERLAY_TRANSFORM_INVALID) | |
| 110 return false; | |
| 111 if (!quad->matrix.IsScaleOrTranslation()) { | |
| 112 // We cannot handle anything other than scaling & translation for texture | |
| 113 // coordinates yet. | |
| 114 return false; | |
| 115 } | |
| 116 candidate->resource_id = quad->resource_id(); | |
| 117 candidate->resource_size_in_pixels = quad->resource_size_in_pixels(); | |
| 118 candidate->transform = overlay_transform; | |
| 119 | |
| 120 gfx::Point3F uv0 = gfx::Point3F(0, 0, 0); | |
| 121 gfx::Point3F uv1 = gfx::Point3F(1, 1, 0); | |
| 122 quad->matrix.TransformPoint(&uv0); | |
| 123 quad->matrix.TransformPoint(&uv1); | |
| 124 gfx::Vector3dF delta = uv1 - uv0; | |
| 125 if (delta.x() < 0) { | |
| 126 candidate->transform = ModifyTransform( | |
| 127 candidate->transform, gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL); | |
| 128 float x0 = uv0.x(); | |
| 129 uv0.set_x(uv1.x()); | |
| 130 uv1.set_x(x0); | |
| 131 delta.set_x(-delta.x()); | |
| 132 } | |
| 133 | |
| 134 if (delta.y() < 0) { | |
| 135 // In this situation, uv0y < uv1y. Since we overlay inverted, a request | |
| 136 // to invert the source texture means we can just output the texture | |
| 137 // normally and it will be correct. | |
| 138 candidate->uv_rect = gfx::RectF(uv0.x(), uv1.y(), delta.x(), -delta.y()); | |
| 139 } else { | |
| 140 candidate->transform = ModifyTransform( | |
| 141 candidate->transform, gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL); | |
| 142 candidate->uv_rect = gfx::RectF(uv0.x(), uv0.y(), delta.x(), delta.y()); | |
| 143 } | |
| 144 return true; | |
| 145 } | |
| 146 | |
| 147 // static | |
| 148 bool OverlayCandidate::FromIOSurfaceQuad(const IOSurfaceDrawQuad* quad, | |
| 149 OverlayCandidate* candidate) { | |
| 150 if (!quad->allow_overlay) | |
| 151 return false; | |
| 152 gfx::OverlayTransform overlay_transform = GetOverlayTransform( | |
| 153 quad->shared_quad_state->quad_to_target_transform, false); | |
| 154 if (overlay_transform != gfx::OVERLAY_TRANSFORM_NONE) | |
| 155 return false; | |
| 156 candidate->resource_id = quad->io_surface_resource_id(); | |
| 157 candidate->resource_size_in_pixels = quad->io_surface_size; | |
| 158 candidate->transform = overlay_transform; | |
| 159 candidate->uv_rect = gfx::RectF(1.f, 1.f); | |
| 160 return true; | |
| 161 } | |
| 162 | |
| 163 // static | |
| 50 gfx::OverlayTransform OverlayCandidate::GetOverlayTransform( | 164 gfx::OverlayTransform OverlayCandidate::GetOverlayTransform( |
| 51 const gfx::Transform& quad_transform, | 165 const gfx::Transform& quad_transform, |
| 52 bool y_flipped) { | 166 bool y_flipped) { |
| 53 if (!quad_transform.Preserves2dAxisAlignment()) { | 167 if (!quad_transform.Preserves2dAxisAlignment()) { |
| 54 return gfx::OVERLAY_TRANSFORM_INVALID; | 168 return gfx::OVERLAY_TRANSFORM_INVALID; |
| 55 } | 169 } |
| 56 | 170 |
| 57 gfx::Vector3dF x_axis = MathUtil::GetXAxis(quad_transform); | 171 gfx::Vector3dF x_axis = MathUtil::GetXAxis(quad_transform); |
| 58 gfx::Vector3dF y_axis = MathUtil::GetYAxis(quad_transform); | 172 gfx::Vector3dF y_axis = MathUtil::GetYAxis(quad_transform); |
| 59 if (y_flipped) { | 173 if (y_flipped) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 const gfx::Transform& quad_transform, | 294 const gfx::Transform& quad_transform, |
| 181 const gfx::Rect& rect) { | 295 const gfx::Rect& rect) { |
| 182 DCHECK(quad_transform.Preserves2dAxisAlignment()); | 296 DCHECK(quad_transform.Preserves2dAxisAlignment()); |
| 183 | 297 |
| 184 gfx::RectF float_rect(rect); | 298 gfx::RectF float_rect(rect); |
| 185 quad_transform.TransformRect(&float_rect); | 299 quad_transform.TransformRect(&float_rect); |
| 186 return float_rect; | 300 return float_rect; |
| 187 } | 301 } |
| 188 | 302 |
| 189 } // namespace cc | 303 } // namespace cc |
| OLD | NEW |