OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/gfx/image/image_skia_operations.h" | 5 #include "ui/gfx/image/image_skia_operations.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "skia/ext/image_operations.h" | 9 #include "skia/ext/image_operations.h" |
10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // This class guarantees that two ImageSkiaReps have have the same pixel size. | 47 // This class guarantees that two ImageSkiaReps have have the same pixel size. |
48 class BinaryImageSource : public gfx::ImageSkiaSource { | 48 class BinaryImageSource : public gfx::ImageSkiaSource { |
49 protected: | 49 protected: |
50 BinaryImageSource(const ImageSkia& first, | 50 BinaryImageSource(const ImageSkia& first, |
51 const ImageSkia& second, | 51 const ImageSkia& second, |
52 const char* source_name) | 52 const char* source_name) |
53 : first_(first), | 53 : first_(first), |
54 second_(second), | 54 second_(second), |
55 source_name_(source_name) { | 55 source_name_(source_name) { |
56 } | 56 } |
57 virtual ~BinaryImageSource() { | 57 ~BinaryImageSource() override {} |
58 } | |
59 | 58 |
60 // gfx::ImageSkiaSource overrides: | 59 // gfx::ImageSkiaSource overrides: |
61 virtual ImageSkiaRep GetImageForScale(float scale) override { | 60 ImageSkiaRep GetImageForScale(float scale) override { |
62 ImageSkiaRep first_rep = first_.GetRepresentation(scale); | 61 ImageSkiaRep first_rep = first_.GetRepresentation(scale); |
63 ImageSkiaRep second_rep = second_.GetRepresentation(scale); | 62 ImageSkiaRep second_rep = second_.GetRepresentation(scale); |
64 if (first_rep.pixel_size() != second_rep.pixel_size()) { | 63 if (first_rep.pixel_size() != second_rep.pixel_size()) { |
65 DCHECK_NE(first_rep.scale(), second_rep.scale()); | 64 DCHECK_NE(first_rep.scale(), second_rep.scale()); |
66 if (first_rep.scale() == second_rep.scale()) { | 65 if (first_rep.scale() == second_rep.scale()) { |
67 LOG(ERROR) << "ImageSkiaRep size mismatch in " << source_name_; | 66 LOG(ERROR) << "ImageSkiaRep size mismatch in " << source_name_; |
68 return GetErrorImageRep(first_rep.scale(),first_rep.pixel_size()); | 67 return GetErrorImageRep(first_rep.scale(),first_rep.pixel_size()); |
69 } | 68 } |
70 first_rep = first_.GetRepresentation(1.0f); | 69 first_rep = first_.GetRepresentation(1.0f); |
71 second_rep = second_.GetRepresentation(1.0f); | 70 second_rep = second_.GetRepresentation(1.0f); |
(...skipping 27 matching lines...) Expand all Loading... |
99 | 98 |
100 class BlendingImageSource : public BinaryImageSource { | 99 class BlendingImageSource : public BinaryImageSource { |
101 public: | 100 public: |
102 BlendingImageSource(const ImageSkia& first, | 101 BlendingImageSource(const ImageSkia& first, |
103 const ImageSkia& second, | 102 const ImageSkia& second, |
104 double alpha) | 103 double alpha) |
105 : BinaryImageSource(first, second, "BlendingImageSource"), | 104 : BinaryImageSource(first, second, "BlendingImageSource"), |
106 alpha_(alpha) { | 105 alpha_(alpha) { |
107 } | 106 } |
108 | 107 |
109 virtual ~BlendingImageSource() { | 108 ~BlendingImageSource() override {} |
110 } | |
111 | 109 |
112 // BinaryImageSource overrides: | 110 // BinaryImageSource overrides: |
113 virtual ImageSkiaRep CreateImageSkiaRep( | 111 ImageSkiaRep CreateImageSkiaRep( |
114 const ImageSkiaRep& first_rep, | 112 const ImageSkiaRep& first_rep, |
115 const ImageSkiaRep& second_rep) const override { | 113 const ImageSkiaRep& second_rep) const override { |
116 SkBitmap blended = SkBitmapOperations::CreateBlendedBitmap( | 114 SkBitmap blended = SkBitmapOperations::CreateBlendedBitmap( |
117 first_rep.sk_bitmap(), second_rep.sk_bitmap(), alpha_); | 115 first_rep.sk_bitmap(), second_rep.sk_bitmap(), alpha_); |
118 return ImageSkiaRep(blended, first_rep.scale()); | 116 return ImageSkiaRep(blended, first_rep.scale()); |
119 } | 117 } |
120 | 118 |
121 private: | 119 private: |
122 double alpha_; | 120 double alpha_; |
123 | 121 |
124 DISALLOW_COPY_AND_ASSIGN(BlendingImageSource); | 122 DISALLOW_COPY_AND_ASSIGN(BlendingImageSource); |
125 }; | 123 }; |
126 | 124 |
127 class SuperimposedImageSource : public gfx::CanvasImageSource { | 125 class SuperimposedImageSource : public gfx::CanvasImageSource { |
128 public: | 126 public: |
129 SuperimposedImageSource(const ImageSkia& first, | 127 SuperimposedImageSource(const ImageSkia& first, |
130 const ImageSkia& second) | 128 const ImageSkia& second) |
131 : gfx::CanvasImageSource(first.size(), false /* is opaque */), | 129 : gfx::CanvasImageSource(first.size(), false /* is opaque */), |
132 first_(first), | 130 first_(first), |
133 second_(second) { | 131 second_(second) { |
134 } | 132 } |
135 | 133 |
136 virtual ~SuperimposedImageSource() {} | 134 ~SuperimposedImageSource() override {} |
137 | 135 |
138 // gfx::CanvasImageSource override. | 136 // gfx::CanvasImageSource override. |
139 virtual void Draw(Canvas* canvas) override { | 137 void Draw(Canvas* canvas) override { |
140 canvas->DrawImageInt(first_, 0, 0); | 138 canvas->DrawImageInt(first_, 0, 0); |
141 canvas->DrawImageInt(second_, | 139 canvas->DrawImageInt(second_, |
142 (first_.width() - second_.width()) / 2, | 140 (first_.width() - second_.width()) / 2, |
143 (first_.height() - second_.height()) / 2); | 141 (first_.height() - second_.height()) / 2); |
144 } | 142 } |
145 | 143 |
146 private: | 144 private: |
147 const ImageSkia first_; | 145 const ImageSkia first_; |
148 const ImageSkia second_; | 146 const ImageSkia second_; |
149 | 147 |
150 DISALLOW_COPY_AND_ASSIGN(SuperimposedImageSource); | 148 DISALLOW_COPY_AND_ASSIGN(SuperimposedImageSource); |
151 }; | 149 }; |
152 | 150 |
153 class TransparentImageSource : public gfx::ImageSkiaSource { | 151 class TransparentImageSource : public gfx::ImageSkiaSource { |
154 public: | 152 public: |
155 TransparentImageSource(const ImageSkia& image, double alpha) | 153 TransparentImageSource(const ImageSkia& image, double alpha) |
156 : image_(image), | 154 : image_(image), |
157 alpha_(alpha) { | 155 alpha_(alpha) { |
158 } | 156 } |
159 | 157 |
160 virtual ~TransparentImageSource() {} | 158 ~TransparentImageSource() override {} |
161 | 159 |
162 private: | 160 private: |
163 // gfx::ImageSkiaSource overrides: | 161 // gfx::ImageSkiaSource overrides: |
164 virtual ImageSkiaRep GetImageForScale(float scale) override { | 162 ImageSkiaRep GetImageForScale(float scale) override { |
165 ImageSkiaRep image_rep = image_.GetRepresentation(scale); | 163 ImageSkiaRep image_rep = image_.GetRepresentation(scale); |
166 SkBitmap alpha; | 164 SkBitmap alpha; |
167 alpha.allocN32Pixels(image_rep.pixel_width(), | 165 alpha.allocN32Pixels(image_rep.pixel_width(), |
168 image_rep.pixel_height()); | 166 image_rep.pixel_height()); |
169 alpha.eraseColor(SkColorSetARGB(alpha_ * 255, 0, 0, 0)); | 167 alpha.eraseColor(SkColorSetARGB(alpha_ * 255, 0, 0, 0)); |
170 return ImageSkiaRep( | 168 return ImageSkiaRep( |
171 SkBitmapOperations::CreateMaskedBitmap(image_rep.sk_bitmap(), alpha), | 169 SkBitmapOperations::CreateMaskedBitmap(image_rep.sk_bitmap(), alpha), |
172 image_rep.scale()); | 170 image_rep.scale()); |
173 } | 171 } |
174 | 172 |
175 ImageSkia image_; | 173 ImageSkia image_; |
176 double alpha_; | 174 double alpha_; |
177 | 175 |
178 DISALLOW_COPY_AND_ASSIGN(TransparentImageSource); | 176 DISALLOW_COPY_AND_ASSIGN(TransparentImageSource); |
179 }; | 177 }; |
180 | 178 |
181 class MaskedImageSource : public BinaryImageSource { | 179 class MaskedImageSource : public BinaryImageSource { |
182 public: | 180 public: |
183 MaskedImageSource(const ImageSkia& rgb, const ImageSkia& alpha) | 181 MaskedImageSource(const ImageSkia& rgb, const ImageSkia& alpha) |
184 : BinaryImageSource(rgb, alpha, "MaskedImageSource") { | 182 : BinaryImageSource(rgb, alpha, "MaskedImageSource") { |
185 } | 183 } |
186 | 184 |
187 virtual ~MaskedImageSource() { | 185 ~MaskedImageSource() override {} |
188 } | |
189 | 186 |
190 // BinaryImageSource overrides: | 187 // BinaryImageSource overrides: |
191 virtual ImageSkiaRep CreateImageSkiaRep( | 188 ImageSkiaRep CreateImageSkiaRep( |
192 const ImageSkiaRep& first_rep, | 189 const ImageSkiaRep& first_rep, |
193 const ImageSkiaRep& second_rep) const override { | 190 const ImageSkiaRep& second_rep) const override { |
194 return ImageSkiaRep(SkBitmapOperations::CreateMaskedBitmap( | 191 return ImageSkiaRep(SkBitmapOperations::CreateMaskedBitmap( |
195 first_rep.sk_bitmap(), second_rep.sk_bitmap()), | 192 first_rep.sk_bitmap(), second_rep.sk_bitmap()), |
196 first_rep.scale()); | 193 first_rep.scale()); |
197 } | 194 } |
198 | 195 |
199 private: | 196 private: |
200 DISALLOW_COPY_AND_ASSIGN(MaskedImageSource); | 197 DISALLOW_COPY_AND_ASSIGN(MaskedImageSource); |
201 }; | 198 }; |
202 | 199 |
203 class TiledImageSource : public gfx::ImageSkiaSource { | 200 class TiledImageSource : public gfx::ImageSkiaSource { |
204 public: | 201 public: |
205 TiledImageSource(const ImageSkia& source, | 202 TiledImageSource(const ImageSkia& source, |
206 int src_x, int src_y, | 203 int src_x, int src_y, |
207 int dst_w, int dst_h) | 204 int dst_w, int dst_h) |
208 : source_(source), | 205 : source_(source), |
209 src_x_(src_x), | 206 src_x_(src_x), |
210 src_y_(src_y), | 207 src_y_(src_y), |
211 dst_w_(dst_w), | 208 dst_w_(dst_w), |
212 dst_h_(dst_h) { | 209 dst_h_(dst_h) { |
213 } | 210 } |
214 | 211 |
215 virtual ~TiledImageSource() { | 212 ~TiledImageSource() override {} |
216 } | |
217 | 213 |
218 // gfx::ImageSkiaSource overrides: | 214 // gfx::ImageSkiaSource overrides: |
219 virtual ImageSkiaRep GetImageForScale(float scale) override { | 215 ImageSkiaRep GetImageForScale(float scale) override { |
220 ImageSkiaRep source_rep = source_.GetRepresentation(scale); | 216 ImageSkiaRep source_rep = source_.GetRepresentation(scale); |
221 gfx::Rect bounds = DIPToPixelBounds(gfx::Rect(src_x_, src_y_, dst_w_, | 217 gfx::Rect bounds = DIPToPixelBounds(gfx::Rect(src_x_, src_y_, dst_w_, |
222 dst_h_), source_rep.scale()); | 218 dst_h_), source_rep.scale()); |
223 return ImageSkiaRep( | 219 return ImageSkiaRep( |
224 SkBitmapOperations::CreateTiledBitmap( | 220 SkBitmapOperations::CreateTiledBitmap( |
225 source_rep.sk_bitmap(), | 221 source_rep.sk_bitmap(), |
226 bounds.x(), bounds.y(), bounds.width(), bounds.height()), | 222 bounds.x(), bounds.y(), bounds.width(), bounds.height()), |
227 source_rep.scale()); | 223 source_rep.scale()); |
228 } | 224 } |
229 | 225 |
230 private: | 226 private: |
231 const ImageSkia source_; | 227 const ImageSkia source_; |
232 const int src_x_; | 228 const int src_x_; |
233 const int src_y_; | 229 const int src_y_; |
234 const int dst_w_; | 230 const int dst_w_; |
235 const int dst_h_; | 231 const int dst_h_; |
236 | 232 |
237 DISALLOW_COPY_AND_ASSIGN(TiledImageSource); | 233 DISALLOW_COPY_AND_ASSIGN(TiledImageSource); |
238 }; | 234 }; |
239 | 235 |
240 class HSLImageSource : public gfx::ImageSkiaSource { | 236 class HSLImageSource : public gfx::ImageSkiaSource { |
241 public: | 237 public: |
242 HSLImageSource(const ImageSkia& image, | 238 HSLImageSource(const ImageSkia& image, |
243 const color_utils::HSL& hsl_shift) | 239 const color_utils::HSL& hsl_shift) |
244 : image_(image), | 240 : image_(image), |
245 hsl_shift_(hsl_shift) { | 241 hsl_shift_(hsl_shift) { |
246 } | 242 } |
247 | 243 |
248 virtual ~HSLImageSource() { | 244 ~HSLImageSource() override {} |
249 } | |
250 | 245 |
251 // gfx::ImageSkiaSource overrides: | 246 // gfx::ImageSkiaSource overrides: |
252 virtual ImageSkiaRep GetImageForScale(float scale) override { | 247 ImageSkiaRep GetImageForScale(float scale) override { |
253 ImageSkiaRep image_rep = image_.GetRepresentation(scale); | 248 ImageSkiaRep image_rep = image_.GetRepresentation(scale); |
254 return gfx::ImageSkiaRep( | 249 return gfx::ImageSkiaRep( |
255 SkBitmapOperations::CreateHSLShiftedBitmap(image_rep.sk_bitmap(), | 250 SkBitmapOperations::CreateHSLShiftedBitmap(image_rep.sk_bitmap(), |
256 hsl_shift_), image_rep.scale()); | 251 hsl_shift_), image_rep.scale()); |
257 } | 252 } |
258 | 253 |
259 private: | 254 private: |
260 const gfx::ImageSkia image_; | 255 const gfx::ImageSkia image_; |
261 const color_utils::HSL hsl_shift_; | 256 const color_utils::HSL hsl_shift_; |
262 DISALLOW_COPY_AND_ASSIGN(HSLImageSource); | 257 DISALLOW_COPY_AND_ASSIGN(HSLImageSource); |
263 }; | 258 }; |
264 | 259 |
265 // ImageSkiaSource which uses SkBitmapOperations::CreateButtonBackground | 260 // ImageSkiaSource which uses SkBitmapOperations::CreateButtonBackground |
266 // to generate image reps for the target image. The image and mask can be | 261 // to generate image reps for the target image. The image and mask can be |
267 // diferent sizes (crbug.com/171725). | 262 // diferent sizes (crbug.com/171725). |
268 class ButtonImageSource: public gfx::ImageSkiaSource { | 263 class ButtonImageSource: public gfx::ImageSkiaSource { |
269 public: | 264 public: |
270 ButtonImageSource(SkColor color, | 265 ButtonImageSource(SkColor color, |
271 const ImageSkia& image, | 266 const ImageSkia& image, |
272 const ImageSkia& mask) | 267 const ImageSkia& mask) |
273 : color_(color), | 268 : color_(color), |
274 image_(image), | 269 image_(image), |
275 mask_(mask) { | 270 mask_(mask) { |
276 } | 271 } |
277 | 272 |
278 virtual ~ButtonImageSource() { | 273 ~ButtonImageSource() override {} |
279 } | |
280 | 274 |
281 // gfx::ImageSkiaSource overrides: | 275 // gfx::ImageSkiaSource overrides: |
282 virtual ImageSkiaRep GetImageForScale(float scale) override { | 276 ImageSkiaRep GetImageForScale(float scale) override { |
283 ImageSkiaRep image_rep = image_.GetRepresentation(scale); | 277 ImageSkiaRep image_rep = image_.GetRepresentation(scale); |
284 ImageSkiaRep mask_rep = mask_.GetRepresentation(scale); | 278 ImageSkiaRep mask_rep = mask_.GetRepresentation(scale); |
285 if (image_rep.scale() != mask_rep.scale()) { | 279 if (image_rep.scale() != mask_rep.scale()) { |
286 image_rep = image_.GetRepresentation(1.0f); | 280 image_rep = image_.GetRepresentation(1.0f); |
287 mask_rep = mask_.GetRepresentation(1.0f); | 281 mask_rep = mask_.GetRepresentation(1.0f); |
288 } | 282 } |
289 return gfx::ImageSkiaRep( | 283 return gfx::ImageSkiaRep( |
290 SkBitmapOperations::CreateButtonBackground(color_, | 284 SkBitmapOperations::CreateButtonBackground(color_, |
291 image_rep.sk_bitmap(), mask_rep.sk_bitmap()), | 285 image_rep.sk_bitmap(), mask_rep.sk_bitmap()), |
292 image_rep.scale()); | 286 image_rep.scale()); |
(...skipping 10 matching lines...) Expand all Loading... |
303 // ImageSkiaSource which uses SkBitmap::extractSubset to generate image reps | 297 // ImageSkiaSource which uses SkBitmap::extractSubset to generate image reps |
304 // for the target image. | 298 // for the target image. |
305 class ExtractSubsetImageSource: public gfx::ImageSkiaSource { | 299 class ExtractSubsetImageSource: public gfx::ImageSkiaSource { |
306 public: | 300 public: |
307 ExtractSubsetImageSource(const gfx::ImageSkia& image, | 301 ExtractSubsetImageSource(const gfx::ImageSkia& image, |
308 const gfx::Rect& subset_bounds) | 302 const gfx::Rect& subset_bounds) |
309 : image_(image), | 303 : image_(image), |
310 subset_bounds_(subset_bounds) { | 304 subset_bounds_(subset_bounds) { |
311 } | 305 } |
312 | 306 |
313 virtual ~ExtractSubsetImageSource() { | 307 ~ExtractSubsetImageSource() override {} |
314 } | |
315 | 308 |
316 // gfx::ImageSkiaSource overrides: | 309 // gfx::ImageSkiaSource overrides: |
317 virtual ImageSkiaRep GetImageForScale(float scale) override { | 310 ImageSkiaRep GetImageForScale(float scale) override { |
318 ImageSkiaRep image_rep = image_.GetRepresentation(scale); | 311 ImageSkiaRep image_rep = image_.GetRepresentation(scale); |
319 SkIRect subset_bounds_in_pixel = RectToSkIRect( | 312 SkIRect subset_bounds_in_pixel = RectToSkIRect( |
320 DIPToPixelBounds(subset_bounds_, image_rep.scale())); | 313 DIPToPixelBounds(subset_bounds_, image_rep.scale())); |
321 SkBitmap dst; | 314 SkBitmap dst; |
322 bool success = image_rep.sk_bitmap().extractSubset(&dst, | 315 bool success = image_rep.sk_bitmap().extractSubset(&dst, |
323 subset_bounds_in_pixel); | 316 subset_bounds_in_pixel); |
324 DCHECK(success); | 317 DCHECK(success); |
325 return gfx::ImageSkiaRep(dst, image_rep.scale()); | 318 return gfx::ImageSkiaRep(dst, image_rep.scale()); |
326 } | 319 } |
327 | 320 |
328 private: | 321 private: |
329 const gfx::ImageSkia image_; | 322 const gfx::ImageSkia image_; |
330 const gfx::Rect subset_bounds_; | 323 const gfx::Rect subset_bounds_; |
331 | 324 |
332 DISALLOW_COPY_AND_ASSIGN(ExtractSubsetImageSource); | 325 DISALLOW_COPY_AND_ASSIGN(ExtractSubsetImageSource); |
333 }; | 326 }; |
334 | 327 |
335 // ResizeSource resizes relevant image reps in |source| to |target_dip_size| | 328 // ResizeSource resizes relevant image reps in |source| to |target_dip_size| |
336 // for requested scale factors. | 329 // for requested scale factors. |
337 class ResizeSource : public ImageSkiaSource { | 330 class ResizeSource : public ImageSkiaSource { |
338 public: | 331 public: |
339 ResizeSource(const ImageSkia& source, | 332 ResizeSource(const ImageSkia& source, |
340 skia::ImageOperations::ResizeMethod method, | 333 skia::ImageOperations::ResizeMethod method, |
341 const Size& target_dip_size) | 334 const Size& target_dip_size) |
342 : source_(source), | 335 : source_(source), |
343 resize_method_(method), | 336 resize_method_(method), |
344 target_dip_size_(target_dip_size) { | 337 target_dip_size_(target_dip_size) { |
345 } | 338 } |
346 virtual ~ResizeSource() {} | 339 ~ResizeSource() override {} |
347 | 340 |
348 // gfx::ImageSkiaSource overrides: | 341 // gfx::ImageSkiaSource overrides: |
349 virtual ImageSkiaRep GetImageForScale(float scale) override { | 342 ImageSkiaRep GetImageForScale(float scale) override { |
350 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); | 343 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); |
351 if (image_rep.GetWidth() == target_dip_size_.width() && | 344 if (image_rep.GetWidth() == target_dip_size_.width() && |
352 image_rep.GetHeight() == target_dip_size_.height()) | 345 image_rep.GetHeight() == target_dip_size_.height()) |
353 return image_rep; | 346 return image_rep; |
354 | 347 |
355 const Size target_pixel_size = DIPToPixelSize(target_dip_size_, scale); | 348 const Size target_pixel_size = DIPToPixelSize(target_dip_size_, scale); |
356 const SkBitmap resized = skia::ImageOperations::Resize( | 349 const SkBitmap resized = skia::ImageOperations::Resize( |
357 image_rep.sk_bitmap(), | 350 image_rep.sk_bitmap(), |
358 resize_method_, | 351 resize_method_, |
359 target_pixel_size.width(), | 352 target_pixel_size.width(), |
(...skipping 11 matching lines...) Expand all Loading... |
371 | 364 |
372 // DropShadowSource generates image reps with drop shadow for image reps in | 365 // DropShadowSource generates image reps with drop shadow for image reps in |
373 // |source| that represent requested scale factors. | 366 // |source| that represent requested scale factors. |
374 class DropShadowSource : public ImageSkiaSource { | 367 class DropShadowSource : public ImageSkiaSource { |
375 public: | 368 public: |
376 DropShadowSource(const ImageSkia& source, | 369 DropShadowSource(const ImageSkia& source, |
377 const ShadowValues& shadows_in_dip) | 370 const ShadowValues& shadows_in_dip) |
378 : source_(source), | 371 : source_(source), |
379 shaodws_in_dip_(shadows_in_dip) { | 372 shaodws_in_dip_(shadows_in_dip) { |
380 } | 373 } |
381 virtual ~DropShadowSource() {} | 374 ~DropShadowSource() override {} |
382 | 375 |
383 // gfx::ImageSkiaSource overrides: | 376 // gfx::ImageSkiaSource overrides: |
384 virtual ImageSkiaRep GetImageForScale(float scale) override { | 377 ImageSkiaRep GetImageForScale(float scale) override { |
385 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); | 378 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); |
386 | 379 |
387 ShadowValues shadows_in_pixel; | 380 ShadowValues shadows_in_pixel; |
388 for (size_t i = 0; i < shaodws_in_dip_.size(); ++i) | 381 for (size_t i = 0; i < shaodws_in_dip_.size(); ++i) |
389 shadows_in_pixel.push_back(shaodws_in_dip_[i].Scale(scale)); | 382 shadows_in_pixel.push_back(shaodws_in_dip_[i].Scale(scale)); |
390 | 383 |
391 const SkBitmap shadow_bitmap = SkBitmapOperations::CreateDropShadow( | 384 const SkBitmap shadow_bitmap = SkBitmapOperations::CreateDropShadow( |
392 image_rep.sk_bitmap(), | 385 image_rep.sk_bitmap(), |
393 shadows_in_pixel); | 386 shadows_in_pixel); |
394 return ImageSkiaRep(shadow_bitmap, image_rep.scale()); | 387 return ImageSkiaRep(shadow_bitmap, image_rep.scale()); |
395 } | 388 } |
396 | 389 |
397 private: | 390 private: |
398 const ImageSkia source_; | 391 const ImageSkia source_; |
399 const ShadowValues shaodws_in_dip_; | 392 const ShadowValues shaodws_in_dip_; |
400 | 393 |
401 DISALLOW_COPY_AND_ASSIGN(DropShadowSource); | 394 DISALLOW_COPY_AND_ASSIGN(DropShadowSource); |
402 }; | 395 }; |
403 | 396 |
404 // RotatedSource generates image reps that are rotations of those in | 397 // RotatedSource generates image reps that are rotations of those in |
405 // |source| that represent requested scale factors. | 398 // |source| that represent requested scale factors. |
406 class RotatedSource : public ImageSkiaSource { | 399 class RotatedSource : public ImageSkiaSource { |
407 public: | 400 public: |
408 RotatedSource(const ImageSkia& source, | 401 RotatedSource(const ImageSkia& source, |
409 SkBitmapOperations::RotationAmount rotation) | 402 SkBitmapOperations::RotationAmount rotation) |
410 : source_(source), | 403 : source_(source), |
411 rotation_(rotation) { | 404 rotation_(rotation) { |
412 } | 405 } |
413 virtual ~RotatedSource() {} | 406 ~RotatedSource() override {} |
414 | 407 |
415 // gfx::ImageSkiaSource overrides: | 408 // gfx::ImageSkiaSource overrides: |
416 virtual ImageSkiaRep GetImageForScale(float scale) override { | 409 ImageSkiaRep GetImageForScale(float scale) override { |
417 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); | 410 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); |
418 const SkBitmap rotated_bitmap = | 411 const SkBitmap rotated_bitmap = |
419 SkBitmapOperations::Rotate(image_rep.sk_bitmap(), rotation_); | 412 SkBitmapOperations::Rotate(image_rep.sk_bitmap(), rotation_); |
420 return ImageSkiaRep(rotated_bitmap, image_rep.scale()); | 413 return ImageSkiaRep(rotated_bitmap, image_rep.scale()); |
421 } | 414 } |
422 | 415 |
423 private: | 416 private: |
424 const ImageSkia source_; | 417 const ImageSkia source_; |
425 const SkBitmapOperations::RotationAmount rotation_; | 418 const SkBitmapOperations::RotationAmount rotation_; |
426 | 419 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 return ImageSkia(); | 539 return ImageSkia(); |
547 | 540 |
548 return ImageSkia(new RotatedSource(source, rotation), | 541 return ImageSkia(new RotatedSource(source, rotation), |
549 SkBitmapOperations::ROTATION_180_CW == rotation ? | 542 SkBitmapOperations::ROTATION_180_CW == rotation ? |
550 source.size() : | 543 source.size() : |
551 gfx::Size(source.height(), source.width())); | 544 gfx::Size(source.height(), source.width())); |
552 | 545 |
553 } | 546 } |
554 | 547 |
555 } // namespace gfx | 548 } // namespace gfx |
OLD | NEW |