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

Side by Side Diff: ui/gfx/skbitmap_operations.cc

Issue 1123393007: Fix SkBitmapOperations::CreateDropShadow drawing too large a shadow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 5 years, 7 months 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 | « no previous file | 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/skbitmap_operations.h" 5 #include "ui/gfx/skbitmap_operations.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 SkCanvas canvas(image_with_shadow); 734 SkCanvas canvas(image_with_shadow);
735 canvas.translate(SkIntToScalar(shadow_margin.left()), 735 canvas.translate(SkIntToScalar(shadow_margin.left()),
736 SkIntToScalar(shadow_margin.top())); 736 SkIntToScalar(shadow_margin.top()));
737 737
738 SkPaint paint; 738 SkPaint paint;
739 for (size_t i = 0; i < shadows.size(); ++i) { 739 for (size_t i = 0; i < shadows.size(); ++i) {
740 const gfx::ShadowValue& shadow = shadows[i]; 740 const gfx::ShadowValue& shadow = shadows[i];
741 SkBitmap shadow_image = SkBitmapOperations::CreateColorMask(bitmap, 741 SkBitmap shadow_image = SkBitmapOperations::CreateColorMask(bitmap,
742 shadow.color()); 742 shadow.color());
743 743
744 // The blur is halved to produce a shadow that correctly fits within the
745 // |shadow_margin|.
746 SkScalar sigma = SkDoubleToScalar(shadow.blur() / 2);
744 skia::RefPtr<SkBlurImageFilter> filter = 747 skia::RefPtr<SkBlurImageFilter> filter =
745 skia::AdoptRef(SkBlurImageFilter::Create( 748 skia::AdoptRef(SkBlurImageFilter::Create(sigma, sigma));
746 SkDoubleToScalar(shadow.blur()), SkDoubleToScalar(shadow.blur())));
747 paint.setImageFilter(filter.get()); 749 paint.setImageFilter(filter.get());
748 750
749 canvas.saveLayer(0, &paint); 751 canvas.saveLayer(0, &paint);
750 canvas.drawBitmap(shadow_image, 752 canvas.drawBitmap(shadow_image,
751 SkIntToScalar(shadow.x()), 753 SkIntToScalar(shadow.x()),
752 SkIntToScalar(shadow.y())); 754 SkIntToScalar(shadow.y()));
753 canvas.restore(); 755 canvas.restore();
754 } 756 }
755 757
756 canvas.drawBitmap(bitmap, SkIntToScalar(0), SkIntToScalar(0)); 758 canvas.drawBitmap(bitmap, SkIntToScalar(0), SkIntToScalar(0));
(...skipping 27 matching lines...) Expand all
784 canvas.translate(SkFloatToScalar(result.width() * 0.5f), 786 canvas.translate(SkFloatToScalar(result.width() * 0.5f),
785 SkFloatToScalar(result.height() * 0.5f)); 787 SkFloatToScalar(result.height() * 0.5f));
786 canvas.rotate(angle); 788 canvas.rotate(angle);
787 canvas.translate(-SkFloatToScalar(source.width() * 0.5f), 789 canvas.translate(-SkFloatToScalar(source.width() * 0.5f),
788 -SkFloatToScalar(source.height() * 0.5f)); 790 -SkFloatToScalar(source.height() * 0.5f));
789 canvas.drawBitmap(source, 0, 0); 791 canvas.drawBitmap(source, 0, 0);
790 canvas.flush(); 792 canvas.flush();
791 793
792 return result; 794 return result;
793 } 795 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698