Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: cc/output/gl_renderer.cc

Issue 2543473004: cc: Move filters from RenderPassDrawQuad to RenderPass (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 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/gl_renderer.h" 5 #include "cc/output/gl_renderer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 ~DrawRenderPassDrawQuadParams() {} 160 ~DrawRenderPassDrawQuadParams() {}
161 161
162 // Required Inputs. 162 // Required Inputs.
163 const RenderPassDrawQuad* quad = nullptr; 163 const RenderPassDrawQuad* quad = nullptr;
164 const Resource* contents_texture = nullptr; 164 const Resource* contents_texture = nullptr;
165 const gfx::QuadF* clip_region = nullptr; 165 const gfx::QuadF* clip_region = nullptr;
166 bool flip_texture = false; 166 bool flip_texture = false;
167 gfx::Transform window_matrix; 167 gfx::Transform window_matrix;
168 gfx::Transform projection_matrix; 168 gfx::Transform projection_matrix;
169 gfx::Transform quad_to_target_transform; 169 gfx::Transform quad_to_target_transform;
170 const FilterOperations* filters = nullptr;
171 const FilterOperations* background_filters = nullptr;
170 172
171 // |frame| is only used for background effects. 173 // |frame| is only used for background effects.
172 DirectRenderer::DrawingFrame* frame = nullptr; 174 DirectRenderer::DrawingFrame* frame = nullptr;
173 175
174 // Whether the texture to be sampled from needs to be flipped. 176 // Whether the texture to be sampled from needs to be flipped.
175 bool source_needs_flip = false; 177 bool source_needs_flip = false;
176 178
177 float edge[24]; 179 float edge[24];
178 SkScalar color_matrix[20]; 180 SkScalar color_matrix[20];
179 181
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 if (blend_mode == SkBlendMode::kSrcOver) 787 if (blend_mode == SkBlendMode::kSrcOver)
786 return; 788 return;
787 789
788 if (use_blend_equation_advanced_) { 790 if (use_blend_equation_advanced_) {
789 gl_->BlendEquation(GL_FUNC_ADD); 791 gl_->BlendEquation(GL_FUNC_ADD);
790 } else { 792 } else {
791 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 793 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
792 } 794 }
793 } 795 }
794 796
795 bool GLRenderer::ShouldApplyBackgroundFilters(const RenderPassDrawQuad* quad) { 797 bool GLRenderer::ShouldApplyBackgroundFilters(
796 if (quad->background_filters.IsEmpty()) 798 const RenderPassDrawQuad* quad,
799 const FilterOperations* background_filters) {
800 if (!background_filters)
797 return false; 801 return false;
802 DCHECK(!background_filters->IsEmpty());
798 803
799 // TODO(hendrikw): Look into allowing background filters to see pixels from 804 // TODO(hendrikw): Look into allowing background filters to see pixels from
800 // other render targets. See crbug.com/314867. 805 // other render targets. See crbug.com/314867.
801 806
802 return true; 807 return true;
803 } 808 }
804 809
805 // This takes a gfx::Rect and a clip region quad in the same space, 810 // This takes a gfx::Rect and a clip region quad in the same space,
806 // and returns a quad with the same proportions in the space -0.5->0.5. 811 // and returns a quad with the same proportions in the space -0.5->0.5.
807 bool GetScaledRegion(const gfx::Rect& rect, 812 bool GetScaledRegion(const gfx::Rect& rect,
(...skipping 28 matching lines...) Expand all
836 uvs[5] = ((clip->p3().y() - rect.y()) / rect.height()); 841 uvs[5] = ((clip->p3().y() - rect.y()) / rect.height());
837 uvs[6] = ((clip->p4().x() - rect.x()) / rect.width()); 842 uvs[6] = ((clip->p4().x() - rect.x()) / rect.width());
838 uvs[7] = ((clip->p4().y() - rect.y()) / rect.height()); 843 uvs[7] = ((clip->p4().y() - rect.y()) / rect.height());
839 return true; 844 return true;
840 } 845 }
841 846
842 gfx::Rect GLRenderer::GetBackdropBoundingBoxForRenderPassQuad( 847 gfx::Rect GLRenderer::GetBackdropBoundingBoxForRenderPassQuad(
843 DrawingFrame* frame, 848 DrawingFrame* frame,
844 const RenderPassDrawQuad* quad, 849 const RenderPassDrawQuad* quad,
845 const gfx::Transform& contents_device_transform, 850 const gfx::Transform& contents_device_transform,
851 const FilterOperations* filters,
852 const FilterOperations* background_filters,
846 const gfx::QuadF* clip_region, 853 const gfx::QuadF* clip_region,
847 bool use_aa, 854 bool use_aa,
848 gfx::Rect* unclipped_rect) { 855 gfx::Rect* unclipped_rect) {
849 gfx::QuadF scaled_region; 856 gfx::QuadF scaled_region;
850 if (!GetScaledRegion(quad->rect, clip_region, &scaled_region)) { 857 if (!GetScaledRegion(quad->rect, clip_region, &scaled_region)) {
851 scaled_region = SharedGeometryQuad().BoundingBox(); 858 scaled_region = SharedGeometryQuad().BoundingBox();
852 } 859 }
853 860
854 gfx::Rect backdrop_rect = gfx::ToEnclosingRect(MathUtil::MapClippedRect( 861 gfx::Rect backdrop_rect = gfx::ToEnclosingRect(MathUtil::MapClippedRect(
855 contents_device_transform, scaled_region.BoundingBox())); 862 contents_device_transform, scaled_region.BoundingBox()));
856 863
857 if (ShouldApplyBackgroundFilters(quad)) { 864 if (ShouldApplyBackgroundFilters(quad, background_filters)) {
858 SkMatrix matrix; 865 SkMatrix matrix;
859 matrix.setScale(quad->filters_scale.x(), quad->filters_scale.y()); 866 matrix.setScale(quad->filters_scale.x(), quad->filters_scale.y());
860 if (FlippedFramebuffer(frame)) { 867 if (FlippedFramebuffer(frame)) {
861 // TODO(jbroman): This probably isn't the right way to account for this. 868 // TODO(jbroman): This probably isn't the right way to account for this.
862 // Probably some combination of frame->projection_matrix, 869 // Probably some combination of frame->projection_matrix,
863 // frame->window_matrix and contents_device_transform? 870 // frame->window_matrix and contents_device_transform?
864 matrix.postScale(1, -1); 871 matrix.postScale(1, -1);
865 } 872 }
866 backdrop_rect = 873 backdrop_rect = background_filters->MapRectReverse(backdrop_rect, matrix);
867 quad->background_filters.MapRectReverse(backdrop_rect, matrix);
868 } 874 }
869 875
870 if (!backdrop_rect.IsEmpty() && use_aa) { 876 if (!backdrop_rect.IsEmpty() && use_aa) {
871 const int kOutsetForAntialiasing = 1; 877 const int kOutsetForAntialiasing = 1;
872 backdrop_rect.Inset(-kOutsetForAntialiasing, -kOutsetForAntialiasing); 878 backdrop_rect.Inset(-kOutsetForAntialiasing, -kOutsetForAntialiasing);
873 } 879 }
874 880
875 if (!quad->filters.IsEmpty()) { 881 if (filters) {
882 DCHECK(!filters->IsEmpty());
876 // If we have filters, grab an extra one-pixel border around the 883 // If we have filters, grab an extra one-pixel border around the
877 // background, so texture edge clamping gives us a transparent border 884 // background, so texture edge clamping gives us a transparent border
878 // in case the filter expands the result. 885 // in case the filter expands the result.
879 backdrop_rect.Inset(-1, -1, -1, -1); 886 backdrop_rect.Inset(-1, -1, -1, -1);
880 } 887 }
881 888
882 *unclipped_rect = backdrop_rect; 889 *unclipped_rect = backdrop_rect;
883 backdrop_rect.Intersect(MoveFromDrawToWindowSpace( 890 backdrop_rect.Intersect(MoveFromDrawToWindowSpace(
884 frame, frame->current_render_pass->output_rect)); 891 frame, frame->current_render_pass->output_rect));
885 return backdrop_rect; 892 return backdrop_rect;
(...skipping 11 matching lines...) Expand all
897 { 904 {
898 ResourceProvider::ScopedWriteLockGL lock( 905 ResourceProvider::ScopedWriteLockGL lock(
899 resource_provider_, device_background_texture->id(), false); 906 resource_provider_, device_background_texture->id(), false);
900 GetFramebufferTexture(lock.texture_id(), bounding_rect); 907 GetFramebufferTexture(lock.texture_id(), bounding_rect);
901 } 908 }
902 return device_background_texture; 909 return device_background_texture;
903 } 910 }
904 911
905 sk_sp<SkImage> GLRenderer::ApplyBackgroundFilters( 912 sk_sp<SkImage> GLRenderer::ApplyBackgroundFilters(
906 const RenderPassDrawQuad* quad, 913 const RenderPassDrawQuad* quad,
914 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.
907 ScopedResource* background_texture, 915 ScopedResource* background_texture,
908 const gfx::RectF& rect, 916 const gfx::RectF& rect,
909 const gfx::RectF& unclipped_rect) { 917 const gfx::RectF& unclipped_rect) {
910 DCHECK(ShouldApplyBackgroundFilters(quad)); 918 DCHECK(ShouldApplyBackgroundFilters(quad, background_filters));
911 auto use_gr_context = ScopedUseGrContext::Create(this); 919 auto use_gr_context = ScopedUseGrContext::Create(this);
912 920
913 gfx::Vector2dF clipping_offset = 921 gfx::Vector2dF clipping_offset =
914 (rect.top_right() - unclipped_rect.top_right()) + 922 (rect.top_right() - unclipped_rect.top_right()) +
915 (rect.bottom_left() - unclipped_rect.bottom_left()); 923 (rect.bottom_left() - unclipped_rect.bottom_left());
916 sk_sp<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( 924 sk_sp<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter(
917 quad->background_filters, gfx::SizeF(background_texture->size()), 925 *background_filters, gfx::SizeF(background_texture->size()),
918 clipping_offset); 926 clipping_offset);
919 927
920 // TODO(senorblanco): background filters should be moved to the 928 // TODO(senorblanco): background filters should be moved to the
921 // makeWithFilter fast-path, and go back to calling ApplyImageFilter(). 929 // makeWithFilter fast-path, and go back to calling ApplyImageFilter().
922 // See http://crbug.com/613233. 930 // See http://crbug.com/613233.
923 if (!filter || !use_gr_context) 931 if (!filter || !use_gr_context)
924 return nullptr; 932 return nullptr;
925 933
926 ResourceProvider::ScopedReadLockGL lock(resource_provider_, 934 ResourceProvider::ScopedReadLockGL lock(resource_provider_,
927 background_texture->id()); 935 background_texture->id());
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 UpdateRPDQUniforms(params); 1089 UpdateRPDQUniforms(params);
1082 DrawRPDQ(*params); 1090 DrawRPDQ(*params);
1083 } 1091 }
1084 1092
1085 bool GLRenderer::InitializeRPDQParameters( 1093 bool GLRenderer::InitializeRPDQParameters(
1086 DrawRenderPassDrawQuadParams* params) { 1094 DrawRenderPassDrawQuadParams* params) {
1087 const RenderPassDrawQuad* quad = params->quad; 1095 const RenderPassDrawQuad* quad = params->quad;
1088 SkMatrix local_matrix; 1096 SkMatrix local_matrix;
1089 local_matrix.setTranslate(quad->filters_origin.x(), quad->filters_origin.y()); 1097 local_matrix.setTranslate(quad->filters_origin.x(), quad->filters_origin.y());
1090 local_matrix.postScale(quad->filters_scale.x(), quad->filters_scale.y()); 1098 local_matrix.postScale(quad->filters_scale.x(), quad->filters_scale.y());
1091 gfx::Rect dst_rect = quad->filters.MapRect(quad->rect, local_matrix); 1099 params->filters = FiltersForPass(quad->render_pass_id);
1100 params->background_filters = BackgroundFiltersForPass(quad->render_pass_id);
1101 gfx::Rect dst_rect = params->filters
1102 ? params->filters->MapRect(quad->rect, local_matrix)
1103 : quad->rect;
1092 params->dst_rect.SetRect(static_cast<float>(dst_rect.x()), 1104 params->dst_rect.SetRect(static_cast<float>(dst_rect.x()),
1093 static_cast<float>(dst_rect.y()), 1105 static_cast<float>(dst_rect.y()),
1094 static_cast<float>(dst_rect.width()), 1106 static_cast<float>(dst_rect.width()),
1095 static_cast<float>(dst_rect.height())); 1107 static_cast<float>(dst_rect.height()));
1096 gfx::Transform quad_rect_matrix; 1108 gfx::Transform quad_rect_matrix;
1097 QuadRectTransform(&quad_rect_matrix, params->quad_to_target_transform, 1109 QuadRectTransform(&quad_rect_matrix, params->quad_to_target_transform,
1098 params->dst_rect); 1110 params->dst_rect);
1099 params->contents_device_transform = 1111 params->contents_device_transform =
1100 params->window_matrix * params->projection_matrix * quad_rect_matrix; 1112 params->window_matrix * params->projection_matrix * quad_rect_matrix;
1101 params->contents_device_transform.FlattenTo2d(); 1113 params->contents_device_transform.FlattenTo2d();
(...skipping 20 matching lines...) Expand all
1122 1134
1123 return true; 1135 return true;
1124 } 1136 }
1125 1137
1126 void GLRenderer::UpdateRPDQShadersForBlending( 1138 void GLRenderer::UpdateRPDQShadersForBlending(
1127 DrawRenderPassDrawQuadParams* params) { 1139 DrawRenderPassDrawQuadParams* params) {
1128 const RenderPassDrawQuad* quad = params->quad; 1140 const RenderPassDrawQuad* quad = params->quad;
1129 SkBlendMode blend_mode = quad->shared_quad_state->blend_mode; 1141 SkBlendMode blend_mode = quad->shared_quad_state->blend_mode;
1130 params->use_shaders_for_blending = 1142 params->use_shaders_for_blending =
1131 !CanApplyBlendModeUsingBlendFunc(blend_mode) || 1143 !CanApplyBlendModeUsingBlendFunc(blend_mode) ||
1132 ShouldApplyBackgroundFilters(quad) || 1144 ShouldApplyBackgroundFilters(quad, params->background_filters) ||
1133 settings_->force_blending_with_shaders; 1145 settings_->force_blending_with_shaders;
1134 1146
1135 if (params->use_shaders_for_blending) { 1147 if (params->use_shaders_for_blending) {
1136 DCHECK(params->frame); 1148 DCHECK(params->frame);
1137 // Compute a bounding box around the pixels that will be visible through 1149 // Compute a bounding box around the pixels that will be visible through
1138 // the quad. 1150 // the quad.
1139 gfx::Rect unclipped_rect; 1151 gfx::Rect unclipped_rect;
1140 params->background_rect = GetBackdropBoundingBoxForRenderPassQuad( 1152 params->background_rect = GetBackdropBoundingBoxForRenderPassQuad(
1141 params->frame, quad, params->contents_device_transform, 1153 params->frame, quad, params->contents_device_transform, params->filters,
1142 params->clip_region, params->use_aa, &unclipped_rect); 1154 params->background_filters, params->clip_region, params->use_aa,
1155 &unclipped_rect);
1143 1156
1144 if (!params->background_rect.IsEmpty()) { 1157 if (!params->background_rect.IsEmpty()) {
1145 // The pixels from the filtered background should completely replace the 1158 // The pixels from the filtered background should completely replace the
1146 // current pixel values. 1159 // current pixel values.
1147 if (blend_enabled()) 1160 if (blend_enabled())
1148 SetBlendEnabled(false); 1161 SetBlendEnabled(false);
1149 1162
1150 // Read the pixels in the bounding box into a buffer R. 1163 // Read the pixels in the bounding box into a buffer R.
1151 // This function allocates a texture, which should contribute to the 1164 // This function allocates a texture, which should contribute to the
1152 // amount of memory used by render surfaces: 1165 // amount of memory used by render surfaces:
1153 // LayerTreeHost::CalculateMemoryForRenderSurfaces. 1166 // LayerTreeHost::CalculateMemoryForRenderSurfaces.
1154 params->background_texture = 1167 params->background_texture =
1155 GetBackdropTexture(params->frame, params->background_rect); 1168 GetBackdropTexture(params->frame, params->background_rect);
1156 1169
1157 if (ShouldApplyBackgroundFilters(quad) && params->background_texture) { 1170 if (ShouldApplyBackgroundFilters(quad, params->background_filters) &&
1171 params->background_texture) {
1158 // Apply the background filters to R, so that it is applied in the 1172 // Apply the background filters to R, so that it is applied in the
1159 // pixels' coordinate space. 1173 // pixels' coordinate space.
1160 params->background_image = ApplyBackgroundFilters( 1174 params->background_image = ApplyBackgroundFilters(
1161 quad, params->background_texture.get(), 1175 quad, params->background_filters, params->background_texture.get(),
1162 gfx::RectF(params->background_rect), gfx::RectF(unclipped_rect)); 1176 gfx::RectF(params->background_rect), gfx::RectF(unclipped_rect));
1163 if (params->background_image) { 1177 if (params->background_image) {
1164 params->background_image_id = 1178 params->background_image_id =
1165 skia::GrBackendObjectToGrGLTextureInfo( 1179 skia::GrBackendObjectToGrGLTextureInfo(
1166 params->background_image->getTextureHandle(true)) 1180 params->background_image->getTextureHandle(true))
1167 ->fID; 1181 ->fID;
1168 DCHECK(params->background_image_id); 1182 DCHECK(params->background_image_id);
1169 } 1183 }
1170 } 1184 }
1171 } 1185 }
1172 1186
1173 if (!params->background_texture) { 1187 if (!params->background_texture) {
1174 // Something went wrong with reading the backdrop. 1188 // Something went wrong with reading the backdrop.
1175 DCHECK(!params->background_image_id); 1189 DCHECK(!params->background_image_id);
1176 params->use_shaders_for_blending = false; 1190 params->use_shaders_for_blending = false;
1177 } else if (params->background_image_id) { 1191 } else if (params->background_image_id) {
1178 // Reset original background texture if there is not any mask 1192 // Reset original background texture if there is not any mask
1179 if (!quad->mask_resource_id()) 1193 if (!quad->mask_resource_id())
1180 params->background_texture.reset(); 1194 params->background_texture.reset();
1181 } else if (CanApplyBlendModeUsingBlendFunc(blend_mode) && 1195 } else if (CanApplyBlendModeUsingBlendFunc(blend_mode) &&
1182 ShouldApplyBackgroundFilters(quad)) { 1196 ShouldApplyBackgroundFilters(quad, params->background_filters)) {
1183 // Something went wrong with applying background filters to the backdrop. 1197 // Something went wrong with applying background filters to the backdrop.
1184 params->use_shaders_for_blending = false; 1198 params->use_shaders_for_blending = false;
1185 params->background_texture.reset(); 1199 params->background_texture.reset();
1186 } 1200 }
1187 } 1201 }
1188 // Need original background texture for mask? 1202 // Need original background texture for mask?
1189 params->mask_for_background = 1203 params->mask_for_background =
1190 params->background_texture && // Have original background texture 1204 params->background_texture && // Have original background texture
1191 params->background_image_id && // Have filtered background texture 1205 params->background_image_id && // Have filtered background texture
1192 quad->mask_resource_id(); // Have mask texture 1206 quad->mask_resource_id(); // Have mask texture
1193 DCHECK_EQ(params->background_texture || params->background_image_id, 1207 DCHECK_EQ(params->background_texture || params->background_image_id,
1194 params->use_shaders_for_blending); 1208 params->use_shaders_for_blending);
1195 } 1209 }
1196 1210
1197 bool GLRenderer::UpdateRPDQWithSkiaFilters( 1211 bool GLRenderer::UpdateRPDQWithSkiaFilters(
1198 DrawRenderPassDrawQuadParams* params) { 1212 DrawRenderPassDrawQuadParams* params) {
1199 const RenderPassDrawQuad* quad = params->quad; 1213 const RenderPassDrawQuad* quad = params->quad;
1200 // Apply filters to the contents texture. 1214 // Apply filters to the contents texture.
1201 if (!quad->filters.IsEmpty()) { 1215 if (params->filters) {
1216 DCHECK(!params->filters->IsEmpty());
1202 sk_sp<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( 1217 sk_sp<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter(
1203 quad->filters, gfx::SizeF(params->contents_texture->size())); 1218 *params->filters, gfx::SizeF(params->contents_texture->size()));
1204 if (filter) { 1219 if (filter) {
1205 SkColorFilter* colorfilter_rawptr = NULL; 1220 SkColorFilter* colorfilter_rawptr = NULL;
1206 filter->asColorFilter(&colorfilter_rawptr); 1221 filter->asColorFilter(&colorfilter_rawptr);
1207 sk_sp<SkColorFilter> cf(colorfilter_rawptr); 1222 sk_sp<SkColorFilter> cf(colorfilter_rawptr);
1208 1223
1209 if (cf && cf->asColorMatrix(params->color_matrix)) { 1224 if (cf && cf->asColorMatrix(params->color_matrix)) {
1210 // We have a color matrix at the root of the filter DAG; apply it 1225 // We have a color matrix at the root of the filter DAG; apply it
1211 // locally in the compositor and process the rest of the DAG (if any) 1226 // locally in the compositor and process the rest of the DAG (if any)
1212 // in Skia. 1227 // in Skia.
1213 params->use_color_matrix = true; 1228 params->use_color_matrix = true;
(...skipping 2841 matching lines...) Expand 10 before | Expand all | Expand 10 after
4055 // The alpha has already been applied when copying the RPDQ to an IOSurface. 4070 // The alpha has already been applied when copying the RPDQ to an IOSurface.
4056 GLfloat alpha = 1; 4071 GLfloat alpha = 1;
4057 gl_->ScheduleCALayerSharedStateCHROMIUM(alpha, is_clipped, clip_rect, 4072 gl_->ScheduleCALayerSharedStateCHROMIUM(alpha, is_clipped, clip_rect,
4058 sorting_context_id, gl_transform); 4073 sorting_context_id, gl_transform);
4059 gl_->ScheduleCALayerCHROMIUM( 4074 gl_->ScheduleCALayerCHROMIUM(
4060 texture_id, contents_rect, ca_layer_overlay->background_color, 4075 texture_id, contents_rect, ca_layer_overlay->background_color,
4061 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); 4076 ca_layer_overlay->edge_aa_mask, bounds_rect, filter);
4062 } 4077 }
4063 4078
4064 } // namespace cc 4079 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698