| Index: src/effects/SkLightingImageFilter.cpp
|
| diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
|
| index 2454dc1b36cf43d30cac29e9e380c6292823554b..7c8883d846be412b0ff682335da99f60e6032a21 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"
|
| @@ -291,8 +292,8 @@ protected:
|
| SkScalar kd, SkImageFilter* input, const CropRect* cropRect,
|
| uint32_t uniqueID);
|
| 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*, SkImage& src, const Context&,
|
| + SkAutoTUnref<SkImage>&, SkIPoint* offset) const SK_OVERRIDE;
|
| #if SK_SUPPORT_GPU
|
| virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const SkMatrix&,
|
| const SkIRect& bounds) const SK_OVERRIDE;
|
| @@ -321,8 +322,8 @@ protected:
|
| SkScalar shininess, SkImageFilter* input, const CropRect*,
|
| uint32_t uniqueID);
|
| 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*, SkImage& src, const Context&,
|
| + SkAutoTUnref<SkImage>& result, SkIPoint* offset) const SK_OVERRIDE;
|
| #if SK_SUPPORT_GPU
|
| virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const SkMatrix&,
|
| const SkIRect& bounds) const SK_OVERRIDE;
|
| @@ -984,56 +985,78 @@ void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const {
|
| }
|
|
|
| bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy,
|
| - const SkBitmap& source,
|
| + SkImage& source,
|
| const Context& ctx,
|
| - SkBitmap* dst,
|
| + SkAutoTUnref<SkImage>& dst,
|
| SkIPoint* offset) const {
|
| SkImageFilter* input = getInput(0);
|
| - SkBitmap src = source;
|
| + SkAutoTUnref<SkImage> src(SkRef(&source));
|
| SkIPoint srcOffset = SkIPoint::Make(0, 0);
|
| - if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) {
|
| + if (input && !input->filterImage(proxy, source, ctx, src, &srcOffset)) {
|
| return false;
|
| }
|
| -
|
| +#if 0
|
| if (src.colorType() != kN32_SkColorType) {
|
| return false;
|
| }
|
| +#endif
|
| 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;
|
| }
|
| + SkBitmap srcBitmap;
|
| + if (!as_IB(src)->getROPixels(&srcBitmap)) {
|
| + return false;
|
| + }
|
| + src.reset(NULL);
|
|
|
| - SkAutoLockPixels alp(src);
|
| - if (!src.getPixels()) {
|
| + SkAutoLockPixels alp(srcBitmap);
|
| + if (!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, true, NULL);
|
| + if (NULL == image) {
|
| + return false;
|
| + }
|
| + dst.reset(image);
|
| + offset->fX = resultX;
|
| + offset->fY = resultY;
|
| return true;
|
| }
|
|
|
| @@ -1100,23 +1123,23 @@ void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const {
|
| }
|
|
|
| bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy,
|
| - const SkBitmap& source,
|
| + SkImage& source,
|
| const Context& ctx,
|
| - SkBitmap* dst,
|
| + SkAutoTUnref<SkImage>& dst,
|
| SkIPoint* offset) const {
|
| SkImageFilter* input = getInput(0);
|
| - SkBitmap src = source;
|
| + SkAutoTUnref<SkImage> src(SkRef(&source));
|
| SkIPoint srcOffset = SkIPoint::Make(0, 0);
|
| - if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) {
|
| + if (input && !input->filterImage(proxy, source, ctx, src, &srcOffset)) {
|
| return false;
|
| }
|
| -
|
| +#if 0
|
| if (src.colorType() != kN32_SkColorType) {
|
| return false;
|
| }
|
| -
|
| +#endif
|
| SkIRect bounds;
|
| - if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &bounds, &src)) {
|
| + if (!this->applyCropRect(ctx, proxy, *src, &srcOffset, &bounds, src)) {
|
| return false;
|
| }
|
|
|
| @@ -1124,31 +1147,52 @@ bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy,
|
| return false;
|
| }
|
|
|
| - SkAutoLockPixels alp(src);
|
| - if (!src.getPixels()) {
|
| + SkBitmap srcBitmap;
|
| + if (!as_IB(src)->getROPixels(&srcBitmap)) {
|
| return false;
|
| }
|
| + src.reset(NULL);
|
|
|
| - if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
|
| + SkAutoLockPixels alp(srcBitmap);
|
| + if (!srcBitmap.getPixels()) {
|
| + return false;
|
| + }
|
| +
|
| + 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, true, NULL);
|
| + if (NULL == image) {
|
| + return false;
|
| + }
|
| + dst.reset(image);
|
| + offset->fX = resultX;
|
| + offset->fY = resultY;
|
| return true;
|
| }
|
|
|
|
|