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" |
11 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
12 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
13 #include "SkValidationUtils.h" | 13 #include "SkValidationUtils.h" |
14 | 14 |
15 //////////////////////////////////////////////////////////////////////////////// | 15 //////////////////////////////////////////////////////////////////////////////// |
16 #if SK_SUPPORT_GPU | 16 #if SK_SUPPORT_GPU |
17 #include "GrInvariantOutput.h" | 17 #include "GrInvariantOutput.h" |
18 #include "effects/GrSingleTextureEffect.h" | 18 #include "effects/GrSingleTextureEffect.h" |
19 #include "gl/GrGLProcessor.h" | 19 #include "gl/GrGLProcessor.h" |
20 #include "gl/GrGLTexture.h" | 20 #include "gl/GrGLTexture.h" |
21 #include "gl/builders/GrGLProgramBuilder.h" | 21 #include "gl/builders/GrGLProgramBuilder.h" |
22 | 22 |
23 class GrMagnifierEffect : public GrSingleTextureEffect { | 23 class GrMagnifierEffect : public GrSingleTextureEffect { |
24 | 24 |
25 public: | 25 public: |
26 static GrFragmentProcessor* Create(GrTexture* texture, | 26 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, |
| 27 GrTexture* texture, |
27 const SkRect& bounds, | 28 const SkRect& bounds, |
28 float xOffset, | 29 float xOffset, |
29 float yOffset, | 30 float yOffset, |
30 float xInvZoom, | 31 float xInvZoom, |
31 float yInvZoom, | 32 float yInvZoom, |
32 float xInvInset, | 33 float xInvInset, |
33 float yInvInset) { | 34 float yInvInset) { |
34 return SkNEW_ARGS(GrMagnifierEffect, (texture, | 35 return SkNEW_ARGS(GrMagnifierEffect, (procDataManager, |
| 36 texture, |
35 bounds, | 37 bounds, |
36 xOffset, | 38 xOffset, |
37 yOffset, | 39 yOffset, |
38 xInvZoom, | 40 xInvZoom, |
39 yInvZoom, | 41 yInvZoom, |
40 xInvInset, | 42 xInvInset, |
41 yInvInset)); | 43 yInvInset)); |
42 } | 44 } |
43 | 45 |
44 virtual ~GrMagnifierEffect() {}; | 46 virtual ~GrMagnifierEffect() {}; |
(...skipping 11 matching lines...) Expand all Loading... |
56 | 58 |
57 // Scale to apply to zoomed pixels (srcRect size / bounds size). | 59 // Scale to apply to zoomed pixels (srcRect size / bounds size). |
58 float x_inv_zoom() const { return fXInvZoom; } | 60 float x_inv_zoom() const { return fXInvZoom; } |
59 float y_inv_zoom() const { return fYInvZoom; } | 61 float y_inv_zoom() const { return fYInvZoom; } |
60 | 62 |
61 // 1/radius over which to transition from unzoomed to zoomed pixels (bounds
size / inset). | 63 // 1/radius over which to transition from unzoomed to zoomed pixels (bounds
size / inset). |
62 float x_inv_inset() const { return fXInvInset; } | 64 float x_inv_inset() const { return fXInvInset; } |
63 float y_inv_inset() const { return fYInvInset; } | 65 float y_inv_inset() const { return fYInvInset; } |
64 | 66 |
65 private: | 67 private: |
66 GrMagnifierEffect(GrTexture* texture, | 68 GrMagnifierEffect(GrProcessorDataManager* procDataManager, |
| 69 GrTexture* texture, |
67 const SkRect& bounds, | 70 const SkRect& bounds, |
68 float xOffset, | 71 float xOffset, |
69 float yOffset, | 72 float yOffset, |
70 float xInvZoom, | 73 float xInvZoom, |
71 float yInvZoom, | 74 float yInvZoom, |
72 float xInvInset, | 75 float xInvInset, |
73 float yInvInset) | 76 float yInvInset) |
74 : GrSingleTextureEffect(texture, GrCoordTransform::MakeDivByTextureWHMat
rix(texture)) | 77 : INHERITED(procDataManager, texture, GrCoordTransform::MakeDivByTexture
WHMatrix(texture)) |
75 , fBounds(bounds) | 78 , fBounds(bounds) |
76 , fXOffset(xOffset) | 79 , fXOffset(xOffset) |
77 , fYOffset(yOffset) | 80 , fYOffset(yOffset) |
78 , fXInvZoom(xInvZoom) | 81 , fXInvZoom(xInvZoom) |
79 , fYInvZoom(yInvZoom) | 82 , fYInvZoom(yInvZoom) |
80 , fXInvInset(xInvInset) | 83 , fXInvInset(xInvInset) |
81 , fYInvInset(yInvInset) { | 84 , fYInvInset(yInvInset) { |
82 this->initClassID<GrMagnifierEffect>(); | 85 this->initClassID<GrMagnifierEffect>(); |
83 } | 86 } |
84 | 87 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 const int kMaxWidth = 200; | 215 const int kMaxWidth = 200; |
213 const int kMaxHeight = 200; | 216 const int kMaxHeight = 200; |
214 const int kMaxInset = 20; | 217 const int kMaxInset = 20; |
215 uint32_t width = d->fRandom->nextULessThan(kMaxWidth); | 218 uint32_t width = d->fRandom->nextULessThan(kMaxWidth); |
216 uint32_t height = d->fRandom->nextULessThan(kMaxHeight); | 219 uint32_t height = d->fRandom->nextULessThan(kMaxHeight); |
217 uint32_t x = d->fRandom->nextULessThan(kMaxWidth - width); | 220 uint32_t x = d->fRandom->nextULessThan(kMaxWidth - width); |
218 uint32_t y = d->fRandom->nextULessThan(kMaxHeight - height); | 221 uint32_t y = d->fRandom->nextULessThan(kMaxHeight - height); |
219 uint32_t inset = d->fRandom->nextULessThan(kMaxInset); | 222 uint32_t inset = d->fRandom->nextULessThan(kMaxInset); |
220 | 223 |
221 GrFragmentProcessor* effect = GrMagnifierEffect::Create( | 224 GrFragmentProcessor* effect = GrMagnifierEffect::Create( |
| 225 d->fProcDataManager, |
222 texture, | 226 texture, |
223 SkRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight)), | 227 SkRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight)), |
224 (float) width / texture->width(), | 228 (float) width / texture->width(), |
225 (float) height / texture->height(), | 229 (float) height / texture->height(), |
226 texture->width() / (float) x, | 230 texture->width() / (float) x, |
227 texture->height() / (float) y, | 231 texture->height() / (float) y, |
228 (float) inset / texture->width(), | 232 (float) inset / texture->width(), |
229 (float) inset / texture->height()); | 233 (float) inset / texture->height()); |
230 SkASSERT(effect); | 234 SkASSERT(effect); |
231 return effect; | 235 return effect; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 } | 270 } |
267 | 271 |
268 | 272 |
269 SkMagnifierImageFilter::SkMagnifierImageFilter(const SkRect& srcRect, SkScalar i
nset, | 273 SkMagnifierImageFilter::SkMagnifierImageFilter(const SkRect& srcRect, SkScalar i
nset, |
270 SkImageFilter* input) | 274 SkImageFilter* input) |
271 : INHERITED(1, &input), fSrcRect(srcRect), fInset(inset) { | 275 : INHERITED(1, &input), fSrcRect(srcRect), fInset(inset) { |
272 SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); | 276 SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); |
273 } | 277 } |
274 | 278 |
275 #if SK_SUPPORT_GPU | 279 #if SK_SUPPORT_GPU |
276 bool SkMagnifierImageFilter::asFragmentProcessor(GrFragmentProcessor** fp, GrPro
cessorDataManager*, | 280 bool SkMagnifierImageFilter::asFragmentProcessor(GrFragmentProcessor** fp, |
| 281 GrProcessorDataManager* procDat
aManager, |
277 GrTexture* texture, const SkMat
rix&, | 282 GrTexture* texture, const SkMat
rix&, |
278 const SkIRect&bounds) const { | 283 const SkIRect&bounds) const { |
279 if (fp) { | 284 if (fp) { |
280 SkScalar yOffset = texture->origin() == kTopLeft_GrSurfaceOrigin ? fSrcR
ect.y() : | 285 SkScalar yOffset = texture->origin() == kTopLeft_GrSurfaceOrigin ? fSrcR
ect.y() : |
281 texture->height() - fSrcRect.height() * texture->height() / bounds.he
ight() | 286 texture->height() - fSrcRect.height() * texture->height() / bounds.he
ight() |
282 - fSrcRect.y(); | 287 - fSrcRect.y(); |
283 int boundsY = (texture->origin() == kTopLeft_GrSurfaceOrigin) ? bounds.y
() : | 288 int boundsY = (texture->origin() == kTopLeft_GrSurfaceOrigin) ? bounds.y
() : |
284 (texture->height() - bounds.height()); | 289 (texture->height() - bounds.height()); |
285 SkRect effectBounds = SkRect::MakeXYWH( | 290 SkRect effectBounds = SkRect::MakeXYWH( |
286 SkIntToScalar(bounds.x()) / texture->width(), | 291 SkIntToScalar(bounds.x()) / texture->width(), |
287 SkIntToScalar(boundsY) / texture->height(), | 292 SkIntToScalar(boundsY) / texture->height(), |
288 SkIntToScalar(texture->width()) / bounds.width(), | 293 SkIntToScalar(texture->width()) / bounds.width(), |
289 SkIntToScalar(texture->height()) / bounds.height()); | 294 SkIntToScalar(texture->height()) / bounds.height()); |
290 SkScalar invInset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1; | 295 SkScalar invInset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1; |
291 *fp = GrMagnifierEffect::Create(texture, | 296 *fp = GrMagnifierEffect::Create(procDataManager, |
| 297 texture, |
292 effectBounds, | 298 effectBounds, |
293 fSrcRect.x() / texture->width(), | 299 fSrcRect.x() / texture->width(), |
294 yOffset / texture->height(), | 300 yOffset / texture->height(), |
295 fSrcRect.width() / bounds.width(), | 301 fSrcRect.width() / bounds.width(), |
296 fSrcRect.height() / bounds.height(), | 302 fSrcRect.height() / bounds.height(), |
297 bounds.width() * invInset, | 303 bounds.width() * invInset, |
298 bounds.height() * invInset); | 304 bounds.height() * invInset); |
299 } | 305 } |
300 return true; | 306 return true; |
301 } | 307 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 388 |
383 #ifndef SK_IGNORE_TO_STRING | 389 #ifndef SK_IGNORE_TO_STRING |
384 void SkMagnifierImageFilter::toString(SkString* str) const { | 390 void SkMagnifierImageFilter::toString(SkString* str) const { |
385 str->appendf("SkMagnifierImageFilter: ("); | 391 str->appendf("SkMagnifierImageFilter: ("); |
386 str->appendf("src: (%f,%f,%f,%f) ", | 392 str->appendf("src: (%f,%f,%f,%f) ", |
387 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto
m); | 393 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto
m); |
388 str->appendf("inset: %f", fInset); | 394 str->appendf("inset: %f", fInset); |
389 str->append(")"); | 395 str->append(")"); |
390 } | 396 } |
391 #endif | 397 #endif |
OLD | NEW |