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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/filters/SkiaImageFilterBuilder.cpp

Issue 2889653002: Remove cullRect() from PaintOpBuffer. (Closed)
Patch Set: movecullrect2 rebase-once-and-for-all Created 3 years, 7 months 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 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 InterpolationSpaceUtilities::CreateInterpolationSpaceFilter( 103 InterpolationSpaceUtilities::CreateInterpolationSpaceFilter(
104 src_interpolation_space, dst_interpolation_space); 104 src_interpolation_space, dst_interpolation_space);
105 if (!color_filter) 105 if (!color_filter)
106 return input; 106 return input;
107 107
108 return SkColorFilterImageFilter::Make(std::move(color_filter), 108 return SkColorFilterImageFilter::Make(std::move(color_filter),
109 std::move(input)); 109 std::move(input));
110 } 110 }
111 111
112 void BuildSourceGraphic(FilterEffect* source_graphic, 112 void BuildSourceGraphic(FilterEffect* source_graphic,
113 sk_sp<PaintRecord> record) { 113 sk_sp<PaintRecord> record,
114 const FloatRect& record_bounds) {
114 DCHECK(record); 115 DCHECK(record);
115 SkRect cull_rect = record->cullRect();
116 sk_sp<SkImageFilter> filter = 116 sk_sp<SkImageFilter> filter =
117 SkPictureImageFilter::Make(ToSkPicture(record), cull_rect); 117 SkPictureImageFilter::Make(ToSkPicture(record, record_bounds));
118 PopulateSourceGraphicImageFilters( 118 PopulateSourceGraphicImageFilters(
119 source_graphic, std::move(filter), 119 source_graphic, std::move(filter),
120 source_graphic->OperatingInterpolationSpace()); 120 source_graphic->OperatingInterpolationSpace());
121 } 121 }
122 122
123 static const float kMaxMaskBufferSize = 123 static const float kMaxMaskBufferSize =
124 50.f * 1024.f * 1024.f / 4.f; // 50MB / 4 bytes per pixel 124 50.f * 1024.f * 1024.f / 4.f; // 50MB / 4 bytes per pixel
125 125
126 sk_sp<SkImageFilter> BuildBoxReflectFilter(const BoxReflection& reflection, 126 sk_sp<SkImageFilter> BuildBoxReflectFilter(const BoxReflection& reflection,
127 sk_sp<SkImageFilter> input) { 127 sk_sp<SkImageFilter> input) {
128 sk_sp<SkImageFilter> masked_input; 128 sk_sp<SkImageFilter> masked_input;
129 if (sk_sp<PaintRecord> mask_record = reflection.Mask()) { 129 if (sk_sp<PaintRecord> mask_record = reflection.Mask()) {
130 // Since PaintRecords can't be serialized to the browser process, first 130 // Since PaintRecords can't be serialized to the browser process, first
131 // raster the mask to a bitmap, then encode it in an SkImageSource, which 131 // raster the mask to a bitmap, then encode it in an SkImageSource, which
132 // can be serialized. 132 // can be serialized.
133 SkBitmap bitmap; 133 SkBitmap bitmap;
134 const SkRect cull_rect = mask_record->cullRect(); 134 const SkRect mask_record_bounds = reflection.MaskBounds();
135 if (static_cast<float>(cull_rect.width()) * 135 if (mask_record_bounds.width() * mask_record_bounds.height() <
136 static_cast<float>(cull_rect.height()) <
137 kMaxMaskBufferSize) { 136 kMaxMaskBufferSize) {
138 bitmap.allocPixels( 137 bitmap.allocPixels(SkImageInfo::MakeN32Premul(
139 SkImageInfo::MakeN32Premul(cull_rect.width(), cull_rect.height())); 138 mask_record_bounds.width(), mask_record_bounds.height()));
140 SkiaPaintCanvas canvas(bitmap); 139 SkiaPaintCanvas canvas(bitmap);
141 canvas.clear(SK_ColorTRANSPARENT); 140 canvas.clear(SK_ColorTRANSPARENT);
142 canvas.translate(-cull_rect.x(), -cull_rect.y()); 141 canvas.translate(-mask_record_bounds.x(), -mask_record_bounds.y());
143 canvas.drawPicture(mask_record); 142 canvas.drawPicture(mask_record);
144 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); 143 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
145 144
146 // SkXfermodeImageFilter can choose an excessively large size if the 145 // SkXfermodeImageFilter can choose an excessively large size if the
147 // mask is smaller than the filtered contents (due to overflow). 146 // mask is smaller than the filtered contents (due to overflow).
148 // http://skbug.com/5210 147 // http://skbug.com/5210
149 SkImageFilter::CropRect crop_rect(mask_record->cullRect()); 148 SkImageFilter::CropRect crop_rect(mask_record_bounds);
150 masked_input = SkXfermodeImageFilter::Make( 149 masked_input = SkXfermodeImageFilter::Make(
151 SkBlendMode::kSrcIn, 150 SkBlendMode::kSrcIn,
152 SkOffsetImageFilter::Make(cull_rect.x(), cull_rect.y(), 151 SkOffsetImageFilter::Make(mask_record_bounds.x(),
152 mask_record_bounds.y(),
153 SkImageSource::Make(image)), 153 SkImageSource::Make(image)),
154 input, &crop_rect); 154 input, &crop_rect);
155 } else { 155 } else {
156 // If the buffer is excessively big, give up and make an 156 // If the buffer is excessively big, give up and make an
157 // SkPictureImageFilter anyway, even if it might not render. 157 // SkPictureImageFilter anyway, even if it might not render.
158 SkImageFilter::CropRect crop_rect(mask_record->cullRect()); 158 SkImageFilter::CropRect crop_rect(mask_record_bounds);
159 masked_input = SkXfermodeImageFilter::Make( 159 masked_input = SkXfermodeImageFilter::Make(
160 SkBlendMode::kSrcOver, 160 SkBlendMode::kSrcOver,
161 SkPictureImageFilter::Make(ToSkPicture(std::move(mask_record))), 161 SkPictureImageFilter::Make(
162 ToSkPicture(std::move(mask_record), mask_record_bounds)),
162 input, &crop_rect); 163 input, &crop_rect);
163 } 164 }
164 } else { 165 } else {
165 masked_input = input; 166 masked_input = input;
166 } 167 }
167 sk_sp<SkImageFilter> flip_image_filter = SkImageFilter::MakeMatrixFilter( 168 sk_sp<SkImageFilter> flip_image_filter = SkImageFilter::MakeMatrixFilter(
168 reflection.ReflectionMatrix(), kLow_SkFilterQuality, 169 reflection.ReflectionMatrix(), kLow_SkFilterQuality,
169 std::move(masked_input)); 170 std::move(masked_input));
170 return SkXfermodeImageFilter::Make(SkBlendMode::kSrcOver, 171 return SkXfermodeImageFilter::Make(SkBlendMode::kSrcOver,
171 std::move(flip_image_filter), 172 std::move(flip_image_filter),
172 std::move(input), nullptr); 173 std::move(input), nullptr);
173 } 174 }
174 175
175 } // namespace SkiaImageFilterBuilder 176 } // namespace SkiaImageFilterBuilder
176 } // namespace blink 177 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698