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

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

Issue 11418217: Add skia::RefPtr class to wrap ref counted classes from Skia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Drop TNoRef Created 8 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 | Annotate | Revision Log
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 <algorithm> 7 #include <algorithm>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "skia/ext/refptr.h"
11 #include "third_party/skia/include/core/SkBitmap.h" 12 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "third_party/skia/include/core/SkCanvas.h" 13 #include "third_party/skia/include/core/SkCanvas.h"
13 #include "third_party/skia/include/core/SkColorFilter.h" 14 #include "third_party/skia/include/core/SkColorFilter.h"
14 #include "third_party/skia/include/core/SkColorPriv.h" 15 #include "third_party/skia/include/core/SkColorPriv.h"
15 #include "third_party/skia/include/core/SkUnPreMultiply.h" 16 #include "third_party/skia/include/core/SkUnPreMultiply.h"
16 #include "third_party/skia/include/effects/SkBlurImageFilter.h" 17 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
17 #include "ui/gfx/insets.h" 18 #include "ui/gfx/insets.h"
18 #include "ui/gfx/point.h" 19 #include "ui/gfx/point.h"
19 #include "ui/gfx/size.h" 20 #include "ui/gfx/size.h"
20 21
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 DCHECK(bitmap.config() == SkBitmap::kARGB_8888_Config); 753 DCHECK(bitmap.config() == SkBitmap::kARGB_8888_Config);
753 754
754 SkBitmap color_mask; 755 SkBitmap color_mask;
755 color_mask.setConfig(SkBitmap::kARGB_8888_Config, 756 color_mask.setConfig(SkBitmap::kARGB_8888_Config,
756 bitmap.width(), bitmap.height()); 757 bitmap.width(), bitmap.height());
757 color_mask.allocPixels(); 758 color_mask.allocPixels();
758 color_mask.eraseARGB(0, 0, 0, 0); 759 color_mask.eraseARGB(0, 0, 0, 0);
759 760
760 SkCanvas canvas(color_mask); 761 SkCanvas canvas(color_mask);
761 762
762 SkColorFilter* color_filter = SkColorFilter::CreateModeFilter( 763 skia::RefPtr<SkColorFilter> color_filter = SkColorFilter::CreateModeFilter(
763 c, SkXfermode::kSrcIn_Mode); 764 c, SkXfermode::kSrcIn_Mode);
764 SkPaint paint; 765 SkPaint paint;
765 paint.setColorFilter(color_filter)->unref(); 766 paint.setColorFilter(color_filter.get());
766 canvas.drawBitmap(bitmap, SkIntToScalar(0), SkIntToScalar(0), &paint); 767 canvas.drawBitmap(bitmap, SkIntToScalar(0), SkIntToScalar(0), &paint);
767 return color_mask; 768 return color_mask;
768 } 769 }
769 770
770 // static 771 // static
771 SkBitmap SkBitmapOperations::CreateDropShadow( 772 SkBitmap SkBitmapOperations::CreateDropShadow(
772 const SkBitmap& bitmap, 773 const SkBitmap& bitmap,
773 const gfx::ShadowValues& shadows) { 774 const gfx::ShadowValues& shadows) {
774 DCHECK(bitmap.config() == SkBitmap::kARGB_8888_Config); 775 DCHECK(bitmap.config() == SkBitmap::kARGB_8888_Config);
775 776
(...skipping 12 matching lines...) Expand all
788 SkCanvas canvas(image_with_shadow); 789 SkCanvas canvas(image_with_shadow);
789 canvas.translate(SkIntToScalar(shadow_margin.left()), 790 canvas.translate(SkIntToScalar(shadow_margin.left()),
790 SkIntToScalar(shadow_margin.top())); 791 SkIntToScalar(shadow_margin.top()));
791 792
792 SkPaint paint; 793 SkPaint paint;
793 for (size_t i = 0; i < shadows.size(); ++i) { 794 for (size_t i = 0; i < shadows.size(); ++i) {
794 const gfx::ShadowValue& shadow = shadows[i]; 795 const gfx::ShadowValue& shadow = shadows[i];
795 SkBitmap shadow_image = SkBitmapOperations::CreateColorMask(bitmap, 796 SkBitmap shadow_image = SkBitmapOperations::CreateColorMask(bitmap,
796 shadow.color()); 797 shadow.color());
797 798
798 paint.setImageFilter( 799 skia::RefPtr<SkBlurImageFilter> filter =
799 new SkBlurImageFilter(SkDoubleToScalar(shadow.blur()), 800 new SkBlurImageFilter(SkDoubleToScalar(shadow.blur()),
800 SkDoubleToScalar(shadow.blur())))->unref(); 801 SkDoubleToScalar(shadow.blur()));
802 paint.setImageFilter(filter.get());
801 803
802 canvas.saveLayer(0, &paint); 804 canvas.saveLayer(0, &paint);
803 canvas.drawBitmap(shadow_image, 805 canvas.drawBitmap(shadow_image,
804 SkIntToScalar(shadow.x()), 806 SkIntToScalar(shadow.x()),
805 SkIntToScalar(shadow.y())); 807 SkIntToScalar(shadow.y()));
806 canvas.restore(); 808 canvas.restore();
807 } 809 }
808 810
809 canvas.drawBitmap(bitmap, SkIntToScalar(0), SkIntToScalar(0)); 811 canvas.drawBitmap(bitmap, SkIntToScalar(0), SkIntToScalar(0));
810 return image_with_shadow; 812 return image_with_shadow;
811 } 813 }
OLDNEW
« skia/ext/refptr_unittest.cc ('K') | « ui/gfx/render_text.cc ('k') | ui/gfx/skia_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698