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

Side by Side Diff: src/effects/SkMagnifierImageFilter.cpp

Issue 13602013: Allow single-pass filters (which use asNewEffect()) to participate in the image filter DAG. This w… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix return value of SkImageFilter::asNewEffect(). Created 7 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The Android Open Source Project 2 * Copyright 2012 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkMagnifierImageFilter.h" 9 #include "SkMagnifierImageFilter.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 GrTexture** textures) { 205 GrTexture** textures) {
206 const int kMaxWidth = 200; 206 const int kMaxWidth = 200;
207 const int kMaxHeight = 200; 207 const int kMaxHeight = 200;
208 const int kMaxInset = 20; 208 const int kMaxInset = 20;
209 uint32_t width = random->nextULessThan(kMaxWidth); 209 uint32_t width = random->nextULessThan(kMaxWidth);
210 uint32_t height = random->nextULessThan(kMaxHeight); 210 uint32_t height = random->nextULessThan(kMaxHeight);
211 uint32_t x = random->nextULessThan(kMaxWidth - width); 211 uint32_t x = random->nextULessThan(kMaxWidth - width);
212 uint32_t y = random->nextULessThan(kMaxHeight - height); 212 uint32_t y = random->nextULessThan(kMaxHeight - height);
213 SkScalar inset = SkIntToScalar(random->nextULessThan(kMaxInset)); 213 SkScalar inset = SkIntToScalar(random->nextULessThan(kMaxInset));
214 214
215 SkAutoTUnref<SkImageFilter> filter( 215 SkAutoTUnref<SkMagnifierImageFilter> filter(
216 new SkMagnifierImageFilter( 216 new SkMagnifierImageFilter(
217 SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), 217 SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
218 SkIntToScalar(width), SkIntToScalar(height)), 218 SkIntToScalar(width), SkIntToScalar(height)),
219 inset)); 219 inset));
220 GrEffectRef* effect; 220 GrEffectRef* effect;
221 filter->asNewEffect(&effect, textures[0]); 221 filter->asNewEffect(&effect, textures[0]);
222 GrAssert(NULL != effect); 222 GrAssert(NULL != effect);
223 return effect; 223 return effect;
224 } 224 }
225 225
(...skipping 30 matching lines...) Expand all
256 fSrcRect = SkRect::MakeXYWH(x, y, width, height); 256 fSrcRect = SkRect::MakeXYWH(x, y, width, height);
257 fInset = buffer.readScalar(); 257 fInset = buffer.readScalar();
258 } 258 }
259 259
260 // FIXME: implement single-input semantics 260 // FIXME: implement single-input semantics
261 SkMagnifierImageFilter::SkMagnifierImageFilter(SkRect srcRect, SkScalar inset) 261 SkMagnifierImageFilter::SkMagnifierImageFilter(SkRect srcRect, SkScalar inset)
262 : INHERITED(0), fSrcRect(srcRect), fInset(inset) { 262 : INHERITED(0), fSrcRect(srcRect), fInset(inset) {
263 SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); 263 SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0);
264 } 264 }
265 265
266 #if SK_SUPPORT_GPU
266 bool SkMagnifierImageFilter::asNewEffect(GrEffectRef** effect, GrTexture* textur e) const { 267 bool SkMagnifierImageFilter::asNewEffect(GrEffectRef** effect, GrTexture* textur e) const {
267 #if SK_SUPPORT_GPU
268 if (effect) { 268 if (effect) {
269 *effect = GrMagnifierEffect::Create(texture, 269 *effect = GrMagnifierEffect::Create(texture,
270 fSrcRect.x() / texture->width(), 270 fSrcRect.x() / texture->width(),
271 fSrcRect.y() / texture->height(), 271 fSrcRect.y() / texture->height(),
272 texture->width() / fSrcRect.width(), 272 texture->width() / fSrcRect.width(),
273 texture->height() / fSrcRect.height(), 273 texture->height() / fSrcRect.height( ),
274 fInset / texture->width(), 274 fInset / texture->width(),
275 fInset / texture->height()); 275 fInset / texture->height());
276 } 276 }
277 return true; 277 return true;
278 #else 278 }
279 return false;
280 #endif 279 #endif
281 }
282 280
283 void SkMagnifierImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { 281 void SkMagnifierImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
284 this->INHERITED::flatten(buffer); 282 this->INHERITED::flatten(buffer);
285 buffer.writeScalar(fSrcRect.x()); 283 buffer.writeScalar(fSrcRect.x());
286 buffer.writeScalar(fSrcRect.y()); 284 buffer.writeScalar(fSrcRect.y());
287 buffer.writeScalar(fSrcRect.width()); 285 buffer.writeScalar(fSrcRect.width());
288 buffer.writeScalar(fSrcRect.height()); 286 buffer.writeScalar(fSrcRect.height());
289 buffer.writeScalar(fInset); 287 buffer.writeScalar(fInset);
290 } 288 }
291 289
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 345
348 int x_val = SkMin32(SkScalarFloorToInt(x_interp), width - 1); 346 int x_val = SkMin32(SkScalarFloorToInt(x_interp), width - 1);
349 int y_val = SkMin32(SkScalarFloorToInt(y_interp), height - 1); 347 int y_val = SkMin32(SkScalarFloorToInt(y_interp), height - 1);
350 348
351 *dptr = sptr[y_val * width + x_val]; 349 *dptr = sptr[y_val * width + x_val];
352 dptr++; 350 dptr++;
353 } 351 }
354 } 352 }
355 return true; 353 return true;
356 } 354 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698