| 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/ca_layer_overlay.h" | 5 #include "cc/output/ca_layer_overlay.h" |
| 6 | 6 |
| 7 #include <algorithm> |
| 8 |
| 7 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 8 #include "cc/quads/render_pass_draw_quad.h" | 10 #include "cc/quads/render_pass_draw_quad.h" |
| 9 #include "cc/quads/solid_color_draw_quad.h" | 11 #include "cc/quads/solid_color_draw_quad.h" |
| 10 #include "cc/quads/stream_video_draw_quad.h" | 12 #include "cc/quads/stream_video_draw_quad.h" |
| 11 #include "cc/quads/texture_draw_quad.h" | 13 #include "cc/quads/texture_draw_quad.h" |
| 12 #include "cc/quads/tile_draw_quad.h" | 14 #include "cc/quads/tile_draw_quad.h" |
| 13 #include "cc/resources/resource_provider.h" | 15 #include "cc/resources/resource_provider.h" |
| 14 #include "gpu/GLES2/gl2extchromium.h" | 16 #include "gpu/GLES2/gl2extchromium.h" |
| 15 | 17 |
| 16 namespace cc { | 18 namespace cc { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 case FilterOperation::CONTRAST: | 67 case FilterOperation::CONTRAST: |
| 66 case FilterOperation::OPACITY: | 68 case FilterOperation::OPACITY: |
| 67 case FilterOperation::BLUR: | 69 case FilterOperation::BLUR: |
| 68 case FilterOperation::DROP_SHADOW: | 70 case FilterOperation::DROP_SHADOW: |
| 69 return true; | 71 return true; |
| 70 default: | 72 default: |
| 71 return false; | 73 return false; |
| 72 } | 74 } |
| 73 } | 75 } |
| 74 | 76 |
| 75 CALayerResult FromRenderPassQuad(ResourceProvider* resource_provider, | 77 static const FilterOperations* FiltersForPass( |
| 76 const RenderPassDrawQuad* quad, | 78 RenderPassId id, |
| 77 CALayerOverlay* ca_layer_overlay) { | 79 const RenderPassFilterList& filter_list) { |
| 78 if (quad->background_filters.size() != 0) | 80 auto it = |
| 81 std::find_if(filter_list.begin(), filter_list.end(), |
| 82 [id](const std::pair<RenderPassId, FilterOperations>& p) { |
| 83 return p.first == id; |
| 84 }); |
| 85 return it == filter_list.end() ? nullptr : &it->second; |
| 86 } |
| 87 |
| 88 CALayerResult FromRenderPassQuad( |
| 89 ResourceProvider* resource_provider, |
| 90 const RenderPassDrawQuad* quad, |
| 91 const RenderPassFilterList& render_pass_filters, |
| 92 const RenderPassFilterList& render_pass_background_filters, |
| 93 CALayerOverlay* ca_layer_overlay) { |
| 94 if (FiltersForPass(quad->render_pass_id, render_pass_background_filters)) { |
| 79 return CA_LAYER_FAILED_RENDER_PASS_BACKGROUND_FILTERS; | 95 return CA_LAYER_FAILED_RENDER_PASS_BACKGROUND_FILTERS; |
| 96 } |
| 80 | 97 |
| 81 if (quad->shared_quad_state->sorting_context_id != 0) | 98 if (quad->shared_quad_state->sorting_context_id != 0) |
| 82 return CA_LAYER_FAILED_RENDER_PASS_SORTING_CONTEXT_ID; | 99 return CA_LAYER_FAILED_RENDER_PASS_SORTING_CONTEXT_ID; |
| 83 | 100 |
| 84 for (const FilterOperation& operation : quad->filters.operations()) { | 101 const FilterOperations* filters = |
| 85 bool success = FilterOperationSupported(operation); | 102 FiltersForPass(quad->render_pass_id, render_pass_filters); |
| 86 if (!success) | 103 if (filters) { |
| 87 return CA_LAYER_FAILED_RENDER_PASS_FILTER_OPERATION; | 104 for (const FilterOperation& operation : filters->operations()) { |
| 105 bool success = FilterOperationSupported(operation); |
| 106 if (!success) |
| 107 return CA_LAYER_FAILED_RENDER_PASS_FILTER_OPERATION; |
| 108 } |
| 88 } | 109 } |
| 89 | 110 |
| 90 ca_layer_overlay->rpdq = quad; | 111 ca_layer_overlay->rpdq = quad; |
| 91 ca_layer_overlay->contents_rect = gfx::RectF(0, 0, 1, 1); | 112 ca_layer_overlay->contents_rect = gfx::RectF(0, 0, 1, 1); |
| 92 | 113 |
| 93 return CA_LAYER_SUCCESS; | 114 return CA_LAYER_SUCCESS; |
| 94 } | 115 } |
| 95 | 116 |
| 96 CALayerResult FromStreamVideoQuad(ResourceProvider* resource_provider, | 117 CALayerResult FromStreamVideoQuad(ResourceProvider* resource_provider, |
| 97 const StreamVideoDrawQuad* quad, | 118 const StreamVideoDrawQuad* quad, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 return CA_LAYER_FAILED_TILE_NOT_CANDIDATE; | 177 return CA_LAYER_FAILED_TILE_NOT_CANDIDATE; |
| 157 ca_layer_overlay->contents_resource_id = resource_id; | 178 ca_layer_overlay->contents_resource_id = resource_id; |
| 158 ca_layer_overlay->contents_rect = quad->tex_coord_rect; | 179 ca_layer_overlay->contents_rect = quad->tex_coord_rect; |
| 159 ca_layer_overlay->contents_rect.Scale(1.f / quad->texture_size.width(), | 180 ca_layer_overlay->contents_rect.Scale(1.f / quad->texture_size.width(), |
| 160 1.f / quad->texture_size.height()); | 181 1.f / quad->texture_size.height()); |
| 161 return CA_LAYER_SUCCESS; | 182 return CA_LAYER_SUCCESS; |
| 162 } | 183 } |
| 163 | 184 |
| 164 class CALayerOverlayProcessor { | 185 class CALayerOverlayProcessor { |
| 165 public: | 186 public: |
| 166 CALayerResult FromDrawQuad(ResourceProvider* resource_provider, | 187 CALayerResult FromDrawQuad( |
| 167 const gfx::RectF& display_rect, | 188 ResourceProvider* resource_provider, |
| 168 const DrawQuad* quad, | 189 const gfx::RectF& display_rect, |
| 169 CALayerOverlay* ca_layer_overlay, | 190 const DrawQuad* quad, |
| 170 bool* skip, | 191 const RenderPassFilterList& render_pass_filters, |
| 171 bool* render_pass_draw_quad) { | 192 const RenderPassFilterList& render_pass_background_filters, |
| 193 CALayerOverlay* ca_layer_overlay, |
| 194 bool* skip, |
| 195 bool* render_pass_draw_quad) { |
| 172 if (quad->shared_quad_state->blend_mode != SkBlendMode::kSrcOver) | 196 if (quad->shared_quad_state->blend_mode != SkBlendMode::kSrcOver) |
| 173 return CA_LAYER_FAILED_QUAD_BLEND_MODE; | 197 return CA_LAYER_FAILED_QUAD_BLEND_MODE; |
| 174 | 198 |
| 175 // Early-out for invisible quads. | 199 // Early-out for invisible quads. |
| 176 if (quad->shared_quad_state->opacity == 0.f) { | 200 if (quad->shared_quad_state->opacity == 0.f) { |
| 177 *skip = true; | 201 *skip = true; |
| 178 return CA_LAYER_SUCCESS; | 202 return CA_LAYER_SUCCESS; |
| 179 } | 203 } |
| 180 | 204 |
| 181 // Enable edge anti-aliasing only on layer boundaries. | 205 // Enable edge anti-aliasing only on layer boundaries. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 ca_layer_overlay, skip); | 247 ca_layer_overlay, skip); |
| 224 case DrawQuad::STREAM_VIDEO_CONTENT: | 248 case DrawQuad::STREAM_VIDEO_CONTENT: |
| 225 return FromStreamVideoQuad(resource_provider, | 249 return FromStreamVideoQuad(resource_provider, |
| 226 StreamVideoDrawQuad::MaterialCast(quad), | 250 StreamVideoDrawQuad::MaterialCast(quad), |
| 227 ca_layer_overlay); | 251 ca_layer_overlay); |
| 228 case DrawQuad::DEBUG_BORDER: | 252 case DrawQuad::DEBUG_BORDER: |
| 229 return CA_LAYER_FAILED_DEBUG_BORDER; | 253 return CA_LAYER_FAILED_DEBUG_BORDER; |
| 230 case DrawQuad::PICTURE_CONTENT: | 254 case DrawQuad::PICTURE_CONTENT: |
| 231 return CA_LAYER_FAILED_PICTURE_CONTENT; | 255 return CA_LAYER_FAILED_PICTURE_CONTENT; |
| 232 case DrawQuad::RENDER_PASS: | 256 case DrawQuad::RENDER_PASS: |
| 233 return FromRenderPassQuad(resource_provider, | 257 return FromRenderPassQuad( |
| 234 RenderPassDrawQuad::MaterialCast(quad), | 258 resource_provider, RenderPassDrawQuad::MaterialCast(quad), |
| 235 ca_layer_overlay); | 259 render_pass_filters, render_pass_background_filters, |
| 260 ca_layer_overlay); |
| 236 case DrawQuad::SURFACE_CONTENT: | 261 case DrawQuad::SURFACE_CONTENT: |
| 237 return CA_LAYER_FAILED_SURFACE_CONTENT; | 262 return CA_LAYER_FAILED_SURFACE_CONTENT; |
| 238 case DrawQuad::YUV_VIDEO_CONTENT: | 263 case DrawQuad::YUV_VIDEO_CONTENT: |
| 239 return CA_LAYER_FAILED_YUV_VIDEO_CONTENT; | 264 return CA_LAYER_FAILED_YUV_VIDEO_CONTENT; |
| 240 default: | 265 default: |
| 241 break; | 266 break; |
| 242 } | 267 } |
| 243 | 268 |
| 244 return CA_LAYER_FAILED_UNKNOWN; | 269 return CA_LAYER_FAILED_UNKNOWN; |
| 245 } | 270 } |
| 246 | 271 |
| 247 private: | 272 private: |
| 248 const SharedQuadState* most_recent_shared_quad_state_ = nullptr; | 273 const SharedQuadState* most_recent_shared_quad_state_ = nullptr; |
| 249 scoped_refptr<CALayerOverlaySharedState> most_recent_overlay_shared_state_; | 274 scoped_refptr<CALayerOverlaySharedState> most_recent_overlay_shared_state_; |
| 250 }; | 275 }; |
| 251 | 276 |
| 252 } // namespace | 277 } // namespace |
| 253 | 278 |
| 254 CALayerOverlay::CALayerOverlay() : filter(GL_LINEAR) {} | 279 CALayerOverlay::CALayerOverlay() : filter(GL_LINEAR) {} |
| 255 | 280 |
| 256 CALayerOverlay::CALayerOverlay(const CALayerOverlay& other) = default; | 281 CALayerOverlay::CALayerOverlay(const CALayerOverlay& other) = default; |
| 257 | 282 |
| 258 CALayerOverlay::~CALayerOverlay() {} | 283 CALayerOverlay::~CALayerOverlay() {} |
| 259 | 284 |
| 260 bool ProcessForCALayerOverlays(ResourceProvider* resource_provider, | 285 bool ProcessForCALayerOverlays( |
| 261 const gfx::RectF& display_rect, | 286 ResourceProvider* resource_provider, |
| 262 const QuadList& quad_list, | 287 const gfx::RectF& display_rect, |
| 263 CALayerOverlayList* ca_layer_overlays) { | 288 const QuadList& quad_list, |
| 289 const RenderPassFilterList& render_pass_filters, |
| 290 const RenderPassFilterList& render_pass_background_filters, |
| 291 CALayerOverlayList* ca_layer_overlays) { |
| 264 CALayerResult result = CA_LAYER_SUCCESS; | 292 CALayerResult result = CA_LAYER_SUCCESS; |
| 265 ca_layer_overlays->reserve(quad_list.size()); | 293 ca_layer_overlays->reserve(quad_list.size()); |
| 266 | 294 |
| 267 int render_pass_draw_quad_count = 0; | 295 int render_pass_draw_quad_count = 0; |
| 268 CALayerOverlayProcessor processor; | 296 CALayerOverlayProcessor processor; |
| 269 for (auto it = quad_list.BackToFrontBegin(); it != quad_list.BackToFrontEnd(); | 297 for (auto it = quad_list.BackToFrontBegin(); it != quad_list.BackToFrontEnd(); |
| 270 ++it) { | 298 ++it) { |
| 271 const DrawQuad* quad = *it; | 299 const DrawQuad* quad = *it; |
| 272 CALayerOverlay ca_layer; | 300 CALayerOverlay ca_layer; |
| 273 bool skip = false; | 301 bool skip = false; |
| 274 bool render_pass_draw_quad = false; | 302 bool render_pass_draw_quad = false; |
| 275 result = processor.FromDrawQuad(resource_provider, display_rect, quad, | 303 result = processor.FromDrawQuad(resource_provider, display_rect, quad, |
| 276 &ca_layer, &skip, &render_pass_draw_quad); | 304 render_pass_filters, |
| 305 render_pass_background_filters, &ca_layer, |
| 306 &skip, &render_pass_draw_quad); |
| 277 if (result != CA_LAYER_SUCCESS) | 307 if (result != CA_LAYER_SUCCESS) |
| 278 break; | 308 break; |
| 279 | 309 |
| 280 if (render_pass_draw_quad) { | 310 if (render_pass_draw_quad) { |
| 281 ++render_pass_draw_quad_count; | 311 ++render_pass_draw_quad_count; |
| 282 if (render_pass_draw_quad_count > kTooManyRenderPassDrawQuads) { | 312 if (render_pass_draw_quad_count > kTooManyRenderPassDrawQuads) { |
| 283 result = CA_LAYER_FAILED_TOO_MANY_RENDER_PASS_DRAW_QUADS; | 313 result = CA_LAYER_FAILED_TOO_MANY_RENDER_PASS_DRAW_QUADS; |
| 284 break; | 314 break; |
| 285 } | 315 } |
| 286 } | 316 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 312 CA_LAYER_FAILED_COUNT); | 342 CA_LAYER_FAILED_COUNT); |
| 313 | 343 |
| 314 if (result != CA_LAYER_SUCCESS) { | 344 if (result != CA_LAYER_SUCCESS) { |
| 315 ca_layer_overlays->clear(); | 345 ca_layer_overlays->clear(); |
| 316 return false; | 346 return false; |
| 317 } | 347 } |
| 318 return true; | 348 return true; |
| 319 } | 349 } |
| 320 | 350 |
| 321 } // namespace cc | 351 } // namespace cc |
| OLD | NEW |