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

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

Issue 177343005: Use SkLayerDrawLooper::Builder to construct SkLayerDrawLooper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: looperBuilder -> looper_builder Created 6 years, 9 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 | Annotate | Revision Log
« 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/skia_util.h" 5 #include "ui/gfx/skia_util.h"
6 6
7 #include "third_party/skia/include/core/SkBitmap.h" 7 #include "third_party/skia/include/core/SkBitmap.h"
8 #include "third_party/skia/include/core/SkColorFilter.h" 8 #include "third_party/skia/include/core/SkColorFilter.h"
9 #include "third_party/skia/include/core/SkColorPriv.h" 9 #include "third_party/skia/include/core/SkColorPriv.h"
10 #include "third_party/skia/include/core/SkUnPreMultiply.h" 10 #include "third_party/skia/include/core/SkUnPreMultiply.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 return skia::AdoptRef(SkGradientShader::CreateLinear( 98 return skia::AdoptRef(SkGradientShader::CreateLinear(
99 grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode)); 99 grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode));
100 } 100 }
101 101
102 skia::RefPtr<SkDrawLooper> CreateShadowDrawLooper( 102 skia::RefPtr<SkDrawLooper> CreateShadowDrawLooper(
103 const std::vector<ShadowValue>& shadows) { 103 const std::vector<ShadowValue>& shadows) {
104 if (shadows.empty()) 104 if (shadows.empty())
105 return skia::RefPtr<SkDrawLooper>(); 105 return skia::RefPtr<SkDrawLooper>();
106 106
107 skia::RefPtr<SkLayerDrawLooper> looper = 107 SkLayerDrawLooper::Builder looper_builder;
108 skia::AdoptRef(new SkLayerDrawLooper);
109 108
110 looper->addLayer(); // top layer of the original. 109 looper_builder.addLayer(); // top layer of the original.
111 110
112 SkLayerDrawLooper::LayerInfo layer_info; 111 SkLayerDrawLooper::LayerInfo layer_info;
113 layer_info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; 112 layer_info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit;
114 layer_info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit; 113 layer_info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit;
115 layer_info.fColorMode = SkXfermode::kSrc_Mode; 114 layer_info.fColorMode = SkXfermode::kSrc_Mode;
116 115
117 for (size_t i = 0; i < shadows.size(); ++i) { 116 for (size_t i = 0; i < shadows.size(); ++i) {
118 const ShadowValue& shadow = shadows[i]; 117 const ShadowValue& shadow = shadows[i];
119 118
120 layer_info.fOffset.set(SkIntToScalar(shadow.x()), 119 layer_info.fOffset.set(SkIntToScalar(shadow.x()),
121 SkIntToScalar(shadow.y())); 120 SkIntToScalar(shadow.y()));
122 121
123 // SkBlurMaskFilter's blur radius defines the range to extend the blur from 122 // SkBlurMaskFilter's blur radius defines the range to extend the blur from
124 // original mask, which is half of blur amount as defined in ShadowValue. 123 // original mask, which is half of blur amount as defined in ShadowValue.
125 skia::RefPtr<SkMaskFilter> blur_mask = skia::AdoptRef( 124 skia::RefPtr<SkMaskFilter> blur_mask = skia::AdoptRef(
126 SkBlurMaskFilter::Create(SkDoubleToScalar(shadow.blur() / 2), 125 SkBlurMaskFilter::Create(SkDoubleToScalar(shadow.blur() / 2),
127 SkBlurMaskFilter::kNormal_BlurStyle, 126 SkBlurMaskFilter::kNormal_BlurStyle,
128 SkBlurMaskFilter::kHighQuality_BlurFlag)); 127 SkBlurMaskFilter::kHighQuality_BlurFlag));
129 skia::RefPtr<SkColorFilter> color_filter = skia::AdoptRef( 128 skia::RefPtr<SkColorFilter> color_filter = skia::AdoptRef(
130 SkColorFilter::CreateModeFilter(shadow.color(), 129 SkColorFilter::CreateModeFilter(shadow.color(),
131 SkXfermode::kSrcIn_Mode)); 130 SkXfermode::kSrcIn_Mode));
132 131
133 SkPaint* paint = looper->addLayer(layer_info); 132 SkPaint* paint = looper_builder.addLayer(layer_info);
134 paint->setMaskFilter(blur_mask.get()); 133 paint->setMaskFilter(blur_mask.get());
135 paint->setColorFilter(color_filter.get()); 134 paint->setColorFilter(color_filter.get());
136 } 135 }
137 136
138 return looper; 137 return skia::AdoptRef<SkDrawLooper>(looper_builder.detachLooper());
139 } 138 }
140 139
141 bool BitmapsAreEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2) { 140 bool BitmapsAreEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2) {
142 void* addr1 = NULL; 141 void* addr1 = NULL;
143 void* addr2 = NULL; 142 void* addr2 = NULL;
144 size_t size1 = 0; 143 size_t size1 = 0;
145 size_t size2 = 0; 144 size_t size2 = 0;
146 145
147 bitmap1.lockPixels(); 146 bitmap1.lockPixels();
148 addr1 = bitmap1.getAddr32(0, 0); 147 addr1 = bitmap1.getAddr32(0, 0);
(...skipping 26 matching lines...) Expand all
175 } else { 174 } else {
176 rgba[i + 0] = SkGetPackedR32(pixel_in); 175 rgba[i + 0] = SkGetPackedR32(pixel_in);
177 rgba[i + 1] = SkGetPackedG32(pixel_in); 176 rgba[i + 1] = SkGetPackedG32(pixel_in);
178 rgba[i + 2] = SkGetPackedB32(pixel_in); 177 rgba[i + 2] = SkGetPackedB32(pixel_in);
179 rgba[i + 3] = alpha; 178 rgba[i + 3] = alpha;
180 } 179 }
181 } 180 }
182 } 181 }
183 182
184 } // namespace gfx 183 } // namespace gfx
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