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

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

Issue 11110004: Make gfx::Rect class operations consistently mutate the class they are called on. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: cc/ fixes 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
« 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_;
292 scaled_subset_bounds.Scale(
293 ui::GetScaleFactorScale(image_rep.scale_factor()));
291 SkIRect subset_bounds_in_pixel = RectToSkIRect( 294 SkIRect subset_bounds_in_pixel = RectToSkIRect(
292 ToEnclosingRect(subset_bounds_.Scale( 295 ToEnclosingRect(scaled_subset_bounds));
293 ui::GetScaleFactorScale(image_rep.scale_factor()))));
294 SkBitmap dst; 296 SkBitmap dst;
295 bool success = image_rep.sk_bitmap().extractSubset(&dst, 297 bool success = image_rep.sk_bitmap().extractSubset(&dst,
296 subset_bounds_in_pixel); 298 subset_bounds_in_pixel);
297 DCHECK(success); 299 DCHECK(success);
298 return gfx::ImageSkiaRep(dst, image_rep.scale_factor()); 300 return gfx::ImageSkiaRep(dst, image_rep.scale_factor());
299 } 301 }
300 302
301 private: 303 private:
302 const gfx::ImageSkia image_; 304 const gfx::ImageSkia image_;
303 const gfx::Rect subset_bounds_; 305 const gfx::Rect subset_bounds_;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 // static 425 // static
424 ImageSkia ImageSkiaOperations::CreateButtonBackground(SkColor color, 426 ImageSkia ImageSkiaOperations::CreateButtonBackground(SkColor color,
425 const ImageSkia& image, 427 const ImageSkia& image,
426 const ImageSkia& mask) { 428 const ImageSkia& mask) {
427 return ImageSkia(new ButtonImageSource(color, image, mask), mask.size()); 429 return ImageSkia(new ButtonImageSource(color, image, mask), mask.size());
428 } 430 }
429 431
430 // static 432 // static
431 ImageSkia ImageSkiaOperations::ExtractSubset(const ImageSkia& image, 433 ImageSkia ImageSkiaOperations::ExtractSubset(const ImageSkia& image,
432 const Rect& subset_bounds) { 434 const Rect& subset_bounds) {
433 gfx::Rect clipped_bounds = subset_bounds.Intersect(gfx::Rect(image.size())); 435 gfx::Rect clipped_bounds = subset_bounds;
436 clipped_bounds.Intersect(gfx::Rect(image.size()));
434 if (image.isNull() || clipped_bounds.IsEmpty()) { 437 if (image.isNull() || clipped_bounds.IsEmpty()) {
435 return ImageSkia(); 438 return ImageSkia();
436 } 439 }
437 440
438 return ImageSkia(new ExtractSubsetImageSource(image, clipped_bounds), 441 return ImageSkia(new ExtractSubsetImageSource(image, clipped_bounds),
439 clipped_bounds.size()); 442 clipped_bounds.size());
440 } 443 }
441 444
442 // static 445 // static
443 ImageSkia ImageSkiaOperations::CreateResizedImage( 446 ImageSkia ImageSkiaOperations::CreateResizedImage(
444 const ImageSkia& source, 447 const ImageSkia& source,
445 skia::ImageOperations::ResizeMethod method, 448 skia::ImageOperations::ResizeMethod method,
446 const Size& target_dip_size) { 449 const Size& target_dip_size) {
447 return ImageSkia(new ResizeSource(source, method, target_dip_size), 450 return ImageSkia(new ResizeSource(source, method, target_dip_size),
448 target_dip_size); 451 target_dip_size);
449 } 452 }
450 453
451 // static 454 // static
452 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow( 455 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow(
453 const ImageSkia& source, 456 const ImageSkia& source,
454 const ShadowValues& shadows) { 457 const ShadowValues& shadows) {
455 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); 458 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows);
456 gfx::Size shadow_image_size = source.size(); 459 gfx::Size shadow_image_size = source.size();
457 shadow_image_size.Enlarge(shadow_padding.width(), 460 shadow_image_size.Enlarge(shadow_padding.width(),
458 shadow_padding.height()); 461 shadow_padding.height());
459 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); 462 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size);
460 } 463 }
461 464
462 } // namespace gfx 465 } // 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