| 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/skbitmap_operations.h" | 5 #include "ui/gfx/skbitmap_operations.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "skia/ext/refptr.h" | |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
| 16 #include "third_party/skia/include/core/SkColorFilter.h" | 15 #include "third_party/skia/include/core/SkColorFilter.h" |
| 17 #include "third_party/skia/include/core/SkColorPriv.h" | 16 #include "third_party/skia/include/core/SkColorPriv.h" |
| 18 #include "third_party/skia/include/core/SkUnPreMultiply.h" | 17 #include "third_party/skia/include/core/SkUnPreMultiply.h" |
| 19 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 18 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
| 20 #include "ui/gfx/geometry/insets.h" | 19 #include "ui/gfx/geometry/insets.h" |
| 21 #include "ui/gfx/geometry/point.h" | 20 #include "ui/gfx/geometry/point.h" |
| 22 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
| 23 | 22 |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 | 732 |
| 734 SkPaint paint; | 733 SkPaint paint; |
| 735 for (size_t i = 0; i < shadows.size(); ++i) { | 734 for (size_t i = 0; i < shadows.size(); ++i) { |
| 736 const gfx::ShadowValue& shadow = shadows[i]; | 735 const gfx::ShadowValue& shadow = shadows[i]; |
| 737 SkBitmap shadow_image = SkBitmapOperations::CreateColorMask(bitmap, | 736 SkBitmap shadow_image = SkBitmapOperations::CreateColorMask(bitmap, |
| 738 shadow.color()); | 737 shadow.color()); |
| 739 | 738 |
| 740 // The blur is halved to produce a shadow that correctly fits within the | 739 // The blur is halved to produce a shadow that correctly fits within the |
| 741 // |shadow_margin|. | 740 // |shadow_margin|. |
| 742 SkScalar sigma = SkDoubleToScalar(shadow.blur() / 2); | 741 SkScalar sigma = SkDoubleToScalar(shadow.blur() / 2); |
| 743 skia::RefPtr<SkImageFilter> filter = | 742 paint.setImageFilter(SkBlurImageFilter::Make(sigma, sigma, nullptr)); |
| 744 skia::AdoptRef(SkBlurImageFilter::Create(sigma, sigma)); | |
| 745 paint.setImageFilter(filter.get()); | |
| 746 | 743 |
| 747 canvas.saveLayer(0, &paint); | 744 canvas.saveLayer(0, &paint); |
| 748 canvas.drawBitmap(shadow_image, | 745 canvas.drawBitmap(shadow_image, |
| 749 SkIntToScalar(shadow.x()), | 746 SkIntToScalar(shadow.x()), |
| 750 SkIntToScalar(shadow.y())); | 747 SkIntToScalar(shadow.y())); |
| 751 canvas.restore(); | 748 canvas.restore(); |
| 752 } | 749 } |
| 753 | 750 |
| 754 canvas.drawBitmap(bitmap, SkIntToScalar(0), SkIntToScalar(0)); | 751 canvas.drawBitmap(bitmap, SkIntToScalar(0), SkIntToScalar(0)); |
| 755 return image_with_shadow; | 752 return image_with_shadow; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 785 canvas.translate(SkFloatToScalar(result.width() * 0.5f), | 782 canvas.translate(SkFloatToScalar(result.width() * 0.5f), |
| 786 SkFloatToScalar(result.height() * 0.5f)); | 783 SkFloatToScalar(result.height() * 0.5f)); |
| 787 canvas.rotate(angle); | 784 canvas.rotate(angle); |
| 788 canvas.translate(-SkFloatToScalar(source.width() * 0.5f), | 785 canvas.translate(-SkFloatToScalar(source.width() * 0.5f), |
| 789 -SkFloatToScalar(source.height() * 0.5f)); | 786 -SkFloatToScalar(source.height() * 0.5f)); |
| 790 canvas.drawBitmap(source, 0, 0); | 787 canvas.drawBitmap(source, 0, 0); |
| 791 canvas.flush(); | 788 canvas.flush(); |
| 792 | 789 |
| 793 return result; | 790 return result; |
| 794 } | 791 } |
| OLD | NEW |