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

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

Issue 2443983003: Refactor ShadowImageSource into ui/gfx/skia_util for better reuse (Closed)
Patch Set: remove changes Created 4 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/image/image_skia_operations.h ('k') | no next file » | 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "skia/ext/image_operations.h" 12 #include "skia/ext/image_operations.h"
13 #include "third_party/skia/include/core/SkDrawLooper.h"
13 #include "ui/gfx/canvas.h" 14 #include "ui/gfx/canvas.h"
14 #include "ui/gfx/geometry/insets.h" 15 #include "ui/gfx/geometry/insets.h"
15 #include "ui/gfx/geometry/point.h" 16 #include "ui/gfx/geometry/point.h"
16 #include "ui/gfx/geometry/point_conversions.h" 17 #include "ui/gfx/geometry/point_conversions.h"
17 #include "ui/gfx/geometry/rect.h" 18 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/geometry/rect_conversions.h" 19 #include "ui/gfx/geometry/rect_conversions.h"
19 #include "ui/gfx/geometry/size.h" 20 #include "ui/gfx/geometry/size.h"
20 #include "ui/gfx/geometry/size_conversions.h" 21 #include "ui/gfx/geometry/size_conversions.h"
21 #include "ui/gfx/image/canvas_image_source.h" 22 #include "ui/gfx/image/canvas_image_source.h"
22 #include "ui/gfx/image/image_skia.h" 23 #include "ui/gfx/image/image_skia.h"
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 return ImageSkiaRep(shadow_bitmap, image_rep.scale()); 391 return ImageSkiaRep(shadow_bitmap, image_rep.scale());
391 } 392 }
392 393
393 private: 394 private:
394 const ImageSkia source_; 395 const ImageSkia source_;
395 const ShadowValues shaodws_in_dip_; 396 const ShadowValues shaodws_in_dip_;
396 397
397 DISALLOW_COPY_AND_ASSIGN(DropShadowSource); 398 DISALLOW_COPY_AND_ASSIGN(DropShadowSource);
398 }; 399 };
399 400
401 // An image source that is 1dp wide, suitable for tiling horizontally.
402 class HorizontalShadowSource : public CanvasImageSource {
403 public:
404 HorizontalShadowSource(const std::vector<ShadowValue>& shadows,
405 bool fades_down)
406 : CanvasImageSource(Size(1, GetHeightForShadows(shadows)), false),
407 shadows_(shadows),
408 fades_down_(fades_down) {}
409 ~HorizontalShadowSource() override {}
410
411 // CanvasImageSource overrides:
412 void Draw(Canvas* canvas) override {
413 SkPaint paint;
414 paint.setLooper(CreateShadowDrawLooperCorrectBlur(shadows_));
415 canvas->DrawRect(RectF(0, fades_down_ ? -1 : size().height(), 1, 1), paint);
416 }
417
418 private:
419 static int GetHeightForShadows(const std::vector<ShadowValue>& shadows) {
420 int height = 0;
421 for (const auto& shadow : shadows) {
422 height = std::max(height, shadow.y() + ToCeiledInt(shadow.blur() / 2));
423 }
424 return height;
425 }
426
427 const std::vector<ShadowValue> shadows_;
428
429 // The orientation of the shadow (true for shadows that emanate downwards).
430 bool fades_down_;
431
432 DISALLOW_COPY_AND_ASSIGN(HorizontalShadowSource);
433 };
434
400 // RotatedSource generates image reps that are rotations of those in 435 // RotatedSource generates image reps that are rotations of those in
401 // |source| that represent requested scale factors. 436 // |source| that represent requested scale factors.
402 class RotatedSource : public ImageSkiaSource { 437 class RotatedSource : public ImageSkiaSource {
403 public: 438 public:
404 RotatedSource(const ImageSkia& source, 439 RotatedSource(const ImageSkia& source,
405 SkBitmapOperations::RotationAmount rotation) 440 SkBitmapOperations::RotationAmount rotation)
406 : source_(source), 441 : source_(source),
407 rotation_(rotation) { 442 rotation_(rotation) {
408 } 443 }
409 ~RotatedSource() override {} 444 ~RotatedSource() override {}
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 return ImageSkia(); 585 return ImageSkia();
551 586
552 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); 587 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows);
553 gfx::Size shadow_image_size = source.size(); 588 gfx::Size shadow_image_size = source.size();
554 shadow_image_size.Enlarge(shadow_padding.width(), 589 shadow_image_size.Enlarge(shadow_padding.width(),
555 shadow_padding.height()); 590 shadow_padding.height());
556 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); 591 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size);
557 } 592 }
558 593
559 // static 594 // static
595 ImageSkia ImageSkiaOperations::CreateHorizontalShadow(
596 const std::vector<ShadowValue>& shadows,
597 bool fades_down) {
598 HorizontalShadowSource* source =
599 new HorizontalShadowSource(shadows, fades_down);
600 return ImageSkia(source, source->size());
601 }
602
603 // static
560 ImageSkia ImageSkiaOperations::CreateRotatedImage( 604 ImageSkia ImageSkiaOperations::CreateRotatedImage(
561 const ImageSkia& source, 605 const ImageSkia& source,
562 SkBitmapOperations::RotationAmount rotation) { 606 SkBitmapOperations::RotationAmount rotation) {
563 if (source.isNull()) 607 if (source.isNull())
564 return ImageSkia(); 608 return ImageSkia();
565 609
566 return ImageSkia(new RotatedSource(source, rotation), 610 return ImageSkia(new RotatedSource(source, rotation),
567 SkBitmapOperations::ROTATION_180_CW == rotation ? 611 SkBitmapOperations::ROTATION_180_CW == rotation ?
568 source.size() : 612 source.size() :
569 gfx::Size(source.height(), source.width())); 613 gfx::Size(source.height(), source.width()));
570 614
571 } 615 }
572 616
573 // static 617 // static
574 ImageSkia ImageSkiaOperations::CreateIconWithBadge(const ImageSkia& icon, 618 ImageSkia ImageSkiaOperations::CreateIconWithBadge(const ImageSkia& icon,
575 const ImageSkia& badge) { 619 const ImageSkia& badge) {
576 if (icon.isNull()) 620 if (icon.isNull())
577 return ImageSkia(); 621 return ImageSkia();
578 622
579 if (badge.isNull()) 623 if (badge.isNull())
580 return icon; 624 return icon;
581 625
582 return ImageSkia(new IconWithBadgeSource(icon, badge), icon.size()); 626 return ImageSkia(new IconWithBadgeSource(icon, badge), icon.size());
583 } 627 }
584 628
585 } // namespace gfx 629 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/image/image_skia_operations.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698