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

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

Issue 1363253002: ui/gfx: use SkLayerDrawLooper::Builder::addLayerOnTop instead of addLayer Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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/skia_util.h" 5 #include "ui/gfx/skia_util.h"
6 6
7 #include "base/containers/adapters.h"
7 #include "third_party/skia/include/core/SkBitmap.h" 8 #include "third_party/skia/include/core/SkBitmap.h"
8 #include "third_party/skia/include/core/SkColorFilter.h" 9 #include "third_party/skia/include/core/SkColorFilter.h"
9 #include "third_party/skia/include/core/SkColorPriv.h" 10 #include "third_party/skia/include/core/SkColorPriv.h"
10 #include "third_party/skia/include/core/SkUnPreMultiply.h" 11 #include "third_party/skia/include/core/SkUnPreMultiply.h"
11 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" 12 #include "third_party/skia/include/effects/SkBlurMaskFilter.h"
12 #include "third_party/skia/include/effects/SkGradientShader.h" 13 #include "third_party/skia/include/effects/SkGradientShader.h"
13 #include "third_party/skia/include/effects/SkLayerDrawLooper.h" 14 #include "third_party/skia/include/effects/SkLayerDrawLooper.h"
14 #include "ui/gfx/geometry/quad_f.h" 15 #include "ui/gfx/geometry/quad_f.h"
15 #include "ui/gfx/geometry/rect.h" 16 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/rect_f.h" 17 #include "ui/gfx/geometry/rect_f.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return radius > 0 ? SkDoubleToScalar(0.57735f * radius + 0.5) : 0; 120 return radius > 0 ? SkDoubleToScalar(0.57735f * radius + 0.5) : 0;
120 } 121 }
121 122
122 skia::RefPtr<SkDrawLooper> CreateShadowDrawLooper( 123 skia::RefPtr<SkDrawLooper> CreateShadowDrawLooper(
123 const std::vector<ShadowValue>& shadows) { 124 const std::vector<ShadowValue>& shadows) {
124 if (shadows.empty()) 125 if (shadows.empty())
125 return skia::RefPtr<SkDrawLooper>(); 126 return skia::RefPtr<SkDrawLooper>();
126 127
127 SkLayerDrawLooper::Builder looper_builder; 128 SkLayerDrawLooper::Builder looper_builder;
128 129
129 looper_builder.addLayer(); // top layer of the original.
130
131 SkLayerDrawLooper::LayerInfo layer_info; 130 SkLayerDrawLooper::LayerInfo layer_info;
132 layer_info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; 131 layer_info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit;
133 layer_info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit; 132 layer_info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit;
134 layer_info.fColorMode = SkXfermode::kSrc_Mode; 133 layer_info.fColorMode = SkXfermode::kSrc_Mode;
135 134
136 for (size_t i = 0; i < shadows.size(); ++i) { 135 for (const ShadowValue& shadow : base::Reversed(shadows)) {
137 const ShadowValue& shadow = shadows[i];
138
139 layer_info.fOffset.set(SkIntToScalar(shadow.x()), 136 layer_info.fOffset.set(SkIntToScalar(shadow.x()),
140 SkIntToScalar(shadow.y())); 137 SkIntToScalar(shadow.y()));
141 138
142 // SkBlurMaskFilter's blur radius defines the range to extend the blur from 139 // SkBlurMaskFilter's blur radius defines the range to extend the blur from
143 // original mask, which is half of blur amount as defined in ShadowValue. 140 // original mask, which is half of blur amount as defined in ShadowValue.
144 skia::RefPtr<SkMaskFilter> blur_mask = skia::AdoptRef( 141 skia::RefPtr<SkMaskFilter> blur_mask = skia::AdoptRef(
145 SkBlurMaskFilter::Create(kNormal_SkBlurStyle, 142 SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
146 RadiusToSigma(shadow.blur() / 2), 143 RadiusToSigma(shadow.blur() / 2),
147 SkBlurMaskFilter::kHighQuality_BlurFlag)); 144 SkBlurMaskFilter::kHighQuality_BlurFlag));
148 skia::RefPtr<SkColorFilter> color_filter = skia::AdoptRef( 145 skia::RefPtr<SkColorFilter> color_filter = skia::AdoptRef(
149 SkColorFilter::CreateModeFilter(shadow.color(), 146 SkColorFilter::CreateModeFilter(shadow.color(),
150 SkXfermode::kSrcIn_Mode)); 147 SkXfermode::kSrcIn_Mode));
151 148
152 SkPaint* paint = looper_builder.addLayer(layer_info); 149 SkPaint* paint = looper_builder.addLayerOnTop(layer_info);
153 paint->setMaskFilter(blur_mask.get()); 150 paint->setMaskFilter(blur_mask.get());
154 paint->setColorFilter(color_filter.get()); 151 paint->setColorFilter(color_filter.get());
155 } 152 }
156 153
154 // Top layer of the original.
155 looper_builder.addLayerOnTop(SkLayerDrawLooper::LayerInfo());
156
157 return skia::AdoptRef<SkDrawLooper>(looper_builder.detachLooper()); 157 return skia::AdoptRef<SkDrawLooper>(looper_builder.detachLooper());
158 } 158 }
159 159
160 bool BitmapsAreEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2) { 160 bool BitmapsAreEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2) {
161 void* addr1 = NULL; 161 void* addr1 = NULL;
162 void* addr2 = NULL; 162 void* addr2 = NULL;
163 size_t size1 = 0; 163 size_t size1 = 0;
164 size_t size2 = 0; 164 size_t size2 = 0;
165 165
166 bitmap1.lockPixels(); 166 bitmap1.lockPixels();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } 201 }
202 202
203 void QuadFToSkPoints(const gfx::QuadF& quad, SkPoint points[4]) { 203 void QuadFToSkPoints(const gfx::QuadF& quad, SkPoint points[4]) {
204 points[0] = SkPoint::Make(quad.p1().x(), quad.p1().y()); 204 points[0] = SkPoint::Make(quad.p1().x(), quad.p1().y());
205 points[1] = SkPoint::Make(quad.p2().x(), quad.p2().y()); 205 points[1] = SkPoint::Make(quad.p2().x(), quad.p2().y());
206 points[2] = SkPoint::Make(quad.p3().x(), quad.p3().y()); 206 points[2] = SkPoint::Make(quad.p3().x(), quad.p3().y());
207 points[3] = SkPoint::Make(quad.p4().x(), quad.p4().y()); 207 points[3] = SkPoint::Make(quad.p4().x(), quad.p4().y());
208 } 208 }
209 209
210 } // namespace gfx 210 } // 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