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

Side by Side Diff: ui/gfx/image/image_skia_operations.cc

Issue 10827191: Convert extension action icons code to use ImageSkia instead of SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
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
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 ImageSkia& first,
97 const 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(Canvas* canvas) OVERRIDE {
107 canvas->DrawImageInt(first_, 0, 0);
108 canvas->DrawImageInt(second_,
109 (first_.width() - second_.width()) / 2,
110 (first_.height() - second_.height()) / 2);
111 }
112
113 private:
114 const ImageSkia first_;
115 const ImageSkia second_;
116
117 DISALLOW_COPY_AND_ASSIGN(SuperimposedImageSource);
118 };
119
120 class TransparentImageSource : public gfx::ImageSkiaSource {
121 public:
122 TransparentImageSource(const ImageSkia& image, double alpha)
123 : image_(image),
124 alpha_(alpha) {
125 }
126
127 virtual ~TransparentImageSource() {}
128
129 private:
130 // gfx::ImageSkiaSource overrides:
131 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
132 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor);
133 SkBitmap alpha;
134 const float scale = ui::GetScaleFactorScale(image_rep.scale_factor());
135 alpha.setConfig(SkBitmap::kARGB_8888_Config,
136 static_cast<int>(image_.size().width() * scale),
137 static_cast<int>(image_.size().height() * scale));
138 alpha.allocPixels();
139 alpha.eraseColor(SkColorSetARGB(alpha_ * 256, 0, 0, 0));
140 return ImageSkiaRep(SkBitmapOperations::CreateMaskedBitmap(
141 image_rep.sk_bitmap(), alpha),
142 image_rep.scale_factor());
143 }
144
145 ImageSkia image_;
146 double alpha_;
147
148 DISALLOW_COPY_AND_ASSIGN(TransparentImageSource);
149 };
150
92 class MaskedImageSource : public gfx::ImageSkiaSource { 151 class MaskedImageSource : public gfx::ImageSkiaSource {
93 public: 152 public:
94 MaskedImageSource(const ImageSkia& rgb, const ImageSkia& alpha) 153 MaskedImageSource(const ImageSkia& rgb, const ImageSkia& alpha)
95 : rgb_(rgb), 154 : rgb_(rgb),
96 alpha_(alpha) { 155 alpha_(alpha) {
97 } 156 }
98 157
99 virtual ~MaskedImageSource() { 158 virtual ~MaskedImageSource() {
100 } 159 }
101 160
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } // namespace 374 } // namespace
316 375
317 // static 376 // static
318 ImageSkia ImageSkiaOperations::CreateBlendedImage(const ImageSkia& first, 377 ImageSkia ImageSkiaOperations::CreateBlendedImage(const ImageSkia& first,
319 const ImageSkia& second, 378 const ImageSkia& second,
320 double alpha) { 379 double alpha) {
321 return ImageSkia(new BlendingImageSource(first, second, alpha), first.size()); 380 return ImageSkia(new BlendingImageSource(first, second, alpha), first.size());
322 } 381 }
323 382
324 // static 383 // static
384 ImageSkia ImageSkiaOperations::CreateSuperimposedImage(
385 const ImageSkia& first,
386 const ImageSkia& second) {
387 return ImageSkia(new SuperimposedImageSource(first, second), first.size());
388 }
389
390 // static
391 ImageSkia ImageSkiaOperations::CreateTransparentImage(const ImageSkia& image,
392 double alpha) {
393 return ImageSkia(new TransparentImageSource(image, alpha), image.size());
394 }
395
396 // static
325 ImageSkia ImageSkiaOperations::CreateMaskedImage(const ImageSkia& rgb, 397 ImageSkia ImageSkiaOperations::CreateMaskedImage(const ImageSkia& rgb,
326 const ImageSkia& alpha) { 398 const ImageSkia& alpha) {
327 return ImageSkia(new MaskedImageSource(rgb, alpha), rgb.size()); 399 return ImageSkia(new MaskedImageSource(rgb, alpha), rgb.size());
328 } 400 }
329 401
330 // static 402 // static
331 ImageSkia ImageSkiaOperations::CreateTiledImage(const ImageSkia& source, 403 ImageSkia ImageSkiaOperations::CreateTiledImage(const ImageSkia& source,
332 int src_x, int src_y, 404 int src_x, int src_y,
333 int dst_w, int dst_h) { 405 int dst_w, int dst_h) {
334 return ImageSkia(new TiledImageSource(source, src_x, src_y, dst_w, dst_h), 406 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
372 const ImageSkia& source, 444 const ImageSkia& source,
373 const ShadowValues& shadows) { 445 const ShadowValues& shadows) {
374 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); 446 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows);
375 gfx::Size shadow_image_size = source.size(); 447 gfx::Size shadow_image_size = source.size();
376 shadow_image_size.Enlarge(shadow_padding.width(), 448 shadow_image_size.Enlarge(shadow_padding.width(),
377 shadow_padding.height()); 449 shadow_padding.height());
378 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); 450 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size);
379 } 451 }
380 452
381 } // namespace gfx 453 } // namespace gfx
OLDNEW
« chrome/common/extensions/extension_action.cc ('K') | « ui/gfx/image/image_skia_operations.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698