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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 : image_(image), | 281 : image_(image), |
282 subset_bounds_(subset_bounds) { | 282 subset_bounds_(subset_bounds) { |
283 } | 283 } |
284 | 284 |
285 virtual ~ExtractSubsetImageSource() { | 285 virtual ~ExtractSubsetImageSource() { |
286 } | 286 } |
287 | 287 |
288 // gfx::ImageSkiaSource overrides: | 288 // gfx::ImageSkiaSource overrides: |
289 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 289 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
290 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); | 290 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); |
291 gfx::RectF scaled_subset_bounds = subset_bounds_; | 291 SkIRect subset_bounds_in_pixel = RectToSkIRect(ToEnclosingRect(gfx::Scale( |
292 scaled_subset_bounds.Scale( | 292 subset_bounds_, ui::GetScaleFactorScale(image_rep.scale_factor())))); |
293 ui::GetScaleFactorScale(image_rep.scale_factor())); | |
294 SkIRect subset_bounds_in_pixel = RectToSkIRect( | |
295 ToEnclosingRect(scaled_subset_bounds)); | |
296 SkBitmap dst; | 293 SkBitmap dst; |
297 bool success = image_rep.sk_bitmap().extractSubset(&dst, | 294 bool success = image_rep.sk_bitmap().extractSubset(&dst, |
298 subset_bounds_in_pixel); | 295 subset_bounds_in_pixel); |
299 DCHECK(success); | 296 DCHECK(success); |
300 return gfx::ImageSkiaRep(dst, image_rep.scale_factor()); | 297 return gfx::ImageSkiaRep(dst, image_rep.scale_factor()); |
301 } | 298 } |
302 | 299 |
303 private: | 300 private: |
304 const gfx::ImageSkia image_; | 301 const gfx::ImageSkia image_; |
305 const gfx::Rect subset_bounds_; | 302 const gfx::Rect subset_bounds_; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 // static | 422 // static |
426 ImageSkia ImageSkiaOperations::CreateButtonBackground(SkColor color, | 423 ImageSkia ImageSkiaOperations::CreateButtonBackground(SkColor color, |
427 const ImageSkia& image, | 424 const ImageSkia& image, |
428 const ImageSkia& mask) { | 425 const ImageSkia& mask) { |
429 return ImageSkia(new ButtonImageSource(color, image, mask), mask.size()); | 426 return ImageSkia(new ButtonImageSource(color, image, mask), mask.size()); |
430 } | 427 } |
431 | 428 |
432 // static | 429 // static |
433 ImageSkia ImageSkiaOperations::ExtractSubset(const ImageSkia& image, | 430 ImageSkia ImageSkiaOperations::ExtractSubset(const ImageSkia& image, |
434 const Rect& subset_bounds) { | 431 const Rect& subset_bounds) { |
435 gfx::Rect clipped_bounds = subset_bounds; | 432 gfx::Rect clipped_bounds = |
436 clipped_bounds.Intersect(gfx::Rect(image.size())); | 433 gfx::Intersection(subset_bounds, gfx::Rect(image.size())); |
437 if (image.isNull() || clipped_bounds.IsEmpty()) { | 434 if (image.isNull() || clipped_bounds.IsEmpty()) { |
438 return ImageSkia(); | 435 return ImageSkia(); |
439 } | 436 } |
440 | 437 |
441 return ImageSkia(new ExtractSubsetImageSource(image, clipped_bounds), | 438 return ImageSkia(new ExtractSubsetImageSource(image, clipped_bounds), |
442 clipped_bounds.size()); | 439 clipped_bounds.size()); |
443 } | 440 } |
444 | 441 |
445 // static | 442 // static |
446 ImageSkia ImageSkiaOperations::CreateResizedImage( | 443 ImageSkia ImageSkiaOperations::CreateResizedImage( |
447 const ImageSkia& source, | 444 const ImageSkia& source, |
448 skia::ImageOperations::ResizeMethod method, | 445 skia::ImageOperations::ResizeMethod method, |
449 const Size& target_dip_size) { | 446 const Size& target_dip_size) { |
450 return ImageSkia(new ResizeSource(source, method, target_dip_size), | 447 return ImageSkia(new ResizeSource(source, method, target_dip_size), |
451 target_dip_size); | 448 target_dip_size); |
452 } | 449 } |
453 | 450 |
454 // static | 451 // static |
455 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow( | 452 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow( |
456 const ImageSkia& source, | 453 const ImageSkia& source, |
457 const ShadowValues& shadows) { | 454 const ShadowValues& shadows) { |
458 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); | 455 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); |
459 gfx::Size shadow_image_size = source.size(); | 456 gfx::Size shadow_image_size = source.size(); |
460 shadow_image_size.Enlarge(shadow_padding.width(), | 457 shadow_image_size.Enlarge(shadow_padding.width(), |
461 shadow_padding.height()); | 458 shadow_padding.height()); |
462 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); | 459 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); |
463 } | 460 } |
464 | 461 |
465 } // namespace gfx | 462 } // namespace gfx |
OLD | NEW |