Chromium Code Reviews| 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 "skia/ext/platform_canvas.h" | 10 #include "skia/ext/platform_canvas.h" |
| 11 #include "ui/base/layout.h" | 11 #include "ui/base/layout.h" |
| 12 #include "ui/base/ui_base_switches.h" | 12 #include "ui/base/ui_base_switches.h" |
| 13 #include "ui/gfx/canvas.h" | |
| 14 #include "ui/gfx/image/canvas_image_source.h" | |
| 13 #include "ui/gfx/image/image_skia.h" | 15 #include "ui/gfx/image/image_skia.h" |
| 14 #include "ui/gfx/image/image_skia_rep.h" | 16 #include "ui/gfx/image/image_skia_rep.h" |
| 15 #include "ui/gfx/image/image_skia_source.h" | 17 #include "ui/gfx/image/image_skia_source.h" |
| 16 #include "ui/gfx/insets.h" | 18 #include "ui/gfx/insets.h" |
| 17 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
| 18 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
| 19 #include "ui/gfx/skbitmap_operations.h" | 21 #include "ui/gfx/skbitmap_operations.h" |
| 20 #include "ui/gfx/skia_util.h" | 22 #include "ui/gfx/skia_util.h" |
| 21 | 23 |
| 22 namespace gfx { | 24 namespace gfx { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 } | 84 } |
| 83 | 85 |
| 84 private: | 86 private: |
| 85 const ImageSkia first_; | 87 const ImageSkia first_; |
| 86 const ImageSkia second_; | 88 const ImageSkia second_; |
| 87 double alpha_; | 89 double alpha_; |
| 88 | 90 |
| 89 DISALLOW_COPY_AND_ASSIGN(BlendingImageSource); | 91 DISALLOW_COPY_AND_ASSIGN(BlendingImageSource); |
| 90 }; | 92 }; |
| 91 | 93 |
| 94 class SuperimposedImageSource : public gfx::CanvasImageSource { | |
| 95 public: | |
| 96 SuperimposedImageSource(const gfx::ImageSkia& first, | |
| 97 const gfx::ImageSkia& second) | |
| 98 : gfx::CanvasImageSource(first.size(), false /* is opaque */), | |
| 99 first_(first), | |
| 100 second_(second) { | |
| 101 } | |
| 102 | |
| 103 virtual ~SuperimposedImageSource() {} | |
| 104 | |
| 105 // gfx::CanvasImageSource override. | |
| 106 virtual void Draw(gfx::Canvas* canvas) OVERRIDE { | |
| 107 canvas->DrawImageInt(first_, 0, 0, SkPaint()); | |
|
Jeffrey Yasskin
2012/08/09 21:39:04
There's a DrawImage overload that you don't have t
tbarzic
2012/08/10 06:24:08
Done.
| |
| 108 canvas->DrawImageInt(second_, | |
| 109 (first_.width() - second_.width()) / 2, | |
| 110 (first_.height() - second_.height()) / 2, | |
| 111 SkPaint()); | |
| 112 } | |
| 113 | |
| 114 private: | |
| 115 const gfx::ImageSkia first_; | |
| 116 const gfx::ImageSkia second_; | |
| 117 | |
| 118 DISALLOW_COPY_AND_ASSIGN(SuperimposedImageSource); | |
| 119 }; | |
| 120 | |
| 92 class MaskedImageSource : public gfx::ImageSkiaSource { | 121 class MaskedImageSource : public gfx::ImageSkiaSource { |
| 93 public: | 122 public: |
| 94 MaskedImageSource(const ImageSkia& rgb, const ImageSkia& alpha) | 123 MaskedImageSource(const ImageSkia& rgb, const ImageSkia& alpha) |
| 95 : rgb_(rgb), | 124 : rgb_(rgb), |
| 96 alpha_(alpha) { | 125 alpha_(alpha) { |
| 97 } | 126 } |
| 98 | 127 |
| 99 virtual ~MaskedImageSource() { | 128 virtual ~MaskedImageSource() { |
| 100 } | 129 } |
| 101 | 130 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 } // namespace | 344 } // namespace |
| 316 | 345 |
| 317 // static | 346 // static |
| 318 ImageSkia ImageSkiaOperations::CreateBlendedImage(const ImageSkia& first, | 347 ImageSkia ImageSkiaOperations::CreateBlendedImage(const ImageSkia& first, |
| 319 const ImageSkia& second, | 348 const ImageSkia& second, |
| 320 double alpha) { | 349 double alpha) { |
| 321 return ImageSkia(new BlendingImageSource(first, second, alpha), first.size()); | 350 return ImageSkia(new BlendingImageSource(first, second, alpha), first.size()); |
| 322 } | 351 } |
| 323 | 352 |
| 324 // static | 353 // static |
| 354 ImageSkia ImageSkiaOperations::CreateSuperimposedImage( | |
| 355 const ImageSkia& first, | |
| 356 const ImageSkia& second) { | |
| 357 return ImageSkia(new SuperimposedImageSource(first, second), first.size()); | |
| 358 } | |
| 359 | |
| 360 // static | |
| 325 ImageSkia ImageSkiaOperations::CreateMaskedImage(const ImageSkia& rgb, | 361 ImageSkia ImageSkiaOperations::CreateMaskedImage(const ImageSkia& rgb, |
| 326 const ImageSkia& alpha) { | 362 const ImageSkia& alpha) { |
| 327 return ImageSkia(new MaskedImageSource(rgb, alpha), rgb.size()); | 363 return ImageSkia(new MaskedImageSource(rgb, alpha), rgb.size()); |
| 328 } | 364 } |
| 329 | 365 |
| 330 // static | 366 // static |
| 331 ImageSkia ImageSkiaOperations::CreateTiledImage(const ImageSkia& source, | 367 ImageSkia ImageSkiaOperations::CreateTiledImage(const ImageSkia& source, |
| 332 int src_x, int src_y, | 368 int src_x, int src_y, |
| 333 int dst_w, int dst_h) { | 369 int dst_w, int dst_h) { |
| 334 return ImageSkia(new TiledImageSource(source, src_x, src_y, dst_w, dst_h), | 370 return ImageSkia(new TiledImageSource(source, src_x, src_y, dst_w, dst_h), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 const ImageSkia& source, | 408 const ImageSkia& source, |
| 373 const ShadowValues& shadows) { | 409 const ShadowValues& shadows) { |
| 374 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); | 410 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); |
| 375 gfx::Size shadow_image_size = source.size(); | 411 gfx::Size shadow_image_size = source.size(); |
| 376 shadow_image_size.Enlarge(shadow_padding.width(), | 412 shadow_image_size.Enlarge(shadow_padding.width(), |
| 377 shadow_padding.height()); | 413 shadow_padding.height()); |
| 378 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); | 414 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); |
| 379 } | 415 } |
| 380 | 416 |
| 381 } // namespace gfx | 417 } // namespace gfx |
| OLD | NEW |