Index: src/effects/SkLightingImageFilter.cpp |
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp |
index 2454dc1b36cf43d30cac29e9e380c6292823554b..07eb6c9eb778b92b64d062769c086ac2df5971b7 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*, 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; |
@@ -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*, 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; |
@@ -984,56 +985,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; |
} |
@@ -1100,23 +1113,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; |
} |
@@ -1124,31 +1132,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; |
} |