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 20 matching lines...) Expand all Loading... |
31 | 31 |
32 gfx::Rect DIPToPixelBounds(gfx::Rect dip_bounds, float scale) { | 32 gfx::Rect DIPToPixelBounds(gfx::Rect dip_bounds, float scale) { |
33 return gfx::Rect(ToFlooredPoint(ScalePoint(dip_bounds.origin(), scale)), | 33 return gfx::Rect(ToFlooredPoint(ScalePoint(dip_bounds.origin(), scale)), |
34 DIPToPixelSize(dip_bounds.size(), scale)); | 34 DIPToPixelSize(dip_bounds.size(), scale)); |
35 } | 35 } |
36 | 36 |
37 // Returns an image rep for the ImageSkiaSource to return to visually indicate | 37 // Returns an image rep for the ImageSkiaSource to return to visually indicate |
38 // an error. | 38 // an error. |
39 ImageSkiaRep GetErrorImageRep(float scale, const gfx::Size& pixel_size) { | 39 ImageSkiaRep GetErrorImageRep(float scale, const gfx::Size& pixel_size) { |
40 SkBitmap bitmap; | 40 SkBitmap bitmap; |
41 bitmap.setConfig( | 41 bitmap.allocN32Pixels(pixel_size.width(), pixel_size.height()); |
42 SkBitmap::kARGB_8888_Config, pixel_size.width(), pixel_size.height()); | |
43 bitmap.allocPixels(); | |
44 bitmap.eraseColor(SK_ColorRED); | 42 bitmap.eraseColor(SK_ColorRED); |
45 return gfx::ImageSkiaRep(bitmap, scale); | 43 return gfx::ImageSkiaRep(bitmap, scale); |
46 } | 44 } |
47 | 45 |
48 // A base image source class that creates an image from two source images. | 46 // A base image source class that creates an image from two source images. |
49 // 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. |
50 class BinaryImageSource : public gfx::ImageSkiaSource { | 48 class BinaryImageSource : public gfx::ImageSkiaSource { |
51 protected: | 49 protected: |
52 BinaryImageSource(const ImageSkia& first, | 50 BinaryImageSource(const ImageSkia& first, |
53 const ImageSkia& second, | 51 const ImageSkia& second, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 alpha_(alpha) { | 157 alpha_(alpha) { |
160 } | 158 } |
161 | 159 |
162 virtual ~TransparentImageSource() {} | 160 virtual ~TransparentImageSource() {} |
163 | 161 |
164 private: | 162 private: |
165 // gfx::ImageSkiaSource overrides: | 163 // gfx::ImageSkiaSource overrides: |
166 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 164 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
167 ImageSkiaRep image_rep = image_.GetRepresentation(scale); | 165 ImageSkiaRep image_rep = image_.GetRepresentation(scale); |
168 SkBitmap alpha; | 166 SkBitmap alpha; |
169 alpha.setConfig(SkBitmap::kARGB_8888_Config, | 167 alpha.allocN32Pixels(image_rep.pixel_width(), |
170 image_rep.pixel_width(), | 168 image_rep.pixel_height()); |
171 image_rep.pixel_height()); | |
172 alpha.allocPixels(); | |
173 alpha.eraseColor(SkColorSetARGB(alpha_ * 255, 0, 0, 0)); | 169 alpha.eraseColor(SkColorSetARGB(alpha_ * 255, 0, 0, 0)); |
174 return ImageSkiaRep( | 170 return ImageSkiaRep( |
175 SkBitmapOperations::CreateMaskedBitmap(image_rep.sk_bitmap(), alpha), | 171 SkBitmapOperations::CreateMaskedBitmap(image_rep.sk_bitmap(), alpha), |
176 image_rep.scale()); | 172 image_rep.scale()); |
177 } | 173 } |
178 | 174 |
179 ImageSkia image_; | 175 ImageSkia image_; |
180 double alpha_; | 176 double alpha_; |
181 | 177 |
182 DISALLOW_COPY_AND_ASSIGN(TransparentImageSource); | 178 DISALLOW_COPY_AND_ASSIGN(TransparentImageSource); |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 return ImageSkia(); | 546 return ImageSkia(); |
551 | 547 |
552 return ImageSkia(new RotatedSource(source, rotation), | 548 return ImageSkia(new RotatedSource(source, rotation), |
553 SkBitmapOperations::ROTATION_180_CW == rotation ? | 549 SkBitmapOperations::ROTATION_180_CW == rotation ? |
554 source.size() : | 550 source.size() : |
555 gfx::Size(source.height(), source.width())); | 551 gfx::Size(source.height(), source.width())); |
556 | 552 |
557 } | 553 } |
558 | 554 |
559 } // namespace gfx | 555 } // namespace gfx |
OLD | NEW |