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 "effects/GrSingleTextureEffect.h" | 17 #include "effects/GrSingleTextureEffect.h" |
18 #include "gl/GrGLEffect.h" | 18 #include "gl/GrGLEffect.h" |
19 #include "gl/GrGLSL.h" | 19 #include "gl/GrGLSL.h" |
20 #include "gl/GrGLTexture.h" | 20 #include "gl/GrGLTexture.h" |
21 #include "GrTBackendEffectFactory.h" | 21 #include "GrTBackendEffectFactory.h" |
22 | 22 |
23 class GrGLMagnifierEffect; | 23 class GrGLMagnifierEffect; |
24 | 24 |
25 class GrMagnifierEffect : public GrSingleTextureEffect { | 25 class GrMagnifierEffect : public GrSingleTextureEffect { |
26 | 26 |
27 public: | 27 public: |
28 static GrEffectRef* Create(GrTexture* texture, | 28 static GrEffect* Create(GrTexture* texture, |
29 float xOffset, | 29 float xOffset, |
30 float yOffset, | 30 float yOffset, |
31 float xInvZoom, | 31 float xInvZoom, |
32 float yInvZoom, | 32 float yInvZoom, |
33 float xInvInset, | 33 float xInvInset, |
34 float yInvInset) { | 34 float yInvInset) { |
35 return SkNEW_ARGS(GrMagnifierEffect, (texture, | 35 return SkNEW_ARGS(GrMagnifierEffect, (texture, |
36 xOffset, | 36 xOffset, |
37 yOffset, | 37 yOffset, |
38 xInvZoom, | 38 xInvZoom, |
39 yInvZoom, | 39 yInvZoom, |
40 xInvInset, | 40 xInvInset, |
41 yInvInset)); | 41 yInvInset)); |
42 } | 42 } |
43 | 43 |
44 virtual ~GrMagnifierEffect() {}; | 44 virtual ~GrMagnifierEffect() {}; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 const GrMagnifierEffect& zoom = drawEffect.castEffect<GrMagnifierEffect>(); | 174 const GrMagnifierEffect& zoom = drawEffect.castEffect<GrMagnifierEffect>(); |
175 uman.set2f(fOffsetVar, zoom.x_offset(), zoom.y_offset()); | 175 uman.set2f(fOffsetVar, zoom.x_offset(), zoom.y_offset()); |
176 uman.set2f(fInvZoomVar, zoom.x_inv_zoom(), zoom.y_inv_zoom()); | 176 uman.set2f(fInvZoomVar, zoom.x_inv_zoom(), zoom.y_inv_zoom()); |
177 uman.set2f(fInvInsetVar, zoom.x_inv_inset(), zoom.y_inv_inset()); | 177 uman.set2f(fInvInsetVar, zoom.x_inv_inset(), zoom.y_inv_inset()); |
178 } | 178 } |
179 | 179 |
180 ///////////////////////////////////////////////////////////////////// | 180 ///////////////////////////////////////////////////////////////////// |
181 | 181 |
182 GR_DEFINE_EFFECT_TEST(GrMagnifierEffect); | 182 GR_DEFINE_EFFECT_TEST(GrMagnifierEffect); |
183 | 183 |
184 GrEffectRef* GrMagnifierEffect::TestCreate(SkRandom* random, | 184 GrEffect* GrMagnifierEffect::TestCreate(SkRandom* random, |
185 GrContext* context, | 185 GrContext* context, |
186 const GrDrawTargetCaps&, | 186 const GrDrawTargetCaps&, |
187 GrTexture** textures) { | 187 GrTexture** textures) { |
188 GrTexture* texture = textures[0]; | 188 GrTexture* texture = textures[0]; |
189 const int kMaxWidth = 200; | 189 const int kMaxWidth = 200; |
190 const int kMaxHeight = 200; | 190 const int kMaxHeight = 200; |
191 const int kMaxInset = 20; | 191 const int kMaxInset = 20; |
192 uint32_t width = random->nextULessThan(kMaxWidth); | 192 uint32_t width = random->nextULessThan(kMaxWidth); |
193 uint32_t height = random->nextULessThan(kMaxHeight); | 193 uint32_t height = random->nextULessThan(kMaxHeight); |
194 uint32_t x = random->nextULessThan(kMaxWidth - width); | 194 uint32_t x = random->nextULessThan(kMaxWidth - width); |
195 uint32_t y = random->nextULessThan(kMaxHeight - height); | 195 uint32_t y = random->nextULessThan(kMaxHeight - height); |
196 uint32_t inset = random->nextULessThan(kMaxInset); | 196 uint32_t inset = random->nextULessThan(kMaxInset); |
197 | 197 |
198 GrEffectRef* effect = GrMagnifierEffect::Create( | 198 GrEffect* effect = GrMagnifierEffect::Create( |
199 texture, | 199 texture, |
200 (float) width / texture->width(), | 200 (float) width / texture->width(), |
201 (float) height / texture->height(), | 201 (float) height / texture->height(), |
202 texture->width() / (float) x, | 202 texture->width() / (float) x, |
203 texture->height() / (float) y, | 203 texture->height() / (float) y, |
204 (float) inset / texture->width(), | 204 (float) inset / texture->width(), |
205 (float) inset / texture->height()); | 205 (float) inset / texture->height()); |
206 SkASSERT(NULL != effect); | 206 SkASSERT(NULL != effect); |
207 return effect; | 207 return effect; |
208 } | 208 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 (fSrcRect.fLeft >= 0) && (fSrcRect.fTop >= 0)); | 245 (fSrcRect.fLeft >= 0) && (fSrcRect.fTop >= 0)); |
246 } | 246 } |
247 | 247 |
248 // FIXME: implement single-input semantics | 248 // FIXME: implement single-input semantics |
249 SkMagnifierImageFilter::SkMagnifierImageFilter(const SkRect& srcRect, SkScalar i
nset) | 249 SkMagnifierImageFilter::SkMagnifierImageFilter(const SkRect& srcRect, SkScalar i
nset) |
250 : INHERITED(0), fSrcRect(srcRect), fInset(inset) { | 250 : INHERITED(0), fSrcRect(srcRect), fInset(inset) { |
251 SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); | 251 SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); |
252 } | 252 } |
253 | 253 |
254 #if SK_SUPPORT_GPU | 254 #if SK_SUPPORT_GPU |
255 bool SkMagnifierImageFilter::asNewEffect(GrEffectRef** effect, GrTexture* textur
e, const SkMatrix&, const SkIRect&) const { | 255 bool SkMagnifierImageFilter::asNewEffect(GrEffect** effect, GrTexture* texture,
const SkMatrix&, |
| 256 const SkIRect&) const { |
256 if (effect) { | 257 if (effect) { |
257 SkScalar yOffset = (texture->origin() == kTopLeft_GrSurfaceOrigin) ? fSr
cRect.y() : | 258 SkScalar yOffset = (texture->origin() == kTopLeft_GrSurfaceOrigin) ? fSr
cRect.y() : |
258 (texture->height() - (fSrcRect.y() + fSrcRect.height(
))); | 259 (texture->height() - (fSrcRect.y() + fSrcRect.height(
))); |
259 SkScalar invInset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1; | 260 SkScalar invInset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1; |
260 *effect = GrMagnifierEffect::Create(texture, | 261 *effect = GrMagnifierEffect::Create(texture, |
261 fSrcRect.x() / texture->width(), | 262 fSrcRect.x() / texture->width(), |
262 yOffset / texture->height(), | 263 yOffset / texture->height(), |
263 fSrcRect.width() / texture->width(), | 264 fSrcRect.width() / texture->width(), |
264 fSrcRect.height() / texture->height(
), | 265 fSrcRect.height() / texture->height(
), |
265 texture->width() * invInset, | 266 texture->width() * invInset, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 341 |
341 int x_val = SkPin32(SkScalarFloorToInt(x_interp), 0, width - 1); | 342 int x_val = SkPin32(SkScalarFloorToInt(x_interp), 0, width - 1); |
342 int y_val = SkPin32(SkScalarFloorToInt(y_interp), 0, height - 1); | 343 int y_val = SkPin32(SkScalarFloorToInt(y_interp), 0, height - 1); |
343 | 344 |
344 *dptr = sptr[y_val * width + x_val]; | 345 *dptr = sptr[y_val * width + x_val]; |
345 dptr++; | 346 dptr++; |
346 } | 347 } |
347 } | 348 } |
348 return true; | 349 return true; |
349 } | 350 } |
OLD | NEW |