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" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 : gfx::CanvasImageSource(first.size(), false /* is opaque */), | 98 : gfx::CanvasImageSource(first.size(), false /* is opaque */), |
99 first_(first), | 99 first_(first), |
100 second_(second) { | 100 second_(second) { |
101 } | 101 } |
102 | 102 |
103 virtual ~SuperimposedImageSource() {} | 103 virtual ~SuperimposedImageSource() {} |
104 | 104 |
105 // gfx::CanvasImageSource override. | 105 // gfx::CanvasImageSource override. |
106 virtual void Draw(Canvas* canvas) OVERRIDE { | 106 virtual void Draw(Canvas* canvas) OVERRIDE { |
107 canvas->DrawImageInt(first_, 0, 0); | 107 canvas->DrawImageInt(first_, 0, 0); |
| 108 LOG(ERROR) << second_.width(); |
108 canvas->DrawImageInt(second_, | 109 canvas->DrawImageInt(second_, |
109 (first_.width() - second_.width()) / 2, | 110 (first_.width() - second_.width()) / 2, |
110 (first_.height() - second_.height()) / 2); | 111 (first_.height() - second_.height()) / 2); |
111 } | 112 } |
112 | 113 |
113 private: | 114 private: |
114 const ImageSkia first_; | 115 const ImageSkia first_; |
115 const ImageSkia second_; | 116 const ImageSkia second_; |
116 | 117 |
117 DISALLOW_COPY_AND_ASSIGN(SuperimposedImageSource); | 118 DISALLOW_COPY_AND_ASSIGN(SuperimposedImageSource); |
118 }; | 119 }; |
119 | 120 |
120 class TransparentImageSource : public gfx::ImageSkiaSource { | 121 class TransparentImageSource : public gfx::ImageSkiaSource { |
121 public: | 122 public: |
122 TransparentImageSource(const ImageSkia& image, double alpha) | 123 TransparentImageSource(const ImageSkia& image, double alpha) |
123 : image_(image), | 124 : image_(image), |
124 alpha_(alpha) { | 125 alpha_(alpha) { |
125 } | 126 } |
126 | 127 |
127 virtual ~TransparentImageSource() {} | 128 virtual ~TransparentImageSource() {} |
128 | 129 |
129 private: | 130 private: |
130 // gfx::ImageSkiaSource overrides: | 131 // gfx::ImageSkiaSource overrides: |
131 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 132 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
132 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); | 133 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); |
133 SkBitmap alpha; | 134 SkBitmap alpha; |
134 const float scale = ui::GetScaleFactorScale(image_rep.scale_factor()); | |
135 alpha.setConfig(SkBitmap::kARGB_8888_Config, | 135 alpha.setConfig(SkBitmap::kARGB_8888_Config, |
136 static_cast<int>(image_.size().width() * scale), | 136 static_cast<int>(image_rep.sk_bitmap().width()), |
137 static_cast<int>(image_.size().height() * scale)); | 137 static_cast<int>(image_rep.sk_bitmap().height())); |
138 alpha.allocPixels(); | 138 alpha.allocPixels(); |
139 alpha.eraseColor(SkColorSetARGB(alpha_ * 256, 0, 0, 0)); | 139 alpha.eraseColor(SkColorSetARGB(alpha_ * 256, 0, 0, 0)); |
140 return ImageSkiaRep(SkBitmapOperations::CreateMaskedBitmap( | 140 return ImageSkiaRep( |
141 image_rep.sk_bitmap(), alpha), | 141 SkBitmapOperations::CreateMaskedBitmap(image_rep.sk_bitmap(), alpha), |
142 image_rep.scale_factor()); | 142 image_rep.scale_factor()); |
143 } | 143 } |
144 | 144 |
145 ImageSkia image_; | 145 ImageSkia image_; |
146 double alpha_; | 146 double alpha_; |
147 | 147 |
148 DISALLOW_COPY_AND_ASSIGN(TransparentImageSource); | 148 DISALLOW_COPY_AND_ASSIGN(TransparentImageSource); |
149 }; | 149 }; |
150 | 150 |
151 class MaskedImageSource : public gfx::ImageSkiaSource { | 151 class MaskedImageSource : public gfx::ImageSkiaSource { |
152 public: | 152 public: |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 const ImageSkia& source, | 450 const ImageSkia& source, |
451 const ShadowValues& shadows) { | 451 const ShadowValues& shadows) { |
452 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); | 452 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); |
453 gfx::Size shadow_image_size = source.size(); | 453 gfx::Size shadow_image_size = source.size(); |
454 shadow_image_size.Enlarge(shadow_padding.width(), | 454 shadow_image_size.Enlarge(shadow_padding.width(), |
455 shadow_padding.height()); | 455 shadow_padding.height()); |
456 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); | 456 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); |
457 } | 457 } |
458 | 458 |
459 } // namespace gfx | 459 } // namespace gfx |
OLD | NEW |