| 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/solid_color_draw_quad.h" | 11 #include "cc/quads/solid_color_draw_quad.h" |
| 12 #include "cc/quads/stream_video_draw_quad.h" | 12 #include "cc/quads/stream_video_draw_quad.h" |
| 13 #include "cc/quads/texture_draw_quad.h" | 13 #include "cc/quads/texture_draw_quad.h" |
| 14 #include "cc/quads/tile_draw_quad.h" | 14 #include "cc/quads/tile_draw_quad.h" |
| 15 #include "cc/resources/resource_provider.h" | 15 #include "cc/resources/resource_provider.h" |
| 16 #include "ui/gfx/geometry/rect_conversions.h" | 16 #include "ui/gfx/geometry/rect_conversions.h" |
| 17 #include "ui/gfx/geometry/vector3d_f.h" | 17 #include "ui/gfx/geometry/vector3d_f.h" |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 // Tolerance for considering axis vector elements to be zero. | 22 // Tolerance for considering axis vector elements to be zero. |
| 23 const SkMScalar kEpsilon = std::numeric_limits<float>::epsilon(); | 23 const SkMScalar kEpsilon = std::numeric_limits<float>::epsilon(); |
| 24 | 24 |
| 25 const gfx::BufferFormat kOverlayFormats[] = { |
| 26 gfx::BufferFormat::RGBX_8888, gfx::BufferFormat::RGBA_8888, |
| 27 gfx::BufferFormat::BGRX_8888, gfx::BufferFormat::BGRA_8888, |
| 28 gfx::BufferFormat::BGR_565}; |
| 29 |
| 25 enum Axis { NONE, AXIS_POS_X, AXIS_NEG_X, AXIS_POS_Y, AXIS_NEG_Y }; | 30 enum Axis { NONE, AXIS_POS_X, AXIS_NEG_X, AXIS_POS_Y, AXIS_NEG_Y }; |
| 26 | 31 |
| 27 Axis VectorToAxis(const gfx::Vector3dF& vec) { | 32 Axis VectorToAxis(const gfx::Vector3dF& vec) { |
| 28 if (std::abs(vec.z()) > kEpsilon) | 33 if (std::abs(vec.z()) > kEpsilon) |
| 29 return NONE; | 34 return NONE; |
| 30 const bool x_zero = (std::abs(vec.x()) <= kEpsilon); | 35 const bool x_zero = (std::abs(vec.x()) <= kEpsilon); |
| 31 const bool y_zero = (std::abs(vec.y()) <= kEpsilon); | 36 const bool y_zero = (std::abs(vec.y()) <= kEpsilon); |
| 32 if (x_zero && !y_zero) | 37 if (x_zero && !y_zero) |
| 33 return (vec.y() > 0) ? AXIS_POS_Y : AXIS_NEG_Y; | 38 return (vec.y() > 0) ? AXIS_POS_Y : AXIS_NEG_Y; |
| 34 else if (y_zero && !x_zero) | 39 else if (y_zero && !x_zero) |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 255 } |
| 251 return false; | 256 return false; |
| 252 } | 257 } |
| 253 | 258 |
| 254 // static | 259 // static |
| 255 bool OverlayCandidate::FromTextureQuad(ResourceProvider* resource_provider, | 260 bool OverlayCandidate::FromTextureQuad(ResourceProvider* resource_provider, |
| 256 const TextureDrawQuad* quad, | 261 const TextureDrawQuad* quad, |
| 257 OverlayCandidate* candidate) { | 262 OverlayCandidate* candidate) { |
| 258 if (!resource_provider->IsOverlayCandidate(quad->resource_id())) | 263 if (!resource_provider->IsOverlayCandidate(quad->resource_id())) |
| 259 return false; | 264 return false; |
| 265 |
| 266 gfx::BufferFormat format = |
| 267 resource_provider->GetBufferFormat(quad->resource_id()); |
| 268 if (std::find(std::begin(kOverlayFormats), std::end(kOverlayFormats), |
| 269 format) == std::end(kOverlayFormats)) |
| 270 return false; |
| 260 gfx::OverlayTransform overlay_transform = GetOverlayTransform( | 271 gfx::OverlayTransform overlay_transform = GetOverlayTransform( |
| 261 quad->shared_quad_state->quad_to_target_transform, quad->y_flipped); | 272 quad->shared_quad_state->quad_to_target_transform, quad->y_flipped); |
| 262 if (quad->background_color != SK_ColorTRANSPARENT || | 273 if (quad->background_color != SK_ColorTRANSPARENT || |
| 263 overlay_transform == gfx::OVERLAY_TRANSFORM_INVALID) | 274 overlay_transform == gfx::OVERLAY_TRANSFORM_INVALID) |
| 264 return false; | 275 return false; |
| 265 candidate->resource_id = quad->resource_id(); | 276 candidate->resource_id = quad->resource_id(); |
| 266 candidate->resource_size_in_pixels = quad->resource_size_in_pixels(); | 277 candidate->resource_size_in_pixels = quad->resource_size_in_pixels(); |
| 267 candidate->transform = overlay_transform; | 278 candidate->transform = overlay_transform; |
| 268 candidate->uv_rect = BoundingRect(quad->uv_top_left, quad->uv_bottom_right); | 279 candidate->uv_rect = BoundingRect(quad->uv_top_left, quad->uv_bottom_right); |
| 269 return true; | 280 return true; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 | 345 |
| 335 OverlayCandidateList& OverlayCandidateList::operator=( | 346 OverlayCandidateList& OverlayCandidateList::operator=( |
| 336 OverlayCandidateList&& other) = default; | 347 OverlayCandidateList&& other) = default; |
| 337 | 348 |
| 338 void OverlayCandidateList::AddPromotionHint(const OverlayCandidate& candidate) { | 349 void OverlayCandidateList::AddPromotionHint(const OverlayCandidate& candidate) { |
| 339 promotion_hint_info_map_[candidate.resource_id] = | 350 promotion_hint_info_map_[candidate.resource_id] = |
| 340 candidate.display_rect.origin(); | 351 candidate.display_rect.origin(); |
| 341 } | 352 } |
| 342 | 353 |
| 343 } // namespace cc | 354 } // namespace cc |
| OLD | NEW |