| OLD | NEW |
| 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 Loading... |
| 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 = filter->asNewEffect(textures[0]); |
| 221 filter->asNewEffect(&effect, textures[0]); | |
| 222 GrAssert(NULL != effect); | 221 GrAssert(NULL != effect); |
| 223 return effect; | 222 return effect; |
| 224 } | 223 } |
| 225 | 224 |
| 226 /////////////////////////////////////////////////////////////////////////////// | 225 /////////////////////////////////////////////////////////////////////////////// |
| 227 | 226 |
| 228 const GrBackendEffectFactory& GrMagnifierEffect::getFactory() const { | 227 const GrBackendEffectFactory& GrMagnifierEffect::getFactory() const { |
| 229 return GrTBackendEffectFactory<GrMagnifierEffect>::getInstance(); | 228 return GrTBackendEffectFactory<GrMagnifierEffect>::getInstance(); |
| 230 } | 229 } |
| 231 | 230 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 256 fSrcRect = SkRect::MakeXYWH(x, y, width, height); | 255 fSrcRect = SkRect::MakeXYWH(x, y, width, height); |
| 257 fInset = buffer.readScalar(); | 256 fInset = buffer.readScalar(); |
| 258 } | 257 } |
| 259 | 258 |
| 260 // FIXME: implement single-input semantics | 259 // FIXME: implement single-input semantics |
| 261 SkMagnifierImageFilter::SkMagnifierImageFilter(SkRect srcRect, SkScalar inset) | 260 SkMagnifierImageFilter::SkMagnifierImageFilter(SkRect srcRect, SkScalar inset) |
| 262 : INHERITED(0), fSrcRect(srcRect), fInset(inset) { | 261 : INHERITED(0), fSrcRect(srcRect), fInset(inset) { |
| 263 SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); | 262 SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); |
| 264 } | 263 } |
| 265 | 264 |
| 266 bool SkMagnifierImageFilter::asNewEffect(GrEffectRef** effect, GrTexture* textur
e) const { | |
| 267 #if SK_SUPPORT_GPU | 265 #if SK_SUPPORT_GPU |
| 268 if (effect) { | 266 GrEffectRef* SkMagnifierImageFilter::asNewEffect(GrTexture* texture) const { |
| 269 *effect = GrMagnifierEffect::Create(texture, | 267 return GrMagnifierEffect::Create(texture, |
| 270 fSrcRect.x() / texture->width(), | 268 fSrcRect.x() / texture->width(), |
| 271 fSrcRect.y() / texture->height(), | 269 fSrcRect.y() / texture->height(), |
| 272 texture->width() / fSrcRect.width(), | 270 texture->width() / fSrcRect.width(), |
| 273 texture->height() / fSrcRect.height(), | 271 texture->height() / fSrcRect.height(), |
| 274 fInset / texture->width(), | 272 fInset / texture->width(), |
| 275 fInset / texture->height()); | 273 fInset / texture->height()); |
| 276 } | 274 } |
| 277 return true; | |
| 278 #else | |
| 279 return false; | |
| 280 #endif | 275 #endif |
| 281 } | |
| 282 | 276 |
| 283 void SkMagnifierImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { | 277 void SkMagnifierImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { |
| 284 this->INHERITED::flatten(buffer); | 278 this->INHERITED::flatten(buffer); |
| 285 buffer.writeScalar(fSrcRect.x()); | 279 buffer.writeScalar(fSrcRect.x()); |
| 286 buffer.writeScalar(fSrcRect.y()); | 280 buffer.writeScalar(fSrcRect.y()); |
| 287 buffer.writeScalar(fSrcRect.width()); | 281 buffer.writeScalar(fSrcRect.width()); |
| 288 buffer.writeScalar(fSrcRect.height()); | 282 buffer.writeScalar(fSrcRect.height()); |
| 289 buffer.writeScalar(fInset); | 283 buffer.writeScalar(fInset); |
| 290 } | 284 } |
| 291 | 285 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 341 |
| 348 int x_val = SkMin32(SkScalarFloorToInt(x_interp), width - 1); | 342 int x_val = SkMin32(SkScalarFloorToInt(x_interp), width - 1); |
| 349 int y_val = SkMin32(SkScalarFloorToInt(y_interp), height - 1); | 343 int y_val = SkMin32(SkScalarFloorToInt(y_interp), height - 1); |
| 350 | 344 |
| 351 *dptr = sptr[y_val * width + x_val]; | 345 *dptr = sptr[y_val * width + x_val]; |
| 352 dptr++; | 346 dptr++; |
| 353 } | 347 } |
| 354 } | 348 } |
| 355 return true; | 349 return true; |
| 356 } | 350 } |
| OLD | NEW |