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 14 matching lines...) Expand all Loading... |
25 public: | 25 public: |
26 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, | 26 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, |
27 GrTexture* texture, | 27 GrTexture* texture, |
28 const SkRect& bounds, | 28 const SkRect& bounds, |
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, (procDataManager, | 35 return new GrMagnifierEffect(procDataManager, texture, bounds, xOffset,
yOffset, xInvZoom, |
36 texture, | 36 yInvZoom, xInvInset, yInvInset); |
37 bounds, | |
38 xOffset, | |
39 yOffset, | |
40 xInvZoom, | |
41 yInvZoom, | |
42 xInvInset, | |
43 yInvInset)); | |
44 } | 37 } |
45 | 38 |
46 virtual ~GrMagnifierEffect() {}; | 39 virtual ~GrMagnifierEffect() {}; |
47 | 40 |
48 const char* name() const override { return "Magnifier"; } | 41 const char* name() const override { return "Magnifier"; } |
49 | 42 |
50 const SkRect& bounds() const { return fBounds; } // Bounds of source imag
e. | 43 const SkRect& bounds() const { return fBounds; } // Bounds of source imag
e. |
51 // Offset to apply to zoomed pixels, (srcRect position / texture size). | 44 // Offset to apply to zoomed pixels, (srcRect position / texture size). |
52 float x_offset() const { return fXOffset; } | 45 float x_offset() const { return fXOffset; } |
53 float y_offset() const { return fYOffset; } | 46 float y_offset() const { return fYOffset; } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } | 183 } |
191 | 184 |
192 ///////////////////////////////////////////////////////////////////// | 185 ///////////////////////////////////////////////////////////////////// |
193 | 186 |
194 void GrMagnifierEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 187 void GrMagnifierEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
195 GrProcessorKeyBuilder* b) const { | 188 GrProcessorKeyBuilder* b) const { |
196 GrGLMagnifierEffect::GenKey(*this, caps, b); | 189 GrGLMagnifierEffect::GenKey(*this, caps, b); |
197 } | 190 } |
198 | 191 |
199 GrGLFragmentProcessor* GrMagnifierEffect::onCreateGLInstance() const { | 192 GrGLFragmentProcessor* GrMagnifierEffect::onCreateGLInstance() const { |
200 return SkNEW_ARGS(GrGLMagnifierEffect, (*this)); | 193 return new GrGLMagnifierEffect(*this); |
201 } | 194 } |
202 | 195 |
203 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMagnifierEffect); | 196 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMagnifierEffect); |
204 | 197 |
205 GrFragmentProcessor* GrMagnifierEffect::TestCreate(GrProcessorTestData* d) { | 198 GrFragmentProcessor* GrMagnifierEffect::TestCreate(GrProcessorTestData* d) { |
206 GrTexture* texture = d->fTextures[0]; | 199 GrTexture* texture = d->fTextures[0]; |
207 const int kMaxWidth = 200; | 200 const int kMaxWidth = 200; |
208 const int kMaxHeight = 200; | 201 const int kMaxHeight = 200; |
209 const int kMaxInset = 20; | 202 const int kMaxInset = 20; |
210 uint32_t width = d->fRandom->nextULessThan(kMaxWidth); | 203 uint32_t width = d->fRandom->nextULessThan(kMaxWidth); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 SkImageFilter* SkMagnifierImageFilter::Create(const SkRect& srcRect, SkScalar in
set, | 244 SkImageFilter* SkMagnifierImageFilter::Create(const SkRect& srcRect, SkScalar in
set, |
252 SkImageFilter* input) { | 245 SkImageFilter* input) { |
253 | 246 |
254 if (!SkScalarIsFinite(inset) || !SkIsValidRect(srcRect)) { | 247 if (!SkScalarIsFinite(inset) || !SkIsValidRect(srcRect)) { |
255 return NULL; | 248 return NULL; |
256 } | 249 } |
257 // Negative numbers in src rect are not supported | 250 // Negative numbers in src rect are not supported |
258 if (srcRect.fLeft < 0 || srcRect.fTop < 0) { | 251 if (srcRect.fLeft < 0 || srcRect.fTop < 0) { |
259 return NULL; | 252 return NULL; |
260 } | 253 } |
261 return SkNEW_ARGS(SkMagnifierImageFilter, (srcRect, inset, input)); | 254 return new SkMagnifierImageFilter(srcRect, inset, input); |
262 } | 255 } |
263 | 256 |
264 | 257 |
265 SkMagnifierImageFilter::SkMagnifierImageFilter(const SkRect& srcRect, SkScalar i
nset, | 258 SkMagnifierImageFilter::SkMagnifierImageFilter(const SkRect& srcRect, SkScalar i
nset, |
266 SkImageFilter* input) | 259 SkImageFilter* input) |
267 : INHERITED(1, &input), fSrcRect(srcRect), fInset(inset) { | 260 : INHERITED(1, &input), fSrcRect(srcRect), fInset(inset) { |
268 SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); | 261 SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); |
269 } | 262 } |
270 | 263 |
271 #if SK_SUPPORT_GPU | 264 #if SK_SUPPORT_GPU |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 373 |
381 #ifndef SK_IGNORE_TO_STRING | 374 #ifndef SK_IGNORE_TO_STRING |
382 void SkMagnifierImageFilter::toString(SkString* str) const { | 375 void SkMagnifierImageFilter::toString(SkString* str) const { |
383 str->appendf("SkMagnifierImageFilter: ("); | 376 str->appendf("SkMagnifierImageFilter: ("); |
384 str->appendf("src: (%f,%f,%f,%f) ", | 377 str->appendf("src: (%f,%f,%f,%f) ", |
385 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto
m); | 378 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto
m); |
386 str->appendf("inset: %f", fInset); | 379 str->appendf("inset: %f", fInset); |
387 str->append(")"); | 380 str->append(")"); |
388 } | 381 } |
389 #endif | 382 #endif |
OLD | NEW |