Chromium Code Reviews| 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" | 10 #include "ui/base/layout.h" |
| 11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/image/canvas_image_source.h" | 12 #include "ui/gfx/image/canvas_image_source.h" |
| 13 #include "ui/gfx/image/image_skia.h" | 13 #include "ui/gfx/image/image_skia.h" |
| 14 #include "ui/gfx/image/image_skia_rep.h" | 14 #include "ui/gfx/image/image_skia_rep.h" |
| 15 #include "ui/gfx/image/image_skia_source.h" | 15 #include "ui/gfx/image/image_skia_source.h" |
| 16 #include "ui/gfx/insets.h" | 16 #include "ui/gfx/insets.h" |
| 17 #include "ui/gfx/point.h" | |
| 18 #include "ui/gfx/point_conversions.h" | |
| 17 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
| 18 #include "ui/gfx/rect_conversions.h" | 20 #include "ui/gfx/rect_conversions.h" |
| 19 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
| 20 #include "ui/gfx/size_conversions.h" | 22 #include "ui/gfx/size_conversions.h" |
| 21 #include "ui/gfx/skbitmap_operations.h" | 23 #include "ui/gfx/skbitmap_operations.h" |
| 22 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
| 23 | 25 |
| 24 namespace gfx { | 26 namespace gfx { |
| 25 namespace { | 27 namespace { |
| 26 | 28 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 47 second_(second), | 49 second_(second), |
| 48 source_name_(source_name) { | 50 source_name_(source_name) { |
| 49 } | 51 } |
| 50 virtual ~BinaryImageSource() { | 52 virtual ~BinaryImageSource() { |
| 51 } | 53 } |
| 52 | 54 |
| 53 // gfx::ImageSkiaSource overrides: | 55 // gfx::ImageSkiaSource overrides: |
| 54 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 56 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
| 55 ImageSkiaRep first_rep = first_.GetRepresentation(scale_factor); | 57 ImageSkiaRep first_rep = first_.GetRepresentation(scale_factor); |
| 56 ImageSkiaRep second_rep = second_.GetRepresentation(scale_factor); | 58 ImageSkiaRep second_rep = second_.GetRepresentation(scale_factor); |
| 57 if (first_rep.pixel_size() != second_rep.pixel_size()) { | 59 gfx::Size first_size = first_rep.pixel_size(); |
| 60 gfx::Size second_size = second_rep.pixel_size(); | |
| 61 // Allow for maximum of 1 pixel mismatch due to rounding errors. | |
| 62 int dw = first_size.width() - second_size.width(); | |
| 63 int dh = first_size.height() - second_size.height(); | |
| 64 if (abs(dw) > 1 || abs(dh) > 1) { | |
| 58 DCHECK_NE(first_rep.scale_factor(), second_rep.scale_factor()); | 65 DCHECK_NE(first_rep.scale_factor(), second_rep.scale_factor()); |
| 59 if (first_rep.scale_factor() == second_rep.scale_factor()) { | 66 if (first_rep.scale_factor() == second_rep.scale_factor()) { |
| 60 LOG(ERROR) << "ImageSkiaRep size mismatch in " << source_name_; | 67 LOG(ERROR) << "ImageSkiaRep size mismatch in " << source_name_; |
| 61 return GetErrorImageRep(first_rep.scale_factor(), | 68 return GetErrorImageRep(first_rep.scale_factor(), |
| 62 first_rep.pixel_size()); | 69 first_rep.pixel_size()); |
| 63 } | 70 } |
| 64 first_rep = first_.GetRepresentation(ui::SCALE_FACTOR_100P); | 71 first_rep = first_.GetRepresentation(ui::SCALE_FACTOR_100P); |
| 65 second_rep = second_.GetRepresentation(ui::SCALE_FACTOR_100P); | 72 second_rep = second_.GetRepresentation(ui::SCALE_FACTOR_100P); |
| 66 DCHECK_EQ(first_rep.pixel_width(), second_rep.pixel_width()); | 73 DCHECK_LE(abs(dw), 1); |
| 67 DCHECK_EQ(first_rep.pixel_height(), second_rep.pixel_height()); | 74 DCHECK_LE(abs(dh), 1); |
| 68 if (first_rep.pixel_size() != second_rep.pixel_size()) { | 75 if (abs(dw) > 1 || abs(dh) > 1) { |
| 69 LOG(ERROR) << "ImageSkiaRep size mismatch in " << source_name_; | 76 LOG(ERROR) << "ImageSkiaRep size mismatch in " << source_name_; |
| 70 return GetErrorImageRep(first_rep.scale_factor(), | 77 return GetErrorImageRep(first_rep.scale_factor(), |
| 71 first_rep.pixel_size()); | 78 first_rep.pixel_size()); |
| 72 } | 79 } |
| 73 } else { | 80 } else { |
| 74 DCHECK_EQ(first_rep.scale_factor(), second_rep.scale_factor()); | 81 DCHECK_EQ(first_rep.scale_factor(), second_rep.scale_factor()); |
| 75 } | 82 } |
| 76 return CreateImageSkiaRep(first_rep, second_rep); | 83 return CreateImageSkiaRep(first_rep, second_rep); |
| 77 } | 84 } |
| 78 | 85 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 dst_h_(dst_h) { | 216 dst_h_(dst_h) { |
| 210 } | 217 } |
| 211 | 218 |
| 212 virtual ~TiledImageSource() { | 219 virtual ~TiledImageSource() { |
| 213 } | 220 } |
| 214 | 221 |
| 215 // gfx::ImageSkiaSource overrides: | 222 // gfx::ImageSkiaSource overrides: |
| 216 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 223 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
| 217 ImageSkiaRep source_rep = source_.GetRepresentation(scale_factor); | 224 ImageSkiaRep source_rep = source_.GetRepresentation(scale_factor); |
| 218 float scale = ui::GetScaleFactorScale(source_rep.scale_factor()); | 225 float scale = ui::GetScaleFactorScale(source_rep.scale_factor()); |
| 226 gfx::Point point = gfx::ToFlooredPoint(gfx::ScalePoint( | |
|
pkotwicz
2013/03/12 15:54:37
You should create a generic method which does this
kevers
2013/03/12 22:02:25
Done.
| |
| 227 gfx::Point(src_x_, src_y_), scale)); | |
| 228 gfx::Size size = gfx::ToCeiledSize(gfx::ScaleSize( | |
| 229 gfx::Size(dst_w_, dst_h_), scale)); | |
| 219 return ImageSkiaRep( | 230 return ImageSkiaRep( |
| 220 SkBitmapOperations::CreateTiledBitmap( | 231 SkBitmapOperations::CreateTiledBitmap( |
| 221 source_rep.sk_bitmap(), | 232 source_rep.sk_bitmap(), |
| 222 src_x_ * scale, src_y_ * scale, dst_w_ * scale, dst_h_ * scale), | 233 point.x(), point.y(), size.width(), size.height()), |
| 223 source_rep.scale_factor()); | 234 source_rep.scale_factor()); |
| 224 } | 235 } |
| 225 | 236 |
| 226 private: | 237 private: |
| 227 const ImageSkia source_; | 238 const ImageSkia source_; |
| 228 const int src_x_; | 239 const int src_x_; |
| 229 const int src_y_; | 240 const int src_y_; |
| 230 const int dst_w_; | 241 const int dst_w_; |
| 231 const int dst_h_; | 242 const int dst_h_; |
| 232 | 243 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 253 } | 264 } |
| 254 | 265 |
| 255 private: | 266 private: |
| 256 const gfx::ImageSkia image_; | 267 const gfx::ImageSkia image_; |
| 257 const color_utils::HSL hsl_shift_; | 268 const color_utils::HSL hsl_shift_; |
| 258 DISALLOW_COPY_AND_ASSIGN(HSLImageSource); | 269 DISALLOW_COPY_AND_ASSIGN(HSLImageSource); |
| 259 }; | 270 }; |
| 260 | 271 |
| 261 // ImageSkiaSource which uses SkBitmapOperations::CreateButtonBackground | 272 // ImageSkiaSource which uses SkBitmapOperations::CreateButtonBackground |
| 262 // to generate image reps for the target image. | 273 // to generate image reps for the target image. |
| 263 class ButtonImageSource: public gfx::ImageSkiaSource { | 274 class ButtonImageSource: public gfx::ImageSkiaSource { |
|
pkotwicz
2013/03/12 15:54:37
Nit: Switch this class to inherit from BinaryImage
kevers
2013/03/12 22:02:25
Done.
| |
| 264 public: | 275 public: |
| 265 ButtonImageSource(SkColor color, | 276 ButtonImageSource(SkColor color, |
| 266 const ImageSkia& image, | 277 const ImageSkia& image, |
| 267 const ImageSkia& mask) | 278 const ImageSkia& mask) |
| 268 : color_(color), | 279 : color_(color), |
| 269 image_(image), | 280 image_(image), |
| 270 mask_(mask) { | 281 mask_(mask) { |
| 271 } | 282 } |
| 272 | 283 |
| 273 virtual ~ButtonImageSource() { | 284 virtual ~ButtonImageSource() { |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 return ImageSkia(); | 556 return ImageSkia(); |
| 546 | 557 |
| 547 return ImageSkia(new RotatedSource(source, rotation), | 558 return ImageSkia(new RotatedSource(source, rotation), |
| 548 SkBitmapOperations::ROTATION_180_CW == rotation ? | 559 SkBitmapOperations::ROTATION_180_CW == rotation ? |
| 549 source.size() : | 560 source.size() : |
| 550 gfx::Size(source.height(), source.width())); | 561 gfx::Size(source.height(), source.width())); |
| 551 | 562 |
| 552 } | 563 } |
| 553 | 564 |
| 554 } // namespace gfx | 565 } // namespace gfx |
| OLD | NEW |