Chromium Code Reviews| Index: cc/output/gl_renderer.cc |
| diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc |
| index 3eecc1329dd45ef01a6d5ffb09755bfa28ff97e5..d13a37092c0ce2e7b3d3b8035a7ffad264ab2bac 100644 |
| --- a/cc/output/gl_renderer.cc |
| +++ b/cc/output/gl_renderer.cc |
| @@ -167,6 +167,8 @@ struct DrawRenderPassDrawQuadParams { |
| gfx::Transform window_matrix; |
| gfx::Transform projection_matrix; |
| gfx::Transform quad_to_target_transform; |
| + const FilterOperations* filters = nullptr; |
| + const FilterOperations* background_filters = nullptr; |
| // |frame| is only used for background effects. |
| DirectRenderer::DrawingFrame* frame = nullptr; |
| @@ -792,9 +794,12 @@ void GLRenderer::RestoreBlendFuncToDefault(SkBlendMode blend_mode) { |
| } |
| } |
| -bool GLRenderer::ShouldApplyBackgroundFilters(const RenderPassDrawQuad* quad) { |
| - if (quad->background_filters.IsEmpty()) |
| +bool GLRenderer::ShouldApplyBackgroundFilters( |
| + const RenderPassDrawQuad* quad, |
| + const FilterOperations* background_filters) { |
| + if (!background_filters) |
| return false; |
| + DCHECK(!background_filters->IsEmpty()); |
| // TODO(hendrikw): Look into allowing background filters to see pixels from |
| // other render targets. See crbug.com/314867. |
| @@ -843,6 +848,8 @@ gfx::Rect GLRenderer::GetBackdropBoundingBoxForRenderPassQuad( |
| DrawingFrame* frame, |
| const RenderPassDrawQuad* quad, |
| const gfx::Transform& contents_device_transform, |
| + const FilterOperations* filters, |
| + const FilterOperations* background_filters, |
| const gfx::QuadF* clip_region, |
| bool use_aa, |
| gfx::Rect* unclipped_rect) { |
| @@ -854,7 +861,7 @@ gfx::Rect GLRenderer::GetBackdropBoundingBoxForRenderPassQuad( |
| gfx::Rect backdrop_rect = gfx::ToEnclosingRect(MathUtil::MapClippedRect( |
| contents_device_transform, scaled_region.BoundingBox())); |
| - if (ShouldApplyBackgroundFilters(quad)) { |
| + if (ShouldApplyBackgroundFilters(quad, background_filters)) { |
| SkMatrix matrix; |
| matrix.setScale(quad->filters_scale.x(), quad->filters_scale.y()); |
| if (FlippedFramebuffer(frame)) { |
| @@ -863,8 +870,7 @@ gfx::Rect GLRenderer::GetBackdropBoundingBoxForRenderPassQuad( |
| // frame->window_matrix and contents_device_transform? |
| matrix.postScale(1, -1); |
| } |
| - backdrop_rect = |
| - quad->background_filters.MapRectReverse(backdrop_rect, matrix); |
| + backdrop_rect = background_filters->MapRectReverse(backdrop_rect, matrix); |
| } |
| if (!backdrop_rect.IsEmpty() && use_aa) { |
| @@ -872,7 +878,8 @@ gfx::Rect GLRenderer::GetBackdropBoundingBoxForRenderPassQuad( |
| backdrop_rect.Inset(-kOutsetForAntialiasing, -kOutsetForAntialiasing); |
| } |
| - if (!quad->filters.IsEmpty()) { |
| + if (filters) { |
| + DCHECK(!filters->IsEmpty()); |
| // If we have filters, grab an extra one-pixel border around the |
| // background, so texture edge clamping gives us a transparent border |
| // in case the filter expands the result. |
| @@ -904,17 +911,18 @@ std::unique_ptr<ScopedResource> GLRenderer::GetBackdropTexture( |
| sk_sp<SkImage> GLRenderer::ApplyBackgroundFilters( |
| const RenderPassDrawQuad* quad, |
| + const FilterOperations* background_filters, |
|
danakj
2016/12/01 01:50:46
if this can't be null maybe pass it by const& to h
weiliangc
2016/12/01 19:04:31
So it's every RP always have filters, but most tim
danakj
2016/12/01 21:14:34
No we don't call this function if it was null (we
ajuma
2016/12/13 15:08:11
Done.
|
| ScopedResource* background_texture, |
| const gfx::RectF& rect, |
| const gfx::RectF& unclipped_rect) { |
| - DCHECK(ShouldApplyBackgroundFilters(quad)); |
| + DCHECK(ShouldApplyBackgroundFilters(quad, background_filters)); |
| auto use_gr_context = ScopedUseGrContext::Create(this); |
| gfx::Vector2dF clipping_offset = |
| (rect.top_right() - unclipped_rect.top_right()) + |
| (rect.bottom_left() - unclipped_rect.bottom_left()); |
| sk_sp<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( |
| - quad->background_filters, gfx::SizeF(background_texture->size()), |
| + *background_filters, gfx::SizeF(background_texture->size()), |
| clipping_offset); |
| // TODO(senorblanco): background filters should be moved to the |
| @@ -1088,7 +1096,11 @@ bool GLRenderer::InitializeRPDQParameters( |
| SkMatrix local_matrix; |
| local_matrix.setTranslate(quad->filters_origin.x(), quad->filters_origin.y()); |
| local_matrix.postScale(quad->filters_scale.x(), quad->filters_scale.y()); |
| - gfx::Rect dst_rect = quad->filters.MapRect(quad->rect, local_matrix); |
| + params->filters = FiltersForPass(quad->render_pass_id); |
| + params->background_filters = BackgroundFiltersForPass(quad->render_pass_id); |
| + gfx::Rect dst_rect = params->filters |
| + ? params->filters->MapRect(quad->rect, local_matrix) |
| + : quad->rect; |
| params->dst_rect.SetRect(static_cast<float>(dst_rect.x()), |
| static_cast<float>(dst_rect.y()), |
| static_cast<float>(dst_rect.width()), |
| @@ -1129,7 +1141,7 @@ void GLRenderer::UpdateRPDQShadersForBlending( |
| SkBlendMode blend_mode = quad->shared_quad_state->blend_mode; |
| params->use_shaders_for_blending = |
| !CanApplyBlendModeUsingBlendFunc(blend_mode) || |
| - ShouldApplyBackgroundFilters(quad) || |
| + ShouldApplyBackgroundFilters(quad, params->background_filters) || |
| settings_->force_blending_with_shaders; |
| if (params->use_shaders_for_blending) { |
| @@ -1138,8 +1150,9 @@ void GLRenderer::UpdateRPDQShadersForBlending( |
| // the quad. |
| gfx::Rect unclipped_rect; |
| params->background_rect = GetBackdropBoundingBoxForRenderPassQuad( |
| - params->frame, quad, params->contents_device_transform, |
| - params->clip_region, params->use_aa, &unclipped_rect); |
| + params->frame, quad, params->contents_device_transform, params->filters, |
| + params->background_filters, params->clip_region, params->use_aa, |
| + &unclipped_rect); |
| if (!params->background_rect.IsEmpty()) { |
| // The pixels from the filtered background should completely replace the |
| @@ -1154,11 +1167,12 @@ void GLRenderer::UpdateRPDQShadersForBlending( |
| params->background_texture = |
| GetBackdropTexture(params->frame, params->background_rect); |
| - if (ShouldApplyBackgroundFilters(quad) && params->background_texture) { |
| + if (ShouldApplyBackgroundFilters(quad, params->background_filters) && |
| + params->background_texture) { |
| // Apply the background filters to R, so that it is applied in the |
| // pixels' coordinate space. |
| params->background_image = ApplyBackgroundFilters( |
| - quad, params->background_texture.get(), |
| + quad, params->background_filters, params->background_texture.get(), |
| gfx::RectF(params->background_rect), gfx::RectF(unclipped_rect)); |
| if (params->background_image) { |
| params->background_image_id = |
| @@ -1179,7 +1193,7 @@ void GLRenderer::UpdateRPDQShadersForBlending( |
| if (!quad->mask_resource_id()) |
| params->background_texture.reset(); |
| } else if (CanApplyBlendModeUsingBlendFunc(blend_mode) && |
| - ShouldApplyBackgroundFilters(quad)) { |
| + ShouldApplyBackgroundFilters(quad, params->background_filters)) { |
| // Something went wrong with applying background filters to the backdrop. |
| params->use_shaders_for_blending = false; |
| params->background_texture.reset(); |
| @@ -1198,9 +1212,10 @@ bool GLRenderer::UpdateRPDQWithSkiaFilters( |
| DrawRenderPassDrawQuadParams* params) { |
| const RenderPassDrawQuad* quad = params->quad; |
| // Apply filters to the contents texture. |
| - if (!quad->filters.IsEmpty()) { |
| + if (params->filters) { |
| + DCHECK(!params->filters->IsEmpty()); |
| sk_sp<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( |
| - quad->filters, gfx::SizeF(params->contents_texture->size())); |
| + *params->filters, gfx::SizeF(params->contents_texture->size())); |
| if (filter) { |
| SkColorFilter* colorfilter_rawptr = NULL; |
| filter->asColorFilter(&colorfilter_rawptr); |