| 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/base/layout.h" | |
| 11 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/image/canvas_image_source.h" | 11 #include "ui/gfx/image/canvas_image_source.h" |
| 13 #include "ui/gfx/image/image_skia.h" | 12 #include "ui/gfx/image/image_skia.h" |
| 14 #include "ui/gfx/image/image_skia_rep.h" | 13 #include "ui/gfx/image/image_skia_rep.h" |
| 15 #include "ui/gfx/image/image_skia_source.h" | 14 #include "ui/gfx/image/image_skia_source.h" |
| 16 #include "ui/gfx/insets.h" | 15 #include "ui/gfx/insets.h" |
| 17 #include "ui/gfx/point.h" | 16 #include "ui/gfx/point.h" |
| 18 #include "ui/gfx/point_conversions.h" | 17 #include "ui/gfx/point_conversions.h" |
| 19 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
| 20 #include "ui/gfx/rect_conversions.h" | 19 #include "ui/gfx/rect_conversions.h" |
| 21 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
| 22 #include "ui/gfx/size_conversions.h" | 21 #include "ui/gfx/size_conversions.h" |
| 23 #include "ui/gfx/skbitmap_operations.h" | 22 #include "ui/gfx/skbitmap_operations.h" |
| 24 #include "ui/gfx/skia_util.h" | 23 #include "ui/gfx/skia_util.h" |
| 25 | 24 |
| 26 namespace gfx { | 25 namespace gfx { |
| 27 namespace { | 26 namespace { |
| 28 | 27 |
| 29 gfx::Size DIPToPixelSize(gfx::Size dip_size, float scale) { | 28 gfx::Size DIPToPixelSize(gfx::Size dip_size, float scale) { |
| 30 return ToCeiledSize(ScaleSize(dip_size, scale)); | 29 return ToCeiledSize(ScaleSize(dip_size, scale)); |
| 31 } | 30 } |
| 32 | 31 |
| 33 gfx::Rect DIPToPixelBounds(gfx::Rect dip_bounds, float scale) { | 32 gfx::Rect DIPToPixelBounds(gfx::Rect dip_bounds, float scale) { |
| 34 return gfx::Rect(ToFlooredPoint(ScalePoint(dip_bounds.origin(), scale)), | 33 return gfx::Rect(ToFlooredPoint(ScalePoint(dip_bounds.origin(), scale)), |
| 35 DIPToPixelSize(dip_bounds.size(), scale)); | 34 DIPToPixelSize(dip_bounds.size(), scale)); |
| 36 } | 35 } |
| 37 | 36 |
| 38 // 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 |
| 39 // an error. | 38 // an error. |
| 40 ImageSkiaRep GetErrorImageRep(ui::ScaleFactor scale_factor, | 39 ImageSkiaRep GetErrorImageRep(float scale, const gfx::Size& pixel_size) { |
| 41 const gfx::Size& pixel_size) { | |
| 42 SkBitmap bitmap; | 40 SkBitmap bitmap; |
| 43 bitmap.setConfig( | 41 bitmap.setConfig( |
| 44 SkBitmap::kARGB_8888_Config, pixel_size.width(), pixel_size.height()); | 42 SkBitmap::kARGB_8888_Config, pixel_size.width(), pixel_size.height()); |
| 45 bitmap.allocPixels(); | 43 bitmap.allocPixels(); |
| 46 bitmap.eraseColor(SK_ColorRED); | 44 bitmap.eraseColor(SK_ColorRED); |
| 47 return gfx::ImageSkiaRep(bitmap, scale_factor); | 45 return gfx::ImageSkiaRep(bitmap, scale); |
| 48 } | 46 } |
| 49 | 47 |
| 50 // A base image source class that creates an image from two source images. | 48 // A base image source class that creates an image from two source images. |
| 51 // This class guarantees that two ImageSkiaReps have have the same pixel size. | 49 // This class guarantees that two ImageSkiaReps have have the same pixel size. |
| 52 class BinaryImageSource : public gfx::ImageSkiaSource { | 50 class BinaryImageSource : public gfx::ImageSkiaSource { |
| 53 protected: | 51 protected: |
| 54 BinaryImageSource(const ImageSkia& first, | 52 BinaryImageSource(const ImageSkia& first, |
| 55 const ImageSkia& second, | 53 const ImageSkia& second, |
| 56 const char* source_name) | 54 const char* source_name) |
| 57 : first_(first), | 55 : first_(first), |
| 58 second_(second), | 56 second_(second), |
| 59 source_name_(source_name) { | 57 source_name_(source_name) { |
| 60 } | 58 } |
| 61 virtual ~BinaryImageSource() { | 59 virtual ~BinaryImageSource() { |
| 62 } | 60 } |
| 63 | 61 |
| 64 // gfx::ImageSkiaSource overrides: | 62 // gfx::ImageSkiaSource overrides: |
| 65 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 63 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
| 66 ImageSkiaRep first_rep = first_.GetRepresentation(scale_factor); | 64 ImageSkiaRep first_rep = first_.GetRepresentation(scale); |
| 67 ImageSkiaRep second_rep = second_.GetRepresentation(scale_factor); | 65 ImageSkiaRep second_rep = second_.GetRepresentation(scale); |
| 68 if (first_rep.pixel_size() != second_rep.pixel_size()) { | 66 if (first_rep.pixel_size() != second_rep.pixel_size()) { |
| 69 DCHECK_NE(first_rep.scale_factor(), second_rep.scale_factor()); | 67 DCHECK_NE(first_rep.scale(), second_rep.scale()); |
| 70 if (first_rep.scale_factor() == second_rep.scale_factor()) { | 68 if (first_rep.scale() == second_rep.scale()) { |
| 71 LOG(ERROR) << "ImageSkiaRep size mismatch in " << source_name_; | 69 LOG(ERROR) << "ImageSkiaRep size mismatch in " << source_name_; |
| 72 return GetErrorImageRep(first_rep.scale_factor(), | 70 return GetErrorImageRep(first_rep.scale(),first_rep.pixel_size()); |
| 73 first_rep.pixel_size()); | |
| 74 } | 71 } |
| 75 first_rep = first_.GetRepresentation(ui::SCALE_FACTOR_100P); | 72 first_rep = first_.GetRepresentation(1.0f); |
| 76 second_rep = second_.GetRepresentation(ui::SCALE_FACTOR_100P); | 73 second_rep = second_.GetRepresentation(1.0f); |
| 77 DCHECK_EQ(first_rep.pixel_width(), second_rep.pixel_width()); | 74 DCHECK_EQ(first_rep.pixel_width(), second_rep.pixel_width()); |
| 78 DCHECK_EQ(first_rep.pixel_height(), second_rep.pixel_height()); | 75 DCHECK_EQ(first_rep.pixel_height(), second_rep.pixel_height()); |
| 79 if (first_rep.pixel_size() != second_rep.pixel_size()) { | 76 if (first_rep.pixel_size() != second_rep.pixel_size()) { |
| 80 LOG(ERROR) << "ImageSkiaRep size mismatch in " << source_name_; | 77 LOG(ERROR) << "ImageSkiaRep size mismatch in " << source_name_; |
| 81 return GetErrorImageRep(first_rep.scale_factor(), | 78 return GetErrorImageRep(first_rep.scale(), first_rep.pixel_size()); |
| 82 first_rep.pixel_size()); | |
| 83 } | 79 } |
| 84 } else { | 80 } else { |
| 85 DCHECK_EQ(first_rep.scale_factor(), second_rep.scale_factor()); | 81 DCHECK_EQ(first_rep.scale(), second_rep.scale()); |
| 86 } | 82 } |
| 87 return CreateImageSkiaRep(first_rep, second_rep); | 83 return CreateImageSkiaRep(first_rep, second_rep); |
| 88 } | 84 } |
| 89 | 85 |
| 90 // Creates a final image from two ImageSkiaReps. The pixel size of | 86 // Creates a final image from two ImageSkiaReps. The pixel size of |
| 91 // the two images are guaranteed to be the same. | 87 // the two images are guaranteed to be the same. |
| 92 virtual ImageSkiaRep CreateImageSkiaRep( | 88 virtual ImageSkiaRep CreateImageSkiaRep( |
| 93 const ImageSkiaRep& first_rep, | 89 const ImageSkiaRep& first_rep, |
| 94 const ImageSkiaRep& second_rep) const = 0; | 90 const ImageSkiaRep& second_rep) const = 0; |
| 95 | 91 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 114 | 110 |
| 115 virtual ~BlendingImageSource() { | 111 virtual ~BlendingImageSource() { |
| 116 } | 112 } |
| 117 | 113 |
| 118 // BinaryImageSource overrides: | 114 // BinaryImageSource overrides: |
| 119 virtual ImageSkiaRep CreateImageSkiaRep( | 115 virtual ImageSkiaRep CreateImageSkiaRep( |
| 120 const ImageSkiaRep& first_rep, | 116 const ImageSkiaRep& first_rep, |
| 121 const ImageSkiaRep& second_rep) const OVERRIDE { | 117 const ImageSkiaRep& second_rep) const OVERRIDE { |
| 122 SkBitmap blended = SkBitmapOperations::CreateBlendedBitmap( | 118 SkBitmap blended = SkBitmapOperations::CreateBlendedBitmap( |
| 123 first_rep.sk_bitmap(), second_rep.sk_bitmap(), alpha_); | 119 first_rep.sk_bitmap(), second_rep.sk_bitmap(), alpha_); |
| 124 return ImageSkiaRep(blended, first_rep.scale_factor()); | 120 return ImageSkiaRep(blended, first_rep.scale()); |
| 125 } | 121 } |
| 126 | 122 |
| 127 private: | 123 private: |
| 128 double alpha_; | 124 double alpha_; |
| 129 | 125 |
| 130 DISALLOW_COPY_AND_ASSIGN(BlendingImageSource); | 126 DISALLOW_COPY_AND_ASSIGN(BlendingImageSource); |
| 131 }; | 127 }; |
| 132 | 128 |
| 133 class SuperimposedImageSource : public gfx::CanvasImageSource { | 129 class SuperimposedImageSource : public gfx::CanvasImageSource { |
| 134 public: | 130 public: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 160 public: | 156 public: |
| 161 TransparentImageSource(const ImageSkia& image, double alpha) | 157 TransparentImageSource(const ImageSkia& image, double alpha) |
| 162 : image_(image), | 158 : image_(image), |
| 163 alpha_(alpha) { | 159 alpha_(alpha) { |
| 164 } | 160 } |
| 165 | 161 |
| 166 virtual ~TransparentImageSource() {} | 162 virtual ~TransparentImageSource() {} |
| 167 | 163 |
| 168 private: | 164 private: |
| 169 // gfx::ImageSkiaSource overrides: | 165 // gfx::ImageSkiaSource overrides: |
| 170 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 166 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
| 171 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); | 167 ImageSkiaRep image_rep = image_.GetRepresentation(scale); |
| 172 SkBitmap alpha; | 168 SkBitmap alpha; |
| 173 alpha.setConfig(SkBitmap::kARGB_8888_Config, | 169 alpha.setConfig(SkBitmap::kARGB_8888_Config, |
| 174 image_rep.pixel_width(), | 170 image_rep.pixel_width(), |
| 175 image_rep.pixel_height()); | 171 image_rep.pixel_height()); |
| 176 alpha.allocPixels(); | 172 alpha.allocPixels(); |
| 177 alpha.eraseColor(SkColorSetARGB(alpha_ * 255, 0, 0, 0)); | 173 alpha.eraseColor(SkColorSetARGB(alpha_ * 255, 0, 0, 0)); |
| 178 return ImageSkiaRep( | 174 return ImageSkiaRep( |
| 179 SkBitmapOperations::CreateMaskedBitmap(image_rep.sk_bitmap(), alpha), | 175 SkBitmapOperations::CreateMaskedBitmap(image_rep.sk_bitmap(), alpha), |
| 180 image_rep.scale_factor()); | 176 image_rep.scale()); |
| 181 } | 177 } |
| 182 | 178 |
| 183 ImageSkia image_; | 179 ImageSkia image_; |
| 184 double alpha_; | 180 double alpha_; |
| 185 | 181 |
| 186 DISALLOW_COPY_AND_ASSIGN(TransparentImageSource); | 182 DISALLOW_COPY_AND_ASSIGN(TransparentImageSource); |
| 187 }; | 183 }; |
| 188 | 184 |
| 189 class MaskedImageSource : public BinaryImageSource { | 185 class MaskedImageSource : public BinaryImageSource { |
| 190 public: | 186 public: |
| 191 MaskedImageSource(const ImageSkia& rgb, const ImageSkia& alpha) | 187 MaskedImageSource(const ImageSkia& rgb, const ImageSkia& alpha) |
| 192 : BinaryImageSource(rgb, alpha, "MaskedImageSource") { | 188 : BinaryImageSource(rgb, alpha, "MaskedImageSource") { |
| 193 } | 189 } |
| 194 | 190 |
| 195 virtual ~MaskedImageSource() { | 191 virtual ~MaskedImageSource() { |
| 196 } | 192 } |
| 197 | 193 |
| 198 // BinaryImageSource overrides: | 194 // BinaryImageSource overrides: |
| 199 virtual ImageSkiaRep CreateImageSkiaRep( | 195 virtual ImageSkiaRep CreateImageSkiaRep( |
| 200 const ImageSkiaRep& first_rep, | 196 const ImageSkiaRep& first_rep, |
| 201 const ImageSkiaRep& second_rep) const OVERRIDE { | 197 const ImageSkiaRep& second_rep) const OVERRIDE { |
| 202 return ImageSkiaRep(SkBitmapOperations::CreateMaskedBitmap( | 198 return ImageSkiaRep(SkBitmapOperations::CreateMaskedBitmap( |
| 203 first_rep.sk_bitmap(), second_rep.sk_bitmap()), | 199 first_rep.sk_bitmap(), second_rep.sk_bitmap()), |
| 204 first_rep.scale_factor()); | 200 first_rep.scale()); |
| 205 } | 201 } |
| 206 | 202 |
| 207 private: | 203 private: |
| 208 DISALLOW_COPY_AND_ASSIGN(MaskedImageSource); | 204 DISALLOW_COPY_AND_ASSIGN(MaskedImageSource); |
| 209 }; | 205 }; |
| 210 | 206 |
| 211 class TiledImageSource : public gfx::ImageSkiaSource { | 207 class TiledImageSource : public gfx::ImageSkiaSource { |
| 212 public: | 208 public: |
| 213 TiledImageSource(const ImageSkia& source, | 209 TiledImageSource(const ImageSkia& source, |
| 214 int src_x, int src_y, | 210 int src_x, int src_y, |
| 215 int dst_w, int dst_h) | 211 int dst_w, int dst_h) |
| 216 : source_(source), | 212 : source_(source), |
| 217 src_x_(src_x), | 213 src_x_(src_x), |
| 218 src_y_(src_y), | 214 src_y_(src_y), |
| 219 dst_w_(dst_w), | 215 dst_w_(dst_w), |
| 220 dst_h_(dst_h) { | 216 dst_h_(dst_h) { |
| 221 } | 217 } |
| 222 | 218 |
| 223 virtual ~TiledImageSource() { | 219 virtual ~TiledImageSource() { |
| 224 } | 220 } |
| 225 | 221 |
| 226 // gfx::ImageSkiaSource overrides: | 222 // gfx::ImageSkiaSource overrides: |
| 227 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 223 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
| 228 ImageSkiaRep source_rep = source_.GetRepresentation(scale_factor); | 224 ImageSkiaRep source_rep = source_.GetRepresentation(scale); |
| 229 float scale = ui::GetScaleFactorScale(source_rep.scale_factor()); | |
| 230 gfx::Rect bounds = DIPToPixelBounds(gfx::Rect(src_x_, src_y_, dst_w_, | 225 gfx::Rect bounds = DIPToPixelBounds(gfx::Rect(src_x_, src_y_, dst_w_, |
| 231 dst_h_), scale); | 226 dst_h_), source_rep.scale()); |
| 232 return ImageSkiaRep( | 227 return ImageSkiaRep( |
| 233 SkBitmapOperations::CreateTiledBitmap( | 228 SkBitmapOperations::CreateTiledBitmap( |
| 234 source_rep.sk_bitmap(), | 229 source_rep.sk_bitmap(), |
| 235 bounds.x(), bounds.y(), bounds.width(), bounds.height()), | 230 bounds.x(), bounds.y(), bounds.width(), bounds.height()), |
| 236 source_rep.scale_factor()); | 231 source_rep.scale()); |
| 237 } | 232 } |
| 238 | 233 |
| 239 private: | 234 private: |
| 240 const ImageSkia source_; | 235 const ImageSkia source_; |
| 241 const int src_x_; | 236 const int src_x_; |
| 242 const int src_y_; | 237 const int src_y_; |
| 243 const int dst_w_; | 238 const int dst_w_; |
| 244 const int dst_h_; | 239 const int dst_h_; |
| 245 | 240 |
| 246 DISALLOW_COPY_AND_ASSIGN(TiledImageSource); | 241 DISALLOW_COPY_AND_ASSIGN(TiledImageSource); |
| 247 }; | 242 }; |
| 248 | 243 |
| 249 class HSLImageSource : public gfx::ImageSkiaSource { | 244 class HSLImageSource : public gfx::ImageSkiaSource { |
| 250 public: | 245 public: |
| 251 HSLImageSource(const ImageSkia& image, | 246 HSLImageSource(const ImageSkia& image, |
| 252 const color_utils::HSL& hsl_shift) | 247 const color_utils::HSL& hsl_shift) |
| 253 : image_(image), | 248 : image_(image), |
| 254 hsl_shift_(hsl_shift) { | 249 hsl_shift_(hsl_shift) { |
| 255 } | 250 } |
| 256 | 251 |
| 257 virtual ~HSLImageSource() { | 252 virtual ~HSLImageSource() { |
| 258 } | 253 } |
| 259 | 254 |
| 260 // gfx::ImageSkiaSource overrides: | 255 // gfx::ImageSkiaSource overrides: |
| 261 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 256 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
| 262 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); | 257 ImageSkiaRep image_rep = image_.GetRepresentation(scale); |
| 263 return gfx::ImageSkiaRep( | 258 return gfx::ImageSkiaRep( |
| 264 SkBitmapOperations::CreateHSLShiftedBitmap(image_rep.sk_bitmap(), | 259 SkBitmapOperations::CreateHSLShiftedBitmap(image_rep.sk_bitmap(), |
| 265 hsl_shift_), image_rep.scale_factor()); | 260 hsl_shift_), image_rep.scale()); |
| 266 } | 261 } |
| 267 | 262 |
| 268 private: | 263 private: |
| 269 const gfx::ImageSkia image_; | 264 const gfx::ImageSkia image_; |
| 270 const color_utils::HSL hsl_shift_; | 265 const color_utils::HSL hsl_shift_; |
| 271 DISALLOW_COPY_AND_ASSIGN(HSLImageSource); | 266 DISALLOW_COPY_AND_ASSIGN(HSLImageSource); |
| 272 }; | 267 }; |
| 273 | 268 |
| 274 // ImageSkiaSource which uses SkBitmapOperations::CreateButtonBackground | 269 // ImageSkiaSource which uses SkBitmapOperations::CreateButtonBackground |
| 275 // to generate image reps for the target image. The image and mask can be | 270 // to generate image reps for the target image. The image and mask can be |
| 276 // diferent sizes (crbug.com/171725). | 271 // diferent sizes (crbug.com/171725). |
| 277 class ButtonImageSource: public gfx::ImageSkiaSource { | 272 class ButtonImageSource: public gfx::ImageSkiaSource { |
| 278 public: | 273 public: |
| 279 ButtonImageSource(SkColor color, | 274 ButtonImageSource(SkColor color, |
| 280 const ImageSkia& image, | 275 const ImageSkia& image, |
| 281 const ImageSkia& mask) | 276 const ImageSkia& mask) |
| 282 : color_(color), | 277 : color_(color), |
| 283 image_(image), | 278 image_(image), |
| 284 mask_(mask) { | 279 mask_(mask) { |
| 285 } | 280 } |
| 286 | 281 |
| 287 virtual ~ButtonImageSource() { | 282 virtual ~ButtonImageSource() { |
| 288 } | 283 } |
| 289 | 284 |
| 290 // gfx::ImageSkiaSource overrides: | 285 // gfx::ImageSkiaSource overrides: |
| 291 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 286 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
| 292 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); | 287 ImageSkiaRep image_rep = image_.GetRepresentation(scale); |
| 293 ImageSkiaRep mask_rep = mask_.GetRepresentation(scale_factor); | 288 ImageSkiaRep mask_rep = mask_.GetRepresentation(scale); |
| 294 if (image_rep.scale_factor() != mask_rep.scale_factor()) { | 289 if (image_rep.scale() != mask_rep.scale()) { |
| 295 image_rep = image_.GetRepresentation(ui::SCALE_FACTOR_100P); | 290 image_rep = image_.GetRepresentation(1.0f); |
| 296 mask_rep = mask_.GetRepresentation(ui::SCALE_FACTOR_100P); | 291 mask_rep = mask_.GetRepresentation(1.0f); |
| 297 } | 292 } |
| 298 return gfx::ImageSkiaRep( | 293 return gfx::ImageSkiaRep( |
| 299 SkBitmapOperations::CreateButtonBackground(color_, | 294 SkBitmapOperations::CreateButtonBackground(color_, |
| 300 image_rep.sk_bitmap(), mask_rep.sk_bitmap()), | 295 image_rep.sk_bitmap(), mask_rep.sk_bitmap()), |
| 301 image_rep.scale_factor()); | 296 image_rep.scale()); |
| 302 } | 297 } |
| 303 | 298 |
| 304 private: | 299 private: |
| 305 const SkColor color_; | 300 const SkColor color_; |
| 306 const ImageSkia image_; | 301 const ImageSkia image_; |
| 307 const ImageSkia mask_; | 302 const ImageSkia mask_; |
| 308 | 303 |
| 309 DISALLOW_COPY_AND_ASSIGN(ButtonImageSource); | 304 DISALLOW_COPY_AND_ASSIGN(ButtonImageSource); |
| 310 }; | 305 }; |
| 311 | 306 |
| 312 // ImageSkiaSource which uses SkBitmap::extractSubset to generate image reps | 307 // ImageSkiaSource which uses SkBitmap::extractSubset to generate image reps |
| 313 // for the target image. | 308 // for the target image. |
| 314 class ExtractSubsetImageSource: public gfx::ImageSkiaSource { | 309 class ExtractSubsetImageSource: public gfx::ImageSkiaSource { |
| 315 public: | 310 public: |
| 316 ExtractSubsetImageSource(const gfx::ImageSkia& image, | 311 ExtractSubsetImageSource(const gfx::ImageSkia& image, |
| 317 const gfx::Rect& subset_bounds) | 312 const gfx::Rect& subset_bounds) |
| 318 : image_(image), | 313 : image_(image), |
| 319 subset_bounds_(subset_bounds) { | 314 subset_bounds_(subset_bounds) { |
| 320 } | 315 } |
| 321 | 316 |
| 322 virtual ~ExtractSubsetImageSource() { | 317 virtual ~ExtractSubsetImageSource() { |
| 323 } | 318 } |
| 324 | 319 |
| 325 // gfx::ImageSkiaSource overrides: | 320 // gfx::ImageSkiaSource overrides: |
| 326 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 321 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
| 327 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); | 322 ImageSkiaRep image_rep = image_.GetRepresentation(scale); |
| 328 float scale_to_pixel = ui::GetScaleFactorScale(image_rep.scale_factor()); | |
| 329 SkIRect subset_bounds_in_pixel = RectToSkIRect( | 323 SkIRect subset_bounds_in_pixel = RectToSkIRect( |
| 330 DIPToPixelBounds(subset_bounds_, scale_to_pixel)); | 324 DIPToPixelBounds(subset_bounds_, image_rep.scale())); |
| 331 SkBitmap dst; | 325 SkBitmap dst; |
| 332 bool success = image_rep.sk_bitmap().extractSubset(&dst, | 326 bool success = image_rep.sk_bitmap().extractSubset(&dst, |
| 333 subset_bounds_in_pixel); | 327 subset_bounds_in_pixel); |
| 334 DCHECK(success); | 328 DCHECK(success); |
| 335 return gfx::ImageSkiaRep(dst, image_rep.scale_factor()); | 329 return gfx::ImageSkiaRep(dst, image_rep.scale()); |
| 336 } | 330 } |
| 337 | 331 |
| 338 private: | 332 private: |
| 339 const gfx::ImageSkia image_; | 333 const gfx::ImageSkia image_; |
| 340 const gfx::Rect subset_bounds_; | 334 const gfx::Rect subset_bounds_; |
| 341 | 335 |
| 342 DISALLOW_COPY_AND_ASSIGN(ExtractSubsetImageSource); | 336 DISALLOW_COPY_AND_ASSIGN(ExtractSubsetImageSource); |
| 343 }; | 337 }; |
| 344 | 338 |
| 345 // ResizeSource resizes relevant image reps in |source| to |target_dip_size| | 339 // ResizeSource resizes relevant image reps in |source| to |target_dip_size| |
| 346 // for requested scale factors. | 340 // for requested scale factors. |
| 347 class ResizeSource : public ImageSkiaSource { | 341 class ResizeSource : public ImageSkiaSource { |
| 348 public: | 342 public: |
| 349 ResizeSource(const ImageSkia& source, | 343 ResizeSource(const ImageSkia& source, |
| 350 skia::ImageOperations::ResizeMethod method, | 344 skia::ImageOperations::ResizeMethod method, |
| 351 const Size& target_dip_size) | 345 const Size& target_dip_size) |
| 352 : source_(source), | 346 : source_(source), |
| 353 resize_method_(method), | 347 resize_method_(method), |
| 354 target_dip_size_(target_dip_size) { | 348 target_dip_size_(target_dip_size) { |
| 355 } | 349 } |
| 356 virtual ~ResizeSource() {} | 350 virtual ~ResizeSource() {} |
| 357 | 351 |
| 358 // gfx::ImageSkiaSource overrides: | 352 // gfx::ImageSkiaSource overrides: |
| 359 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 353 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
| 360 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor); | 354 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); |
| 361 if (image_rep.GetWidth() == target_dip_size_.width() && | 355 if (image_rep.GetWidth() == target_dip_size_.width() && |
| 362 image_rep.GetHeight() == target_dip_size_.height()) | 356 image_rep.GetHeight() == target_dip_size_.height()) |
| 363 return image_rep; | 357 return image_rep; |
| 364 | 358 |
| 365 const float scale = ui::GetScaleFactorScale(scale_factor); | |
| 366 const Size target_pixel_size = DIPToPixelSize(target_dip_size_, scale); | 359 const Size target_pixel_size = DIPToPixelSize(target_dip_size_, scale); |
| 367 const SkBitmap resized = skia::ImageOperations::Resize( | 360 const SkBitmap resized = skia::ImageOperations::Resize( |
| 368 image_rep.sk_bitmap(), | 361 image_rep.sk_bitmap(), |
| 369 resize_method_, | 362 resize_method_, |
| 370 target_pixel_size.width(), | 363 target_pixel_size.width(), |
| 371 target_pixel_size.height()); | 364 target_pixel_size.height()); |
| 372 return ImageSkiaRep(resized, scale_factor); | 365 return ImageSkiaRep(resized, scale); |
| 373 } | 366 } |
| 374 | 367 |
| 375 private: | 368 private: |
| 376 const ImageSkia source_; | 369 const ImageSkia source_; |
| 377 skia::ImageOperations::ResizeMethod resize_method_; | 370 skia::ImageOperations::ResizeMethod resize_method_; |
| 378 const Size target_dip_size_; | 371 const Size target_dip_size_; |
| 379 | 372 |
| 380 DISALLOW_COPY_AND_ASSIGN(ResizeSource); | 373 DISALLOW_COPY_AND_ASSIGN(ResizeSource); |
| 381 }; | 374 }; |
| 382 | 375 |
| 383 // DropShadowSource generates image reps with drop shadow for image reps in | 376 // DropShadowSource generates image reps with drop shadow for image reps in |
| 384 // |source| that represent requested scale factors. | 377 // |source| that represent requested scale factors. |
| 385 class DropShadowSource : public ImageSkiaSource { | 378 class DropShadowSource : public ImageSkiaSource { |
| 386 public: | 379 public: |
| 387 DropShadowSource(const ImageSkia& source, | 380 DropShadowSource(const ImageSkia& source, |
| 388 const ShadowValues& shadows_in_dip) | 381 const ShadowValues& shadows_in_dip) |
| 389 : source_(source), | 382 : source_(source), |
| 390 shaodws_in_dip_(shadows_in_dip) { | 383 shaodws_in_dip_(shadows_in_dip) { |
| 391 } | 384 } |
| 392 virtual ~DropShadowSource() {} | 385 virtual ~DropShadowSource() {} |
| 393 | 386 |
| 394 // gfx::ImageSkiaSource overrides: | 387 // gfx::ImageSkiaSource overrides: |
| 395 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 388 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
| 396 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor); | 389 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); |
| 397 | 390 |
| 398 const float scale = image_rep.GetScale(); | |
| 399 ShadowValues shadows_in_pixel; | 391 ShadowValues shadows_in_pixel; |
| 400 for (size_t i = 0; i < shaodws_in_dip_.size(); ++i) | 392 for (size_t i = 0; i < shaodws_in_dip_.size(); ++i) |
| 401 shadows_in_pixel.push_back(shaodws_in_dip_[i].Scale(scale)); | 393 shadows_in_pixel.push_back(shaodws_in_dip_[i].Scale(scale)); |
| 402 | 394 |
| 403 const SkBitmap shadow_bitmap = SkBitmapOperations::CreateDropShadow( | 395 const SkBitmap shadow_bitmap = SkBitmapOperations::CreateDropShadow( |
| 404 image_rep.sk_bitmap(), | 396 image_rep.sk_bitmap(), |
| 405 shadows_in_pixel); | 397 shadows_in_pixel); |
| 406 return ImageSkiaRep(shadow_bitmap, image_rep.scale_factor()); | 398 return ImageSkiaRep(shadow_bitmap, image_rep.scale()); |
| 407 } | 399 } |
| 408 | 400 |
| 409 private: | 401 private: |
| 410 const ImageSkia source_; | 402 const ImageSkia source_; |
| 411 const ShadowValues shaodws_in_dip_; | 403 const ShadowValues shaodws_in_dip_; |
| 412 | 404 |
| 413 DISALLOW_COPY_AND_ASSIGN(DropShadowSource); | 405 DISALLOW_COPY_AND_ASSIGN(DropShadowSource); |
| 414 }; | 406 }; |
| 415 | 407 |
| 416 // RotatedSource generates image reps that are rotations of those in | 408 // RotatedSource generates image reps that are rotations of those in |
| 417 // |source| that represent requested scale factors. | 409 // |source| that represent requested scale factors. |
| 418 class RotatedSource : public ImageSkiaSource { | 410 class RotatedSource : public ImageSkiaSource { |
| 419 public: | 411 public: |
| 420 RotatedSource(const ImageSkia& source, | 412 RotatedSource(const ImageSkia& source, |
| 421 SkBitmapOperations::RotationAmount rotation) | 413 SkBitmapOperations::RotationAmount rotation) |
| 422 : source_(source), | 414 : source_(source), |
| 423 rotation_(rotation) { | 415 rotation_(rotation) { |
| 424 } | 416 } |
| 425 virtual ~RotatedSource() {} | 417 virtual ~RotatedSource() {} |
| 426 | 418 |
| 427 // gfx::ImageSkiaSource overrides: | 419 // gfx::ImageSkiaSource overrides: |
| 428 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 420 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
| 429 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor); | 421 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); |
| 430 const SkBitmap rotated_bitmap = | 422 const SkBitmap rotated_bitmap = |
| 431 SkBitmapOperations::Rotate(image_rep.sk_bitmap(), rotation_); | 423 SkBitmapOperations::Rotate(image_rep.sk_bitmap(), rotation_); |
| 432 return ImageSkiaRep(rotated_bitmap, image_rep.scale_factor()); | 424 return ImageSkiaRep(rotated_bitmap, image_rep.scale()); |
| 433 } | 425 } |
| 434 | 426 |
| 435 private: | 427 private: |
| 436 const ImageSkia source_; | 428 const ImageSkia source_; |
| 437 const SkBitmapOperations::RotationAmount rotation_; | 429 const SkBitmapOperations::RotationAmount rotation_; |
| 438 | 430 |
| 439 DISALLOW_COPY_AND_ASSIGN(RotatedSource); | 431 DISALLOW_COPY_AND_ASSIGN(RotatedSource); |
| 440 }; | 432 }; |
| 441 | 433 |
| 442 | 434 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 return ImageSkia(); | 550 return ImageSkia(); |
| 559 | 551 |
| 560 return ImageSkia(new RotatedSource(source, rotation), | 552 return ImageSkia(new RotatedSource(source, rotation), |
| 561 SkBitmapOperations::ROTATION_180_CW == rotation ? | 553 SkBitmapOperations::ROTATION_180_CW == rotation ? |
| 562 source.size() : | 554 source.size() : |
| 563 gfx::Size(source.height(), source.width())); | 555 gfx::Size(source.height(), source.width())); |
| 564 | 556 |
| 565 } | 557 } |
| 566 | 558 |
| 567 } // namespace gfx | 559 } // namespace gfx |
| OLD | NEW |