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 "SkDevice.h" |
11 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
12 #include "SkWriteBuffer.h" | 13 #include "SkWriteBuffer.h" |
13 #include "SkValidationUtils.h" | 14 #include "SkValidationUtils.h" |
14 | 15 |
15 //////////////////////////////////////////////////////////////////////////////// | 16 //////////////////////////////////////////////////////////////////////////////// |
16 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
17 #include "GrInvariantOutput.h" | 18 #include "GrInvariantOutput.h" |
18 #include "effects/GrSingleTextureEffect.h" | 19 #include "effects/GrSingleTextureEffect.h" |
19 #include "gl/GrGLFragmentProcessor.h" | 20 #include "gl/GrGLFragmentProcessor.h" |
20 #include "gl/GrGLTexture.h" | 21 #include "gl/GrGLTexture.h" |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 buffer.readRect(&src); | 294 buffer.readRect(&src); |
294 return Create(src, buffer.readScalar(), common.getInput(0)); | 295 return Create(src, buffer.readScalar(), common.getInput(0)); |
295 } | 296 } |
296 | 297 |
297 void SkMagnifierImageFilter::flatten(SkWriteBuffer& buffer) const { | 298 void SkMagnifierImageFilter::flatten(SkWriteBuffer& buffer) const { |
298 this->INHERITED::flatten(buffer); | 299 this->INHERITED::flatten(buffer); |
299 buffer.writeRect(fSrcRect); | 300 buffer.writeRect(fSrcRect); |
300 buffer.writeScalar(fInset); | 301 buffer.writeScalar(fInset); |
301 } | 302 } |
302 | 303 |
303 bool SkMagnifierImageFilter::onFilterImage(Proxy*, const SkBitmap& src, | 304 bool SkMagnifierImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, |
304 const Context&, SkBitmap* dst, | 305 const Context&, SkBitmap* dst, |
305 SkIPoint* offset) const { | 306 SkIPoint* offset) const { |
306 if ((src.colorType() != kN32_SkColorType) || | 307 if ((src.colorType() != kN32_SkColorType) || |
307 (fSrcRect.width() >= src.width()) || | 308 (fSrcRect.width() >= src.width()) || |
308 (fSrcRect.height() >= src.height())) { | 309 (fSrcRect.height() >= src.height())) { |
309 return false; | 310 return false; |
310 } | 311 } |
311 | 312 |
312 SkAutoLockPixels alp(src); | 313 SkAutoLockPixels alp(src); |
313 SkASSERT(src.getPixels()); | 314 SkASSERT(src.getPixels()); |
314 if (!src.getPixels() || src.width() <= 0 || src.height() <= 0) { | 315 if (!src.getPixels() || src.width() <= 0 || src.height() <= 0) { |
315 return false; | 316 return false; |
316 } | 317 } |
317 | 318 |
318 if (!dst->tryAllocPixels(src.info())) { | 319 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(src.width(), src.heigh
t())); |
| 320 if (!device) { |
319 return false; | 321 return false; |
320 } | 322 } |
| 323 *dst = device->accessBitmap(false); |
| 324 SkAutoLockPixels alp_dst(*dst); |
321 | 325 |
322 SkScalar inv_inset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1; | 326 SkScalar inv_inset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1; |
323 | 327 |
324 SkScalar inv_x_zoom = fSrcRect.width() / src.width(); | 328 SkScalar inv_x_zoom = fSrcRect.width() / src.width(); |
325 SkScalar inv_y_zoom = fSrcRect.height() / src.height(); | 329 SkScalar inv_y_zoom = fSrcRect.height() / src.height(); |
326 | 330 |
327 SkColor* sptr = src.getAddr32(0, 0); | 331 SkColor* sptr = src.getAddr32(0, 0); |
328 SkColor* dptr = dst->getAddr32(0, 0); | 332 SkColor* dptr = dst->getAddr32(0, 0); |
329 int width = src.width(), height = src.height(); | 333 int width = src.width(), height = src.height(); |
330 for (int y = 0; y < height; ++y) { | 334 for (int y = 0; y < height; ++y) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 372 |
369 #ifndef SK_IGNORE_TO_STRING | 373 #ifndef SK_IGNORE_TO_STRING |
370 void SkMagnifierImageFilter::toString(SkString* str) const { | 374 void SkMagnifierImageFilter::toString(SkString* str) const { |
371 str->appendf("SkMagnifierImageFilter: ("); | 375 str->appendf("SkMagnifierImageFilter: ("); |
372 str->appendf("src: (%f,%f,%f,%f) ", | 376 str->appendf("src: (%f,%f,%f,%f) ", |
373 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto
m); | 377 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto
m); |
374 str->appendf("inset: %f", fInset); | 378 str->appendf("inset: %f", fInset); |
375 str->append(")"); | 379 str->append(")"); |
376 } | 380 } |
377 #endif | 381 #endif |
OLD | NEW |