| Index: src/effects/SkLightingImageFilter.cpp
|
| diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
|
| index 115776707ddc6445004a54daf0748cc506a5da57..d546b56edaee7dea5b545e8353c05a97321ba2c4 100644
|
| --- a/src/effects/SkLightingImageFilter.cpp
|
| +++ b/src/effects/SkLightingImageFilter.cpp
|
| @@ -8,12 +8,13 @@
|
| #include "SkLightingImageFilter.h"
|
| #include "SkBitmap.h"
|
| #include "SkColorPriv.h"
|
| +#include "SkImagePriv.h"
|
| +#include "SkImage_Base.h"
|
| #include "SkReadBuffer.h"
|
| -#include "SkWriteBuffer.h"
|
| #include "SkReadBuffer.h"
|
| -#include "SkWriteBuffer.h"
|
| #include "SkTypes.h"
|
| -
|
| +#include "SkWriteBuffer.h"
|
| +#include "SkWriteBuffer.h"
|
| #if SK_SUPPORT_GPU
|
| #include "GrFragmentProcessor.h"
|
| #include "GrInvariantOutput.h"
|
| @@ -290,8 +291,8 @@ protected:
|
| SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale,
|
| SkScalar kd, SkImageFilter* input, const CropRect* cropRect);
|
| void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
|
| - virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
|
| - SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
|
| + virtual bool onFilterImage(Proxy*, const SkImage* src, const Context&,
|
| + SkAutoTUnref<const SkImage>&, SkIPoint* offset) const SK_OVERRIDE;
|
| #if SK_SUPPORT_GPU
|
| virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const SkMatrix&,
|
| const SkIRect& bounds) const SK_OVERRIDE;
|
| @@ -318,8 +319,8 @@ protected:
|
| SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScalar ks,
|
| SkScalar shininess, SkImageFilter* input, const CropRect*);
|
| void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
|
| - virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
|
| - SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
|
| + virtual bool onFilterImage(Proxy*, const SkImage* src, const Context&,
|
| + SkAutoTUnref<const SkImage>& result, SkIPoint* offset) const SK_OVERRIDE;
|
| #if SK_SUPPORT_GPU
|
| virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const SkMatrix&,
|
| const SkIRect& bounds) const SK_OVERRIDE;
|
| @@ -980,56 +981,68 @@ void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const {
|
| }
|
|
|
| bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy,
|
| - const SkBitmap& source,
|
| + const SkImage* source,
|
| const Context& ctx,
|
| - SkBitmap* dst,
|
| + SkAutoTUnref<const SkImage>& dst,
|
| SkIPoint* offset) const {
|
| SkImageFilter* input = getInput(0);
|
| - SkBitmap src = source;
|
| + SkAutoTUnref<const SkImage> src(SkRef(source));
|
| SkIPoint srcOffset = SkIPoint::Make(0, 0);
|
| - if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) {
|
| - return false;
|
| - }
|
| -
|
| - if (src.colorType() != kN32_SkColorType) {
|
| + if (input && !input->filterImage(proxy, source, ctx, src, &srcOffset)) {
|
| return false;
|
| }
|
| SkIRect bounds;
|
| - if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &bounds, &src)) {
|
| + if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &bounds, src)) {
|
| return false;
|
| }
|
|
|
| if (bounds.width() < 2 || bounds.height() < 2) {
|
| return false;
|
| }
|
| -
|
| - SkAutoLockPixels alp(src);
|
| - if (!src.getPixels()) {
|
| + SkBitmap srcBitmap;
|
| + SkAutoAdoptImageAsN32Bitmap aai(src, &srcBitmap);
|
| + if (NULL == srcBitmap.getPixels()) {
|
| return false;
|
| }
|
|
|
| - if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
|
| + SkBitmap dstBitmap;
|
| + if (!dstBitmap.tryAllocPixels(srcBitmap.info().makeWH(bounds.width(), bounds.height()))) {
|
| return false;
|
| }
|
|
|
| SkAutoTUnref<SkLight> transformedLight(light()->transform(ctx.ctm()));
|
|
|
| DiffuseLightingType lightingType(fKD);
|
| - offset->fX = bounds.left();
|
| - offset->fY = bounds.top();
|
| + int32_t resultX = bounds.left();
|
| + int32_t resultY = bounds.top();
|
| +
|
| bounds.offset(-srcOffset);
|
| switch (transformedLight->type()) {
|
| case SkLight::kDistant_LightType:
|
| - lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, transformedLight, src, dst, surfaceScale(), bounds);
|
| + lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, transformedLight,
|
| + srcBitmap, &dstBitmap, surfaceScale(),
|
| + bounds);
|
| break;
|
| case SkLight::kPoint_LightType:
|
| - lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, transformedLight, src, dst, surfaceScale(), bounds);
|
| + lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, transformedLight,
|
| + srcBitmap, &dstBitmap, surfaceScale(),
|
| + bounds);
|
| break;
|
| case SkLight::kSpot_LightType:
|
| - lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, transformedLight, src, dst, surfaceScale(), bounds);
|
| + lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, transformedLight, srcBitmap,
|
| + &dstBitmap, surfaceScale(), bounds);
|
| break;
|
| }
|
|
|
| + srcBitmap = SkBitmap();
|
| +
|
| + SkImage* image = SkNewImageFromBitmap(dstBitmap, NULL);
|
| + if (NULL == image) {
|
| + return false;
|
| + }
|
| + dst.reset(image);
|
| + offset->fX = resultX;
|
| + offset->fY = resultY;
|
| return true;
|
| }
|
|
|
| @@ -1096,23 +1109,18 @@ void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const {
|
| }
|
|
|
| bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy,
|
| - const SkBitmap& source,
|
| + const SkImage* source,
|
| const Context& ctx,
|
| - SkBitmap* dst,
|
| + SkAutoTUnref<const SkImage>& dst,
|
| SkIPoint* offset) const {
|
| SkImageFilter* input = getInput(0);
|
| - SkBitmap src = source;
|
| + SkAutoTUnref<const SkImage> src(SkRef(source));
|
| SkIPoint srcOffset = SkIPoint::Make(0, 0);
|
| - if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) {
|
| - return false;
|
| - }
|
| -
|
| - if (src.colorType() != kN32_SkColorType) {
|
| + if (input && !input->filterImage(proxy, source, ctx, src, &srcOffset)) {
|
| return false;
|
| }
|
| -
|
| SkIRect bounds;
|
| - if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &bounds, &src)) {
|
| + if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &bounds, src)) {
|
| return false;
|
| }
|
|
|
| @@ -1120,31 +1128,47 @@ bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy,
|
| return false;
|
| }
|
|
|
| - SkAutoLockPixels alp(src);
|
| - if (!src.getPixels()) {
|
| + SkBitmap srcBitmap;
|
| + SkAutoAdoptImageAsN32Bitmap aai(src, &srcBitmap);
|
| + if (NULL == srcBitmap.getPixels()) {
|
| return false;
|
| }
|
|
|
| - if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
|
| + SkBitmap dstBitmap;
|
| + if (!dstBitmap.tryAllocPixels(srcBitmap.info().makeWH(bounds.width(), bounds.height()))) {
|
| return false;
|
| }
|
|
|
| SpecularLightingType lightingType(fKS, fShininess);
|
| - offset->fX = bounds.left();
|
| - offset->fY = bounds.top();
|
| + int32_t resultX = bounds.left();
|
| + int32_t resultY = bounds.top();
|
| +
|
| bounds.offset(-srcOffset);
|
| SkAutoTUnref<SkLight> transformedLight(light()->transform(ctx.ctm()));
|
| switch (transformedLight->type()) {
|
| case SkLight::kDistant_LightType:
|
| - lightBitmap<SpecularLightingType, SkDistantLight>(lightingType, transformedLight, src, dst, surfaceScale(), bounds);
|
| + lightBitmap<SpecularLightingType, SkDistantLight>(lightingType, transformedLight,
|
| + srcBitmap, &dstBitmap, surfaceScale(),
|
| + bounds);
|
| break;
|
| case SkLight::kPoint_LightType:
|
| - lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transformedLight, src, dst, surfaceScale(), bounds);
|
| + lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transformedLight,
|
| + srcBitmap, &dstBitmap, surfaceScale(),
|
| + bounds);
|
| break;
|
| case SkLight::kSpot_LightType:
|
| - lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, transformedLight, src, dst, surfaceScale(), bounds);
|
| + lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, transformedLight,
|
| + srcBitmap, &dstBitmap, surfaceScale(),
|
| + bounds);
|
| break;
|
| }
|
| + SkImage* image = SkNewImageFromBitmap(dstBitmap, NULL);
|
| + if (NULL == image) {
|
| + return false;
|
| + }
|
| + dst.reset(image);
|
| + offset->fX = resultX;
|
| + offset->fY = resultY;
|
| return true;
|
| }
|
|
|
|
|