| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 const ImageSkia& second, | 51 const ImageSkia& second, |
| 52 const char* source_name) | 52 const char* source_name) |
| 53 : first_(first), | 53 : first_(first), |
| 54 second_(second), | 54 second_(second), |
| 55 source_name_(source_name) { | 55 source_name_(source_name) { |
| 56 } | 56 } |
| 57 virtual ~BinaryImageSource() { | 57 virtual ~BinaryImageSource() { |
| 58 } | 58 } |
| 59 | 59 |
| 60 // gfx::ImageSkiaSource overrides: | 60 // gfx::ImageSkiaSource overrides: |
| 61 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 61 virtual ImageSkiaRep GetImageForScale(float scale) override { |
| 62 ImageSkiaRep first_rep = first_.GetRepresentation(scale); | 62 ImageSkiaRep first_rep = first_.GetRepresentation(scale); |
| 63 ImageSkiaRep second_rep = second_.GetRepresentation(scale); | 63 ImageSkiaRep second_rep = second_.GetRepresentation(scale); |
| 64 if (first_rep.pixel_size() != second_rep.pixel_size()) { | 64 if (first_rep.pixel_size() != second_rep.pixel_size()) { |
| 65 DCHECK_NE(first_rep.scale(), second_rep.scale()); | 65 DCHECK_NE(first_rep.scale(), second_rep.scale()); |
| 66 if (first_rep.scale() == second_rep.scale()) { | 66 if (first_rep.scale() == second_rep.scale()) { |
| 67 LOG(ERROR) << "ImageSkiaRep size mismatch in " << source_name_; | 67 LOG(ERROR) << "ImageSkiaRep size mismatch in " << source_name_; |
| 68 return GetErrorImageRep(first_rep.scale(),first_rep.pixel_size()); | 68 return GetErrorImageRep(first_rep.scale(),first_rep.pixel_size()); |
| 69 } | 69 } |
| 70 first_rep = first_.GetRepresentation(1.0f); | 70 first_rep = first_.GetRepresentation(1.0f); |
| 71 second_rep = second_.GetRepresentation(1.0f); | 71 second_rep = second_.GetRepresentation(1.0f); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 : BinaryImageSource(first, second, "BlendingImageSource"), | 105 : BinaryImageSource(first, second, "BlendingImageSource"), |
| 106 alpha_(alpha) { | 106 alpha_(alpha) { |
| 107 } | 107 } |
| 108 | 108 |
| 109 virtual ~BlendingImageSource() { | 109 virtual ~BlendingImageSource() { |
| 110 } | 110 } |
| 111 | 111 |
| 112 // BinaryImageSource overrides: | 112 // BinaryImageSource overrides: |
| 113 virtual ImageSkiaRep CreateImageSkiaRep( | 113 virtual ImageSkiaRep CreateImageSkiaRep( |
| 114 const ImageSkiaRep& first_rep, | 114 const ImageSkiaRep& first_rep, |
| 115 const ImageSkiaRep& second_rep) const OVERRIDE { | 115 const ImageSkiaRep& second_rep) const override { |
| 116 SkBitmap blended = SkBitmapOperations::CreateBlendedBitmap( | 116 SkBitmap blended = SkBitmapOperations::CreateBlendedBitmap( |
| 117 first_rep.sk_bitmap(), second_rep.sk_bitmap(), alpha_); | 117 first_rep.sk_bitmap(), second_rep.sk_bitmap(), alpha_); |
| 118 return ImageSkiaRep(blended, first_rep.scale()); | 118 return ImageSkiaRep(blended, first_rep.scale()); |
| 119 } | 119 } |
| 120 | 120 |
| 121 private: | 121 private: |
| 122 double alpha_; | 122 double alpha_; |
| 123 | 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(BlendingImageSource); | 124 DISALLOW_COPY_AND_ASSIGN(BlendingImageSource); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 class SuperimposedImageSource : public gfx::CanvasImageSource { | 127 class SuperimposedImageSource : public gfx::CanvasImageSource { |
| 128 public: | 128 public: |
| 129 SuperimposedImageSource(const ImageSkia& first, | 129 SuperimposedImageSource(const ImageSkia& first, |
| 130 const ImageSkia& second) | 130 const ImageSkia& second) |
| 131 : gfx::CanvasImageSource(first.size(), false /* is opaque */), | 131 : gfx::CanvasImageSource(first.size(), false /* is opaque */), |
| 132 first_(first), | 132 first_(first), |
| 133 second_(second) { | 133 second_(second) { |
| 134 } | 134 } |
| 135 | 135 |
| 136 virtual ~SuperimposedImageSource() {} | 136 virtual ~SuperimposedImageSource() {} |
| 137 | 137 |
| 138 // gfx::CanvasImageSource override. | 138 // gfx::CanvasImageSource override. |
| 139 virtual void Draw(Canvas* canvas) OVERRIDE { | 139 virtual void Draw(Canvas* canvas) override { |
| 140 canvas->DrawImageInt(first_, 0, 0); | 140 canvas->DrawImageInt(first_, 0, 0); |
| 141 canvas->DrawImageInt(second_, | 141 canvas->DrawImageInt(second_, |
| 142 (first_.width() - second_.width()) / 2, | 142 (first_.width() - second_.width()) / 2, |
| 143 (first_.height() - second_.height()) / 2); | 143 (first_.height() - second_.height()) / 2); |
| 144 } | 144 } |
| 145 | 145 |
| 146 private: | 146 private: |
| 147 const ImageSkia first_; | 147 const ImageSkia first_; |
| 148 const ImageSkia second_; | 148 const ImageSkia second_; |
| 149 | 149 |
| 150 DISALLOW_COPY_AND_ASSIGN(SuperimposedImageSource); | 150 DISALLOW_COPY_AND_ASSIGN(SuperimposedImageSource); |
| 151 }; | 151 }; |
| 152 | 152 |
| 153 class TransparentImageSource : public gfx::ImageSkiaSource { | 153 class TransparentImageSource : public gfx::ImageSkiaSource { |
| 154 public: | 154 public: |
| 155 TransparentImageSource(const ImageSkia& image, double alpha) | 155 TransparentImageSource(const ImageSkia& image, double alpha) |
| 156 : image_(image), | 156 : image_(image), |
| 157 alpha_(alpha) { | 157 alpha_(alpha) { |
| 158 } | 158 } |
| 159 | 159 |
| 160 virtual ~TransparentImageSource() {} | 160 virtual ~TransparentImageSource() {} |
| 161 | 161 |
| 162 private: | 162 private: |
| 163 // gfx::ImageSkiaSource overrides: | 163 // gfx::ImageSkiaSource overrides: |
| 164 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 164 virtual ImageSkiaRep GetImageForScale(float scale) override { |
| 165 ImageSkiaRep image_rep = image_.GetRepresentation(scale); | 165 ImageSkiaRep image_rep = image_.GetRepresentation(scale); |
| 166 SkBitmap alpha; | 166 SkBitmap alpha; |
| 167 alpha.allocN32Pixels(image_rep.pixel_width(), | 167 alpha.allocN32Pixels(image_rep.pixel_width(), |
| 168 image_rep.pixel_height()); | 168 image_rep.pixel_height()); |
| 169 alpha.eraseColor(SkColorSetARGB(alpha_ * 255, 0, 0, 0)); | 169 alpha.eraseColor(SkColorSetARGB(alpha_ * 255, 0, 0, 0)); |
| 170 return ImageSkiaRep( | 170 return ImageSkiaRep( |
| 171 SkBitmapOperations::CreateMaskedBitmap(image_rep.sk_bitmap(), alpha), | 171 SkBitmapOperations::CreateMaskedBitmap(image_rep.sk_bitmap(), alpha), |
| 172 image_rep.scale()); | 172 image_rep.scale()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 ImageSkia image_; | 175 ImageSkia image_; |
| 176 double alpha_; | 176 double alpha_; |
| 177 | 177 |
| 178 DISALLOW_COPY_AND_ASSIGN(TransparentImageSource); | 178 DISALLOW_COPY_AND_ASSIGN(TransparentImageSource); |
| 179 }; | 179 }; |
| 180 | 180 |
| 181 class MaskedImageSource : public BinaryImageSource { | 181 class MaskedImageSource : public BinaryImageSource { |
| 182 public: | 182 public: |
| 183 MaskedImageSource(const ImageSkia& rgb, const ImageSkia& alpha) | 183 MaskedImageSource(const ImageSkia& rgb, const ImageSkia& alpha) |
| 184 : BinaryImageSource(rgb, alpha, "MaskedImageSource") { | 184 : BinaryImageSource(rgb, alpha, "MaskedImageSource") { |
| 185 } | 185 } |
| 186 | 186 |
| 187 virtual ~MaskedImageSource() { | 187 virtual ~MaskedImageSource() { |
| 188 } | 188 } |
| 189 | 189 |
| 190 // BinaryImageSource overrides: | 190 // BinaryImageSource overrides: |
| 191 virtual ImageSkiaRep CreateImageSkiaRep( | 191 virtual ImageSkiaRep CreateImageSkiaRep( |
| 192 const ImageSkiaRep& first_rep, | 192 const ImageSkiaRep& first_rep, |
| 193 const ImageSkiaRep& second_rep) const OVERRIDE { | 193 const ImageSkiaRep& second_rep) const override { |
| 194 return ImageSkiaRep(SkBitmapOperations::CreateMaskedBitmap( | 194 return ImageSkiaRep(SkBitmapOperations::CreateMaskedBitmap( |
| 195 first_rep.sk_bitmap(), second_rep.sk_bitmap()), | 195 first_rep.sk_bitmap(), second_rep.sk_bitmap()), |
| 196 first_rep.scale()); | 196 first_rep.scale()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 private: | 199 private: |
| 200 DISALLOW_COPY_AND_ASSIGN(MaskedImageSource); | 200 DISALLOW_COPY_AND_ASSIGN(MaskedImageSource); |
| 201 }; | 201 }; |
| 202 | 202 |
| 203 class TiledImageSource : public gfx::ImageSkiaSource { | 203 class TiledImageSource : public gfx::ImageSkiaSource { |
| 204 public: | 204 public: |
| 205 TiledImageSource(const ImageSkia& source, | 205 TiledImageSource(const ImageSkia& source, |
| 206 int src_x, int src_y, | 206 int src_x, int src_y, |
| 207 int dst_w, int dst_h) | 207 int dst_w, int dst_h) |
| 208 : source_(source), | 208 : source_(source), |
| 209 src_x_(src_x), | 209 src_x_(src_x), |
| 210 src_y_(src_y), | 210 src_y_(src_y), |
| 211 dst_w_(dst_w), | 211 dst_w_(dst_w), |
| 212 dst_h_(dst_h) { | 212 dst_h_(dst_h) { |
| 213 } | 213 } |
| 214 | 214 |
| 215 virtual ~TiledImageSource() { | 215 virtual ~TiledImageSource() { |
| 216 } | 216 } |
| 217 | 217 |
| 218 // gfx::ImageSkiaSource overrides: | 218 // gfx::ImageSkiaSource overrides: |
| 219 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 219 virtual ImageSkiaRep GetImageForScale(float scale) override { |
| 220 ImageSkiaRep source_rep = source_.GetRepresentation(scale); | 220 ImageSkiaRep source_rep = source_.GetRepresentation(scale); |
| 221 gfx::Rect bounds = DIPToPixelBounds(gfx::Rect(src_x_, src_y_, dst_w_, | 221 gfx::Rect bounds = DIPToPixelBounds(gfx::Rect(src_x_, src_y_, dst_w_, |
| 222 dst_h_), source_rep.scale()); | 222 dst_h_), source_rep.scale()); |
| 223 return ImageSkiaRep( | 223 return ImageSkiaRep( |
| 224 SkBitmapOperations::CreateTiledBitmap( | 224 SkBitmapOperations::CreateTiledBitmap( |
| 225 source_rep.sk_bitmap(), | 225 source_rep.sk_bitmap(), |
| 226 bounds.x(), bounds.y(), bounds.width(), bounds.height()), | 226 bounds.x(), bounds.y(), bounds.width(), bounds.height()), |
| 227 source_rep.scale()); | 227 source_rep.scale()); |
| 228 } | 228 } |
| 229 | 229 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 242 HSLImageSource(const ImageSkia& image, | 242 HSLImageSource(const ImageSkia& image, |
| 243 const color_utils::HSL& hsl_shift) | 243 const color_utils::HSL& hsl_shift) |
| 244 : image_(image), | 244 : image_(image), |
| 245 hsl_shift_(hsl_shift) { | 245 hsl_shift_(hsl_shift) { |
| 246 } | 246 } |
| 247 | 247 |
| 248 virtual ~HSLImageSource() { | 248 virtual ~HSLImageSource() { |
| 249 } | 249 } |
| 250 | 250 |
| 251 // gfx::ImageSkiaSource overrides: | 251 // gfx::ImageSkiaSource overrides: |
| 252 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 252 virtual ImageSkiaRep GetImageForScale(float scale) override { |
| 253 ImageSkiaRep image_rep = image_.GetRepresentation(scale); | 253 ImageSkiaRep image_rep = image_.GetRepresentation(scale); |
| 254 return gfx::ImageSkiaRep( | 254 return gfx::ImageSkiaRep( |
| 255 SkBitmapOperations::CreateHSLShiftedBitmap(image_rep.sk_bitmap(), | 255 SkBitmapOperations::CreateHSLShiftedBitmap(image_rep.sk_bitmap(), |
| 256 hsl_shift_), image_rep.scale()); | 256 hsl_shift_), image_rep.scale()); |
| 257 } | 257 } |
| 258 | 258 |
| 259 private: | 259 private: |
| 260 const gfx::ImageSkia image_; | 260 const gfx::ImageSkia image_; |
| 261 const color_utils::HSL hsl_shift_; | 261 const color_utils::HSL hsl_shift_; |
| 262 DISALLOW_COPY_AND_ASSIGN(HSLImageSource); | 262 DISALLOW_COPY_AND_ASSIGN(HSLImageSource); |
| 263 }; | 263 }; |
| 264 | 264 |
| 265 // ImageSkiaSource which uses SkBitmapOperations::CreateButtonBackground | 265 // ImageSkiaSource which uses SkBitmapOperations::CreateButtonBackground |
| 266 // to generate image reps for the target image. The image and mask can be | 266 // to generate image reps for the target image. The image and mask can be |
| 267 // diferent sizes (crbug.com/171725). | 267 // diferent sizes (crbug.com/171725). |
| 268 class ButtonImageSource: public gfx::ImageSkiaSource { | 268 class ButtonImageSource: public gfx::ImageSkiaSource { |
| 269 public: | 269 public: |
| 270 ButtonImageSource(SkColor color, | 270 ButtonImageSource(SkColor color, |
| 271 const ImageSkia& image, | 271 const ImageSkia& image, |
| 272 const ImageSkia& mask) | 272 const ImageSkia& mask) |
| 273 : color_(color), | 273 : color_(color), |
| 274 image_(image), | 274 image_(image), |
| 275 mask_(mask) { | 275 mask_(mask) { |
| 276 } | 276 } |
| 277 | 277 |
| 278 virtual ~ButtonImageSource() { | 278 virtual ~ButtonImageSource() { |
| 279 } | 279 } |
| 280 | 280 |
| 281 // gfx::ImageSkiaSource overrides: | 281 // gfx::ImageSkiaSource overrides: |
| 282 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 282 virtual ImageSkiaRep GetImageForScale(float scale) override { |
| 283 ImageSkiaRep image_rep = image_.GetRepresentation(scale); | 283 ImageSkiaRep image_rep = image_.GetRepresentation(scale); |
| 284 ImageSkiaRep mask_rep = mask_.GetRepresentation(scale); | 284 ImageSkiaRep mask_rep = mask_.GetRepresentation(scale); |
| 285 if (image_rep.scale() != mask_rep.scale()) { | 285 if (image_rep.scale() != mask_rep.scale()) { |
| 286 image_rep = image_.GetRepresentation(1.0f); | 286 image_rep = image_.GetRepresentation(1.0f); |
| 287 mask_rep = mask_.GetRepresentation(1.0f); | 287 mask_rep = mask_.GetRepresentation(1.0f); |
| 288 } | 288 } |
| 289 return gfx::ImageSkiaRep( | 289 return gfx::ImageSkiaRep( |
| 290 SkBitmapOperations::CreateButtonBackground(color_, | 290 SkBitmapOperations::CreateButtonBackground(color_, |
| 291 image_rep.sk_bitmap(), mask_rep.sk_bitmap()), | 291 image_rep.sk_bitmap(), mask_rep.sk_bitmap()), |
| 292 image_rep.scale()); | 292 image_rep.scale()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 307 ExtractSubsetImageSource(const gfx::ImageSkia& image, | 307 ExtractSubsetImageSource(const gfx::ImageSkia& image, |
| 308 const gfx::Rect& subset_bounds) | 308 const gfx::Rect& subset_bounds) |
| 309 : image_(image), | 309 : image_(image), |
| 310 subset_bounds_(subset_bounds) { | 310 subset_bounds_(subset_bounds) { |
| 311 } | 311 } |
| 312 | 312 |
| 313 virtual ~ExtractSubsetImageSource() { | 313 virtual ~ExtractSubsetImageSource() { |
| 314 } | 314 } |
| 315 | 315 |
| 316 // gfx::ImageSkiaSource overrides: | 316 // gfx::ImageSkiaSource overrides: |
| 317 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 317 virtual ImageSkiaRep GetImageForScale(float scale) override { |
| 318 ImageSkiaRep image_rep = image_.GetRepresentation(scale); | 318 ImageSkiaRep image_rep = image_.GetRepresentation(scale); |
| 319 SkIRect subset_bounds_in_pixel = RectToSkIRect( | 319 SkIRect subset_bounds_in_pixel = RectToSkIRect( |
| 320 DIPToPixelBounds(subset_bounds_, image_rep.scale())); | 320 DIPToPixelBounds(subset_bounds_, image_rep.scale())); |
| 321 SkBitmap dst; | 321 SkBitmap dst; |
| 322 bool success = image_rep.sk_bitmap().extractSubset(&dst, | 322 bool success = image_rep.sk_bitmap().extractSubset(&dst, |
| 323 subset_bounds_in_pixel); | 323 subset_bounds_in_pixel); |
| 324 DCHECK(success); | 324 DCHECK(success); |
| 325 return gfx::ImageSkiaRep(dst, image_rep.scale()); | 325 return gfx::ImageSkiaRep(dst, image_rep.scale()); |
| 326 } | 326 } |
| 327 | 327 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 339 ResizeSource(const ImageSkia& source, | 339 ResizeSource(const ImageSkia& source, |
| 340 skia::ImageOperations::ResizeMethod method, | 340 skia::ImageOperations::ResizeMethod method, |
| 341 const Size& target_dip_size) | 341 const Size& target_dip_size) |
| 342 : source_(source), | 342 : source_(source), |
| 343 resize_method_(method), | 343 resize_method_(method), |
| 344 target_dip_size_(target_dip_size) { | 344 target_dip_size_(target_dip_size) { |
| 345 } | 345 } |
| 346 virtual ~ResizeSource() {} | 346 virtual ~ResizeSource() {} |
| 347 | 347 |
| 348 // gfx::ImageSkiaSource overrides: | 348 // gfx::ImageSkiaSource overrides: |
| 349 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 349 virtual ImageSkiaRep GetImageForScale(float scale) override { |
| 350 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); | 350 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); |
| 351 if (image_rep.GetWidth() == target_dip_size_.width() && | 351 if (image_rep.GetWidth() == target_dip_size_.width() && |
| 352 image_rep.GetHeight() == target_dip_size_.height()) | 352 image_rep.GetHeight() == target_dip_size_.height()) |
| 353 return image_rep; | 353 return image_rep; |
| 354 | 354 |
| 355 const Size target_pixel_size = DIPToPixelSize(target_dip_size_, scale); | 355 const Size target_pixel_size = DIPToPixelSize(target_dip_size_, scale); |
| 356 const SkBitmap resized = skia::ImageOperations::Resize( | 356 const SkBitmap resized = skia::ImageOperations::Resize( |
| 357 image_rep.sk_bitmap(), | 357 image_rep.sk_bitmap(), |
| 358 resize_method_, | 358 resize_method_, |
| 359 target_pixel_size.width(), | 359 target_pixel_size.width(), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 374 class DropShadowSource : public ImageSkiaSource { | 374 class DropShadowSource : public ImageSkiaSource { |
| 375 public: | 375 public: |
| 376 DropShadowSource(const ImageSkia& source, | 376 DropShadowSource(const ImageSkia& source, |
| 377 const ShadowValues& shadows_in_dip) | 377 const ShadowValues& shadows_in_dip) |
| 378 : source_(source), | 378 : source_(source), |
| 379 shaodws_in_dip_(shadows_in_dip) { | 379 shaodws_in_dip_(shadows_in_dip) { |
| 380 } | 380 } |
| 381 virtual ~DropShadowSource() {} | 381 virtual ~DropShadowSource() {} |
| 382 | 382 |
| 383 // gfx::ImageSkiaSource overrides: | 383 // gfx::ImageSkiaSource overrides: |
| 384 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 384 virtual ImageSkiaRep GetImageForScale(float scale) override { |
| 385 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); | 385 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); |
| 386 | 386 |
| 387 ShadowValues shadows_in_pixel; | 387 ShadowValues shadows_in_pixel; |
| 388 for (size_t i = 0; i < shaodws_in_dip_.size(); ++i) | 388 for (size_t i = 0; i < shaodws_in_dip_.size(); ++i) |
| 389 shadows_in_pixel.push_back(shaodws_in_dip_[i].Scale(scale)); | 389 shadows_in_pixel.push_back(shaodws_in_dip_[i].Scale(scale)); |
| 390 | 390 |
| 391 const SkBitmap shadow_bitmap = SkBitmapOperations::CreateDropShadow( | 391 const SkBitmap shadow_bitmap = SkBitmapOperations::CreateDropShadow( |
| 392 image_rep.sk_bitmap(), | 392 image_rep.sk_bitmap(), |
| 393 shadows_in_pixel); | 393 shadows_in_pixel); |
| 394 return ImageSkiaRep(shadow_bitmap, image_rep.scale()); | 394 return ImageSkiaRep(shadow_bitmap, image_rep.scale()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 406 class RotatedSource : public ImageSkiaSource { | 406 class RotatedSource : public ImageSkiaSource { |
| 407 public: | 407 public: |
| 408 RotatedSource(const ImageSkia& source, | 408 RotatedSource(const ImageSkia& source, |
| 409 SkBitmapOperations::RotationAmount rotation) | 409 SkBitmapOperations::RotationAmount rotation) |
| 410 : source_(source), | 410 : source_(source), |
| 411 rotation_(rotation) { | 411 rotation_(rotation) { |
| 412 } | 412 } |
| 413 virtual ~RotatedSource() {} | 413 virtual ~RotatedSource() {} |
| 414 | 414 |
| 415 // gfx::ImageSkiaSource overrides: | 415 // gfx::ImageSkiaSource overrides: |
| 416 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 416 virtual ImageSkiaRep GetImageForScale(float scale) override { |
| 417 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); | 417 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); |
| 418 const SkBitmap rotated_bitmap = | 418 const SkBitmap rotated_bitmap = |
| 419 SkBitmapOperations::Rotate(image_rep.sk_bitmap(), rotation_); | 419 SkBitmapOperations::Rotate(image_rep.sk_bitmap(), rotation_); |
| 420 return ImageSkiaRep(rotated_bitmap, image_rep.scale()); | 420 return ImageSkiaRep(rotated_bitmap, image_rep.scale()); |
| 421 } | 421 } |
| 422 | 422 |
| 423 private: | 423 private: |
| 424 const ImageSkia source_; | 424 const ImageSkia source_; |
| 425 const SkBitmapOperations::RotationAmount rotation_; | 425 const SkBitmapOperations::RotationAmount rotation_; |
| 426 | 426 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 return ImageSkia(); | 546 return ImageSkia(); |
| 547 | 547 |
| 548 return ImageSkia(new RotatedSource(source, rotation), | 548 return ImageSkia(new RotatedSource(source, rotation), |
| 549 SkBitmapOperations::ROTATION_180_CW == rotation ? | 549 SkBitmapOperations::ROTATION_180_CW == rotation ? |
| 550 source.size() : | 550 source.size() : |
| 551 gfx::Size(source.height(), source.width())); | 551 gfx::Size(source.height(), source.width())); |
| 552 | 552 |
| 553 } | 553 } |
| 554 | 554 |
| 555 } // namespace gfx | 555 } // namespace gfx |
| OLD | NEW |