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

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

Issue 2550593002: Update WM shadows for MD. (Closed)
Patch Set: fix corners Created 4 years 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
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"
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 skia::ImageOperations::ResizeMethod resize_method_; 363 skia::ImageOperations::ResizeMethod resize_method_;
364 const Size target_dip_size_; 364 const Size target_dip_size_;
365 365
366 DISALLOW_COPY_AND_ASSIGN(ResizeSource); 366 DISALLOW_COPY_AND_ASSIGN(ResizeSource);
367 }; 367 };
368 368
369 // DropShadowSource generates image reps with drop shadow for image reps in 369 // DropShadowSource generates image reps with drop shadow for image reps in
370 // |source| that represent requested scale factors. 370 // |source| that represent requested scale factors.
371 class DropShadowSource : public ImageSkiaSource { 371 class DropShadowSource : public ImageSkiaSource {
372 public: 372 public:
373 DropShadowSource(const ImageSkia& source, 373 DropShadowSource(const ImageSkia& source, const ShadowValues& shadows_in_dip)
374 const ShadowValues& shadows_in_dip) 374 : source_(source), shadows_in_dip_(shadows_in_dip) {}
375 : source_(source),
376 shaodws_in_dip_(shadows_in_dip) {
377 }
378 ~DropShadowSource() override {} 375 ~DropShadowSource() override {}
379 376
380 // gfx::ImageSkiaSource overrides: 377 // gfx::ImageSkiaSource overrides:
381 ImageSkiaRep GetImageForScale(float scale) override { 378 ImageSkiaRep GetImageForScale(float scale) override {
382 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale); 379 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale);
383 380
384 ShadowValues shadows_in_pixel; 381 ShadowValues shadows_in_pixel;
385 for (size_t i = 0; i < shaodws_in_dip_.size(); ++i) 382 for (size_t i = 0; i < shadows_in_dip_.size(); ++i)
386 shadows_in_pixel.push_back(shaodws_in_dip_[i].Scale(scale)); 383 shadows_in_pixel.push_back(shadows_in_dip_[i].Scale(scale));
387 384
388 const SkBitmap shadow_bitmap = SkBitmapOperations::CreateDropShadow( 385 const SkBitmap shadow_bitmap = SkBitmapOperations::CreateDropShadow(
389 image_rep.sk_bitmap(), 386 image_rep.sk_bitmap(),
390 shadows_in_pixel); 387 shadows_in_pixel);
391 return ImageSkiaRep(shadow_bitmap, image_rep.scale()); 388 return ImageSkiaRep(shadow_bitmap, image_rep.scale());
392 } 389 }
393 390
394 private: 391 private:
395 const ImageSkia source_; 392 const ImageSkia source_;
396 const ShadowValues shaodws_in_dip_; 393 const ShadowValues shadows_in_dip_;
397 394
398 DISALLOW_COPY_AND_ASSIGN(DropShadowSource); 395 DISALLOW_COPY_AND_ASSIGN(DropShadowSource);
399 }; 396 };
400 397
401 // An image source that is 1dp wide, suitable for tiling horizontally. 398 class ShadowNineboxSource : public CanvasImageSource {
399 public:
400 ShadowNineboxSource(const std::vector<ShadowValue>& shadows,
401 float corner_radius)
402 : CanvasImageSource(CalculateSize(shadows, corner_radius), false),
403 shadows_(shadows),
404 corner_radius_(corner_radius) {}
James Cook 2016/12/05 23:38:35 nit: DCHECK something about shadows.size() or .emp
Evan Stade 2016/12/06 00:53:21 Done.
405 ~ShadowNineboxSource() override {}
406
407 // CanvasImageSource overrides:
408 void Draw(Canvas* canvas) override {
409 SkPaint paint;
410 paint.setLooper(CreateShadowDrawLooperCorrectBlur(shadows_));
411 Insets insets = -ShadowValue::GetMargin(shadows_);
412 gfx::Rect bounds(size());
413 bounds.Inset(insets);
414 gfx::RectF rrect_bounds(bounds);
James Cook 2016/12/05 23:38:35 nit: Either rounded_rect_bounds or comment that rr
Evan Stade 2016/12/06 00:53:21 removed variable
415 SkRRect r_rect = SkRRect::MakeRectXY(gfx::RectFToSkRect(rrect_bounds),
416 corner_radius_, corner_radius_);
417
418 // Clip out the center so it's not painted with the shadow.
419 canvas->sk_canvas()->clipRRect(r_rect, SkRegion::kDifference_Op, true);
420 // Clipping alone is not enough --- due to anti aliasing there will still be
421 // some of the fill color in the rounded corners. We must make the fill
422 // color transparent.
423 paint.setColor(SK_ColorTRANSPARENT);
424 canvas->sk_canvas()->drawRRect(r_rect, paint);
425 }
426
427 private:
428 static Size CalculateSize(const std::vector<ShadowValue>& shadows,
429 float corner_radius) {
430 Insets insets = ShadowValue::GetBlurRegion(shadows);
431 return Size(insets.width() + 2 * corner_radius,
432 insets.height() + 2 * corner_radius);
433 }
434
435 const std::vector<ShadowValue> shadows_;
436
437 float corner_radius_;
438
439 DISALLOW_COPY_AND_ASSIGN(ShadowNineboxSource);
440 };
441
442 // An image source that is 1px wide, suitable for tiling horizontally.
402 class HorizontalShadowSource : public CanvasImageSource { 443 class HorizontalShadowSource : public CanvasImageSource {
403 public: 444 public:
404 HorizontalShadowSource(const std::vector<ShadowValue>& shadows, 445 HorizontalShadowSource(const std::vector<ShadowValue>& shadows,
405 bool fades_down) 446 bool fades_down)
406 : CanvasImageSource(Size(1, GetHeightForShadows(shadows)), false), 447 : CanvasImageSource(Size(1, GetHeightForShadows(shadows)), false),
407 shadows_(shadows), 448 shadows_(shadows),
408 fades_down_(fades_down) {} 449 fades_down_(fades_down) {}
409 ~HorizontalShadowSource() override {} 450 ~HorizontalShadowSource() override {}
410 451
411 // CanvasImageSource overrides: 452 // CanvasImageSource overrides:
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 return ImageSkia(); 626 return ImageSkia();
586 627
587 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); 628 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows);
588 gfx::Size shadow_image_size = source.size(); 629 gfx::Size shadow_image_size = source.size();
589 shadow_image_size.Enlarge(shadow_padding.width(), 630 shadow_image_size.Enlarge(shadow_padding.width(),
590 shadow_padding.height()); 631 shadow_padding.height());
591 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); 632 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size);
592 } 633 }
593 634
594 // static 635 // static
636 ImageSkia ImageSkiaOperations::CreateShadowNinebox(const ShadowValues& shadows,
637 float corner_radius) {
638 auto source = new ShadowNineboxSource(shadows, corner_radius);
639 return ImageSkia(source, source->size());
640 }
641
642 // static
595 ImageSkia ImageSkiaOperations::CreateHorizontalShadow( 643 ImageSkia ImageSkiaOperations::CreateHorizontalShadow(
596 const std::vector<ShadowValue>& shadows, 644 const std::vector<ShadowValue>& shadows,
597 bool fades_down) { 645 bool fades_down) {
598 HorizontalShadowSource* source = 646 auto source = new HorizontalShadowSource(shadows, fades_down);
599 new HorizontalShadowSource(shadows, fades_down);
600 return ImageSkia(source, source->size()); 647 return ImageSkia(source, source->size());
601 } 648 }
602 649
603 // static 650 // static
604 ImageSkia ImageSkiaOperations::CreateRotatedImage( 651 ImageSkia ImageSkiaOperations::CreateRotatedImage(
605 const ImageSkia& source, 652 const ImageSkia& source,
606 SkBitmapOperations::RotationAmount rotation) { 653 SkBitmapOperations::RotationAmount rotation) {
607 if (source.isNull()) 654 if (source.isNull())
608 return ImageSkia(); 655 return ImageSkia();
609 656
(...skipping 10 matching lines...) Expand all
620 if (icon.isNull()) 667 if (icon.isNull())
621 return ImageSkia(); 668 return ImageSkia();
622 669
623 if (badge.isNull()) 670 if (badge.isNull())
624 return icon; 671 return icon;
625 672
626 return ImageSkia(new IconWithBadgeSource(icon, badge), icon.size()); 673 return ImageSkia(new IconWithBadgeSource(icon, badge), icon.size());
627 } 674 }
628 675
629 } // namespace gfx 676 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698