Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: ui/gfx/image/image_skia_operations.cc

Issue 11270042: Add non-member non-mutating methods for common gfx::Rect operations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/blit.cc ('k') | ui/gfx/rect.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 float scale_to_pixel = ui::GetScaleFactorScale(image_rep.scale_factor());
292 scaled_subset_bounds.Scale( 292 SkIRect subset_bounds_in_pixel = RectToSkIRect(ToFlooredRectDeprecated(
293 ui::GetScaleFactorScale(image_rep.scale_factor())); 293 gfx::ScaleRect(subset_bounds_, scale_to_pixel)));
294 SkIRect subset_bounds_in_pixel = RectToSkIRect(
295 ToFlooredRectDeprecated(scaled_subset_bounds));
296 SkBitmap dst; 294 SkBitmap dst;
297 bool success = image_rep.sk_bitmap().extractSubset(&dst, 295 bool success = image_rep.sk_bitmap().extractSubset(&dst,
298 subset_bounds_in_pixel); 296 subset_bounds_in_pixel);
299 DCHECK(success); 297 DCHECK(success);
300 return gfx::ImageSkiaRep(dst, image_rep.scale_factor()); 298 return gfx::ImageSkiaRep(dst, image_rep.scale_factor());
301 } 299 }
302 300
303 private: 301 private:
304 const gfx::ImageSkia image_; 302 const gfx::ImageSkia image_;
305 const gfx::Rect subset_bounds_; 303 const gfx::Rect subset_bounds_;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 // static 423 // static
426 ImageSkia ImageSkiaOperations::CreateButtonBackground(SkColor color, 424 ImageSkia ImageSkiaOperations::CreateButtonBackground(SkColor color,
427 const ImageSkia& image, 425 const ImageSkia& image,
428 const ImageSkia& mask) { 426 const ImageSkia& mask) {
429 return ImageSkia(new ButtonImageSource(color, image, mask), mask.size()); 427 return ImageSkia(new ButtonImageSource(color, image, mask), mask.size());
430 } 428 }
431 429
432 // static 430 // static
433 ImageSkia ImageSkiaOperations::ExtractSubset(const ImageSkia& image, 431 ImageSkia ImageSkiaOperations::ExtractSubset(const ImageSkia& image,
434 const Rect& subset_bounds) { 432 const Rect& subset_bounds) {
435 gfx::Rect clipped_bounds = subset_bounds; 433 gfx::Rect clipped_bounds =
436 clipped_bounds.Intersect(gfx::Rect(image.size())); 434 gfx::IntersectRects(subset_bounds, gfx::Rect(image.size()));
437 if (image.isNull() || clipped_bounds.IsEmpty()) { 435 if (image.isNull() || clipped_bounds.IsEmpty()) {
438 return ImageSkia(); 436 return ImageSkia();
439 } 437 }
440 438
441 return ImageSkia(new ExtractSubsetImageSource(image, clipped_bounds), 439 return ImageSkia(new ExtractSubsetImageSource(image, clipped_bounds),
442 clipped_bounds.size()); 440 clipped_bounds.size());
443 } 441 }
444 442
445 // static 443 // static
446 ImageSkia ImageSkiaOperations::CreateResizedImage( 444 ImageSkia ImageSkiaOperations::CreateResizedImage(
447 const ImageSkia& source, 445 const ImageSkia& source,
448 skia::ImageOperations::ResizeMethod method, 446 skia::ImageOperations::ResizeMethod method,
449 const Size& target_dip_size) { 447 const Size& target_dip_size) {
450 return ImageSkia(new ResizeSource(source, method, target_dip_size), 448 return ImageSkia(new ResizeSource(source, method, target_dip_size),
451 target_dip_size); 449 target_dip_size);
452 } 450 }
453 451
454 // static 452 // static
455 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow( 453 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow(
456 const ImageSkia& source, 454 const ImageSkia& source,
457 const ShadowValues& shadows) { 455 const ShadowValues& shadows) {
458 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); 456 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows);
459 gfx::Size shadow_image_size = source.size(); 457 gfx::Size shadow_image_size = source.size();
460 shadow_image_size.Enlarge(shadow_padding.width(), 458 shadow_image_size.Enlarge(shadow_padding.width(),
461 shadow_padding.height()); 459 shadow_padding.height());
462 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); 460 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size);
463 } 461 }
464 462
465 } // namespace gfx 463 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/blit.cc ('k') | ui/gfx/rect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698