| 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 15 matching lines...) Expand all Loading... |
| 26 class GrMagnifierEffect : public GrSingleTextureEffect { | 26 class GrMagnifierEffect : public GrSingleTextureEffect { |
| 27 | 27 |
| 28 public: | 28 public: |
| 29 static GrFragmentProcessor* Create(GrTexture* texture, | 29 static GrFragmentProcessor* Create(GrTexture* texture, |
| 30 const SkRect& bounds, | 30 const SkRect& bounds, |
| 31 float xOffset, | 31 float xOffset, |
| 32 float yOffset, | 32 float yOffset, |
| 33 float xInvZoom, | 33 float xInvZoom, |
| 34 float yInvZoom, | 34 float yInvZoom, |
| 35 float xInvInset, | 35 float xInvInset, |
| 36 float yInvInset) { | 36 float yInvInset, |
| 37 return new GrMagnifierEffect(texture, bounds, xOffset, yOffset, xInvZoom
, yInvZoom, xInvInset, | 37 GrRenderTarget* dst) { |
| 38 yInvInset); | 38 return new GrMagnifierEffect(texture, bounds, xOffset, yOffset, xInvZoom
, |
| 39 yInvZoom, xInvInset, yInvInset, dst); |
| 39 } | 40 } |
| 40 | 41 |
| 41 virtual ~GrMagnifierEffect() {}; | 42 virtual ~GrMagnifierEffect() {}; |
| 42 | 43 |
| 43 const char* name() const override { return "Magnifier"; } | 44 const char* name() const override { return "Magnifier"; } |
| 44 | 45 |
| 45 const SkRect& bounds() const { return fBounds; } // Bounds of source imag
e. | 46 const SkRect& bounds() const { return fBounds; } // Bounds of source imag
e. |
| 46 // Offset to apply to zoomed pixels, (srcRect position / texture size). | 47 // Offset to apply to zoomed pixels, (srcRect position / texture size). |
| 47 float x_offset() const { return fXOffset; } | 48 float x_offset() const { return fXOffset; } |
| 48 float y_offset() const { return fYOffset; } | 49 float y_offset() const { return fYOffset; } |
| 49 | 50 |
| 50 // Scale to apply to zoomed pixels (srcRect size / bounds size). | 51 // Scale to apply to zoomed pixels (srcRect size / bounds size). |
| 51 float x_inv_zoom() const { return fXInvZoom; } | 52 float x_inv_zoom() const { return fXInvZoom; } |
| 52 float y_inv_zoom() const { return fYInvZoom; } | 53 float y_inv_zoom() const { return fYInvZoom; } |
| 53 | 54 |
| 54 // 1/radius over which to transition from unzoomed to zoomed pixels (bounds
size / inset). | 55 // 1/radius over which to transition from unzoomed to zoomed pixels (bounds
size / inset). |
| 55 float x_inv_inset() const { return fXInvInset; } | 56 float x_inv_inset() const { return fXInvInset; } |
| 56 float y_inv_inset() const { return fYInvInset; } | 57 float y_inv_inset() const { return fYInvInset; } |
| 57 | 58 |
| 58 private: | 59 private: |
| 59 GrMagnifierEffect(GrTexture* texture, | 60 GrMagnifierEffect(GrTexture* texture, |
| 60 const SkRect& bounds, | 61 const SkRect& bounds, |
| 61 float xOffset, | 62 float xOffset, |
| 62 float yOffset, | 63 float yOffset, |
| 63 float xInvZoom, | 64 float xInvZoom, |
| 64 float yInvZoom, | 65 float yInvZoom, |
| 65 float xInvInset, | 66 float xInvInset, |
| 66 float yInvInset) | 67 float yInvInset, GrRenderTarget* dst) |
| 67 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture)
) | 68 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture)
, kLocal_GrCoordSet, dst) |
| 68 , fBounds(bounds) | 69 , fBounds(bounds) |
| 69 , fXOffset(xOffset) | 70 , fXOffset(xOffset) |
| 70 , fYOffset(yOffset) | 71 , fYOffset(yOffset) |
| 71 , fXInvZoom(xInvZoom) | 72 , fXInvZoom(xInvZoom) |
| 72 , fYInvZoom(yInvZoom) | 73 , fYInvZoom(yInvZoom) |
| 73 , fXInvInset(xInvInset) | 74 , fXInvInset(xInvInset) |
| 74 , fYInvInset(yInvInset) { | 75 , fYInvInset(yInvInset) { |
| 75 this->initClassID<GrMagnifierEffect>(); | 76 this->initClassID<GrMagnifierEffect>(); |
| 76 } | 77 } |
| 77 | 78 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 uint32_t inset = d->fRandom->nextULessThan(kMaxInset); | 205 uint32_t inset = d->fRandom->nextULessThan(kMaxInset); |
| 205 | 206 |
| 206 GrFragmentProcessor* effect = GrMagnifierEffect::Create( | 207 GrFragmentProcessor* effect = GrMagnifierEffect::Create( |
| 207 texture, | 208 texture, |
| 208 SkRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight)), | 209 SkRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight)), |
| 209 (float) width / texture->width(), | 210 (float) width / texture->width(), |
| 210 (float) height / texture->height(), | 211 (float) height / texture->height(), |
| 211 texture->width() / (float) x, | 212 texture->width() / (float) x, |
| 212 texture->height() / (float) y, | 213 texture->height() / (float) y, |
| 213 (float) inset / texture->width(), | 214 (float) inset / texture->width(), |
| 214 (float) inset / texture->height()); | 215 (float) inset / texture->height(), NULL); |
| 215 SkASSERT(effect); | 216 SkASSERT(effect); |
| 216 return effect; | 217 return effect; |
| 217 } | 218 } |
| 218 | 219 |
| 219 /////////////////////////////////////////////////////////////////////////////// | 220 /////////////////////////////////////////////////////////////////////////////// |
| 220 | 221 |
| 221 bool GrMagnifierEffect::onIsEqual(const GrFragmentProcessor& sBase) const { | 222 bool GrMagnifierEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
| 222 const GrMagnifierEffect& s = sBase.cast<GrMagnifierEffect>(); | 223 const GrMagnifierEffect& s = sBase.cast<GrMagnifierEffect>(); |
| 223 return (this->fBounds == s.fBounds && | 224 return (this->fBounds == s.fBounds && |
| 224 this->fXOffset == s.fXOffset && | 225 this->fXOffset == s.fXOffset && |
| (...skipping 28 matching lines...) Expand all Loading... |
| 253 | 254 |
| 254 SkMagnifierImageFilter::SkMagnifierImageFilter(const SkRect& srcRect, SkScalar i
nset, | 255 SkMagnifierImageFilter::SkMagnifierImageFilter(const SkRect& srcRect, SkScalar i
nset, |
| 255 SkImageFilter* input) | 256 SkImageFilter* input) |
| 256 : INHERITED(1, &input), fSrcRect(srcRect), fInset(inset) { | 257 : INHERITED(1, &input), fSrcRect(srcRect), fInset(inset) { |
| 257 SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); | 258 SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); |
| 258 } | 259 } |
| 259 | 260 |
| 260 #if SK_SUPPORT_GPU | 261 #if SK_SUPPORT_GPU |
| 261 bool SkMagnifierImageFilter::asFragmentProcessor(GrFragmentProcessor** fp, | 262 bool SkMagnifierImageFilter::asFragmentProcessor(GrFragmentProcessor** fp, |
| 262 GrTexture* texture, const SkMat
rix&, | 263 GrTexture* texture, const SkMat
rix&, |
| 263 const SkIRect&bounds) const { | 264 const SkIRect&bounds, GrRenderT
arget* dst) const { |
| 264 if (fp) { | 265 if (fp) { |
| 265 SkScalar yOffset = texture->origin() == kTopLeft_GrSurfaceOrigin ? fSrcR
ect.y() : | 266 SkScalar yOffset = texture->origin() == kTopLeft_GrSurfaceOrigin ? fSrcR
ect.y() : |
| 266 texture->height() - fSrcRect.height() * texture->height() / bounds.he
ight() | 267 texture->height() - fSrcRect.height() * texture->height() / bounds.he
ight() |
| 267 - fSrcRect.y(); | 268 - fSrcRect.y(); |
| 268 int boundsY = (texture->origin() == kTopLeft_GrSurfaceOrigin) ? bounds.y
() : | 269 int boundsY = (texture->origin() == kTopLeft_GrSurfaceOrigin) ? bounds.y
() : |
| 269 (texture->height() - bounds.height()); | 270 (texture->height() - bounds.height()); |
| 270 SkRect effectBounds = SkRect::MakeXYWH( | 271 SkRect effectBounds = SkRect::MakeXYWH( |
| 271 SkIntToScalar(bounds.x()) / texture->width(), | 272 SkIntToScalar(bounds.x()) / texture->width(), |
| 272 SkIntToScalar(boundsY) / texture->height(), | 273 SkIntToScalar(boundsY) / texture->height(), |
| 273 SkIntToScalar(texture->width()) / bounds.width(), | 274 SkIntToScalar(texture->width()) / bounds.width(), |
| 274 SkIntToScalar(texture->height()) / bounds.height()); | 275 SkIntToScalar(texture->height()) / bounds.height()); |
| 275 SkScalar invInset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1; | 276 SkScalar invInset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1; |
| 276 *fp = GrMagnifierEffect::Create(texture, | 277 *fp = GrMagnifierEffect::Create(texture, |
| 277 effectBounds, | 278 effectBounds, |
| 278 fSrcRect.x() / texture->width(), | 279 fSrcRect.x() / texture->width(), |
| 279 yOffset / texture->height(), | 280 yOffset / texture->height(), |
| 280 fSrcRect.width() / bounds.width(), | 281 fSrcRect.width() / bounds.width(), |
| 281 fSrcRect.height() / bounds.height(), | 282 fSrcRect.height() / bounds.height(), |
| 282 bounds.width() * invInset, | 283 bounds.width() * invInset, |
| 283 bounds.height() * invInset); | 284 bounds.height() * invInset, dst); |
| 284 } | 285 } |
| 285 return true; | 286 return true; |
| 286 } | 287 } |
| 287 #endif | 288 #endif |
| 288 | 289 |
| 289 SkFlattenable* SkMagnifierImageFilter::CreateProc(SkReadBuffer& buffer) { | 290 SkFlattenable* SkMagnifierImageFilter::CreateProc(SkReadBuffer& buffer) { |
| 290 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 291 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
| 291 SkRect src; | 292 SkRect src; |
| 292 buffer.readRect(&src); | 293 buffer.readRect(&src); |
| 293 return Create(src, buffer.readScalar(), common.getInput(0)); | 294 return Create(src, buffer.readScalar(), common.getInput(0)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 | 371 |
| 371 #ifndef SK_IGNORE_TO_STRING | 372 #ifndef SK_IGNORE_TO_STRING |
| 372 void SkMagnifierImageFilter::toString(SkString* str) const { | 373 void SkMagnifierImageFilter::toString(SkString* str) const { |
| 373 str->appendf("SkMagnifierImageFilter: ("); | 374 str->appendf("SkMagnifierImageFilter: ("); |
| 374 str->appendf("src: (%f,%f,%f,%f) ", | 375 str->appendf("src: (%f,%f,%f,%f) ", |
| 375 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto
m); | 376 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto
m); |
| 376 str->appendf("inset: %f", fInset); | 377 str->appendf("inset: %f", fInset); |
| 377 str->append(")"); | 378 str->append(")"); |
| 378 } | 379 } |
| 379 #endif | 380 #endif |
| OLD | NEW |