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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 177 } |
178 | 178 |
179 ///////////////////////////////////////////////////////////////////// | 179 ///////////////////////////////////////////////////////////////////// |
180 | 180 |
181 GR_DEFINE_EFFECT_TEST(GrMagnifierEffect); | 181 GR_DEFINE_EFFECT_TEST(GrMagnifierEffect); |
182 | 182 |
183 GrEffectRef* GrMagnifierEffect::TestCreate(SkRandom* random, | 183 GrEffectRef* GrMagnifierEffect::TestCreate(SkRandom* random, |
184 GrContext* context, | 184 GrContext* context, |
185 const GrDrawTargetCaps&, | 185 const GrDrawTargetCaps&, |
186 GrTexture** textures) { | 186 GrTexture** textures) { |
| 187 GrTexture* texture = textures[0]; |
187 const int kMaxWidth = 200; | 188 const int kMaxWidth = 200; |
188 const int kMaxHeight = 200; | 189 const int kMaxHeight = 200; |
189 const int kMaxInset = 20; | 190 const int kMaxInset = 20; |
190 uint32_t width = random->nextULessThan(kMaxWidth); | 191 uint32_t width = random->nextULessThan(kMaxWidth); |
191 uint32_t height = random->nextULessThan(kMaxHeight); | 192 uint32_t height = random->nextULessThan(kMaxHeight); |
192 uint32_t x = random->nextULessThan(kMaxWidth - width); | 193 uint32_t x = random->nextULessThan(kMaxWidth - width); |
193 uint32_t y = random->nextULessThan(kMaxHeight - height); | 194 uint32_t y = random->nextULessThan(kMaxHeight - height); |
194 SkScalar inset = SkIntToScalar(random->nextULessThan(kMaxInset)); | 195 uint32_t inset = random->nextULessThan(kMaxInset); |
195 | 196 |
196 SkAutoTUnref<SkMagnifierImageFilter> filter( | 197 GrEffectRef* effect = GrMagnifierEffect::Create( |
197 new SkMagnifierImageFilter( | 198 texture, |
198 SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), | 199 (float) width / texture->width(), |
199 SkIntToScalar(width), SkIntToScalar(height)), | 200 (float) height / texture->height(), |
200 inset)); | 201 texture->width() / (float) x, |
201 GrEffectRef* effect; | 202 texture->height() / (float) y, |
202 filter->asNewEffect(&effect, textures[0], SkMatrix::I()); | 203 (float) inset / texture->width(), |
| 204 (float) inset / texture->height()); |
203 SkASSERT(NULL != effect); | 205 SkASSERT(NULL != effect); |
204 return effect; | 206 return effect; |
205 } | 207 } |
206 | 208 |
207 /////////////////////////////////////////////////////////////////////////////// | 209 /////////////////////////////////////////////////////////////////////////////// |
208 | 210 |
209 const GrBackendEffectFactory& GrMagnifierEffect::getFactory() const { | 211 const GrBackendEffectFactory& GrMagnifierEffect::getFactory() const { |
210 return GrTBackendEffectFactory<GrMagnifierEffect>::getInstance(); | 212 return GrTBackendEffectFactory<GrMagnifierEffect>::getInstance(); |
211 } | 213 } |
212 | 214 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 | 328 |
327 int x_val = SkMin32(SkScalarFloorToInt(x_interp), width - 1); | 329 int x_val = SkMin32(SkScalarFloorToInt(x_interp), width - 1); |
328 int y_val = SkMin32(SkScalarFloorToInt(y_interp), height - 1); | 330 int y_val = SkMin32(SkScalarFloorToInt(y_interp), height - 1); |
329 | 331 |
330 *dptr = sptr[y_val * width + x_val]; | 332 *dptr = sptr[y_val * width + x_val]; |
331 dptr++; | 333 dptr++; |
332 } | 334 } |
333 } | 335 } |
334 return true; | 336 return true; |
335 } | 337 } |
OLD | NEW |