Revert of Implement approx-match support in image filter saveLayer() offscreen. (patchset #27 id:510001 of https://codereview.chromium.org/1034733002/)
Reason for revert:
Looks like this change is causing layout test failures which is blocking Skia's DEPS roll into Chromium:
https://codereview.chromium.org/1050563002/
https://codereview.chromium.org/1043133005/
https://codereview.chromium.org/1048273002/
Reverting to see if this fixes the DEPS roll.
Original issue's description:
> Implement approx-match support in image filter saveLayer() offscreen.
>
> Currently, the GPU-side image filter implementation creates
> exact-match textures for the offscreen backing stores for
> saveLayer(). This is because several filters have GPU
> implementations which depend on the texture coordinates
> being 0..1.
>
> The fix is three-fold:
>
> 1) Store the actual requested size in the SkGpuDevice, so
> that when wrapping it in an SkBitmap for passing to
> filterImage(), we can give it the original size.
> 2) Fix the filters (SkMagnifierImageFilter,
> SkLightingImageFilter) whose GPU implementation depends on
> 0..1 texture coordinates.
> 3) Remove the exception for GPU-side image filters in
> SkCanvas::internalSaveLayer().
>
> For the lighting filters, there were two bugs which were
> cancelling each other out: the sobel filter matrix was
> being computed upside down, but then we'd negate the
> resulting normal. This worked fine in the exact-match case,
> but in the approx-match case we'd sample garbage along
> the edge pixels. Also, we never implemented the edge pixels
> according to spec in the GPU case. It requires a
> different fragment shader for each edge of the nine-patch,
> which meant we couldn't use asFragmentProcessor(), and had
> to implement the drawing via a filterImageGPU() override.
> In order to avoid polluting the public API, I inserted a
> new base class, SkLightingImageFilterInternal above
> Sk[Diffuse|Specular]LightingImageFilter to handle the
> implementation.
>
> N.B.: this change will cause some minor pixel diffs in the
> GPU results of the following GMs (and possibly more):
> matriximagefilter, matrixconvolution, imagefiltersscaled,
> lighting, imagemagnifier, filterfastbounds,
> complexclip_aa_Layer_invert, complexclip_aa_layer,
> complexclip_bw_layer_invert, complexclip_bw_layer.
>
> BUG=skia:3532
>
> Committed: https://skia.googlesource.com/skia/+/b97dafefe63ea0a1bbce8e8b209f4920983fb8b9
>
> Committed: https://skia.googlesource.com/skia/+/f5f8518fe0bbd2703e4ffc1b11ad7b4312ff7641
TBR=bsalomon@google.com,reed@chromium.org,senorblanco@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:3532
Review URL: https://codereview.chromium.org/1057443003
diff --git a/gm/lighting.cpp b/gm/lighting.cpp
index 0bfbb47..36c8ba0 100644
--- a/gm/lighting.cpp
+++ b/gm/lighting.cpp
@@ -7,10 +7,9 @@
#include "gm.h"
#include "SkLightingImageFilter.h"
-#include "SkOffsetImageFilter.h"
#define WIDTH 330
-#define HEIGHT 660
+#define HEIGHT 440
namespace skiagm {
@@ -87,70 +86,28 @@
SkPaint paint;
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 10, 60, 65));
- SkImageFilter::CropRect fullSizeCropRect(SkRect::MakeXYWH(0, 0, 100, 100));
- SkAutoTUnref<SkImageFilter> noopCropped(SkOffsetImageFilter::Create(0, 0, NULL, &cropRect));
int y = 0;
- for (int i = 0; i < 3; i++) {
- const SkImageFilter::CropRect* cr = (i == 1) ? &cropRect : (i == 2) ? &fullSizeCropRect : NULL;
- SkImageFilter* input = (i == 2) ? noopCropped.get() : NULL;
- paint.setImageFilter(SkLightingImageFilter::CreatePointLitDiffuse(pointLocation,
- white,
- surfaceScale,
- kd,
- input,
- cr))->unref();
+ for (int i = 0; i < 2; i++) {
+ const SkImageFilter::CropRect* cr = (i == 0) ? NULL : &cropRect;
+ paint.setImageFilter(SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, white, surfaceScale, kd, NULL, cr))->unref();
drawClippedBitmap(canvas, paint, 0, y);
- paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(distantDirection,
- white,
- surfaceScale,
- kd,
- input,
- cr))->unref();
+ paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(distantDirection, white, surfaceScale, kd, NULL, cr))->unref();
drawClippedBitmap(canvas, paint, 110, y);
- paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation,
- spotTarget,
- spotExponent,
- cutoffAngle,
- white,
- surfaceScale,
- kd,
- input,
- cr))->unref();
+ paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, kd, NULL, cr))->unref();
drawClippedBitmap(canvas, paint, 220, y);
y += 110;
- paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(pointLocation,
- white,
- surfaceScale,
- ks,
- shininess,
- input,
- cr))->unref();
+ paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(pointLocation, white, surfaceScale, ks, shininess, NULL, cr))->unref();
drawClippedBitmap(canvas, paint, 0, y);
- paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular(distantDirection,
- white,
- surfaceScale,
- ks,
- shininess,
- input,
- cr))->unref();
+ paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular(distantDirection, white, surfaceScale, ks, shininess, NULL, cr))->unref();
drawClippedBitmap(canvas, paint, 110, y);
- paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(spotLocation,
- spotTarget,
- spotExponent,
- cutoffAngle,
- white,
- surfaceScale,
- ks,
- shininess,
- input,
- cr))->unref();
+ paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(spotLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, ks, shininess, NULL, cr))->unref();
drawClippedBitmap(canvas, paint, 220, y);
y += 110;
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 5310c9f..8426f09 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -936,6 +936,14 @@
}
SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage;
+#if 1
+ // this seems needed for current GMs, but makes us draw slower on the GPU
+ // Related to https://code.google.com/p/skia/issues/detail?id=3519 ?
+ //
+ if (paint && paint->getImageFilter()) {
+ usage = SkBaseDevice::kPossible_TileUsage;
+ }
+#endif
device = device->onCreateDevice(SkBaseDevice::CreateInfo(info, usage, geo), paint);
if (NULL == device) {
SkErrorInternals::SetError( kInternalError_SkError,
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index 972d9ac..72dcf64 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -277,136 +277,7 @@
buffer.writeScalar(point.fZ);
};
-enum BoundaryMode {
- kTopLeft_BoundaryMode,
- kTop_BoundaryMode,
- kTopRight_BoundaryMode,
- kLeft_BoundaryMode,
- kInterior_BoundaryMode,
- kRight_BoundaryMode,
- kBottomLeft_BoundaryMode,
- kBottom_BoundaryMode,
- kBottomRight_BoundaryMode,
-
- kBoundaryModeCount,
-};
-
-class SkLightingImageFilterInternal : public SkLightingImageFilter {
-protected:
- SkLightingImageFilterInternal(SkLight* light,
- SkScalar surfaceScale,
- SkImageFilter* input,
- const CropRect* cropRect)
- : INHERITED(light, surfaceScale, input, cropRect) {}
-
-#if SK_SUPPORT_GPU
- bool canFilterImageGPU() const override { return true; }
- bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&,
- SkBitmap* result, SkIPoint* offset) const override;
- virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*,
- const SkMatrix&,
- const SkIRect& bounds,
- BoundaryMode boundaryMode) const = 0;
-#endif
-private:
-#if SK_SUPPORT_GPU
- void drawRect(GrContext* context,
- GrTexture* src,
- GrTexture* dst,
- const SkMatrix& matrix,
- const GrClip& clip,
- const SkRect& dstRect,
- BoundaryMode boundaryMode,
- const SkIRect& bounds) const;
-#endif
- typedef SkLightingImageFilter INHERITED;
-};
-
-#if SK_SUPPORT_GPU
-void SkLightingImageFilterInternal::drawRect(GrContext* context,
- GrTexture* src,
- GrTexture* dst,
- const SkMatrix& matrix,
- const GrClip& clip,
- const SkRect& dstRect,
- BoundaryMode boundaryMode,
- const SkIRect& bounds) const {
- SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()));
- GrFragmentProcessor* fp = this->getFragmentProcessor(src, matrix, bounds, boundaryMode);
- GrPaint paint;
- paint.addColorProcessor(fp)->unref();
- context->drawNonAARectToRect(dst->asRenderTarget(), clip, paint, SkMatrix::I(),
- dstRect, srcRect);
-}
-
-bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy,
- const SkBitmap& src,
- const Context& ctx,
- SkBitmap* result,
- SkIPoint* offset) const {
- SkBitmap input = src;
- SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (this->getInput(0) &&
- !this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) {
- return false;
- }
- SkIRect bounds;
- if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &bounds, &input)) {
- return false;
- }
- SkRect dstRect = SkRect::MakeWH(SkIntToScalar(bounds.width()),
- SkIntToScalar(bounds.height()));
- GrTexture* srcTexture = input.getTexture();
- GrContext* context = srcTexture->getContext();
-
- GrSurfaceDesc desc;
- desc.fFlags = kRenderTarget_GrSurfaceFlag,
- desc.fWidth = bounds.width();
- desc.fHeight = bounds.height();
- desc.fConfig = kRGBA_8888_GrPixelConfig;
-
- SkAutoTUnref<GrTexture> dst(
- context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch));
- if (!dst) {
- return false;
- }
-
- // setup new clip
- GrClip clip(dstRect);
-
- offset->fX = bounds.left();
- offset->fY = bounds.top();
- SkMatrix matrix(ctx.ctm());
- matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top()));
- bounds.offset(-srcOffset);
- SkRect topLeft = SkRect::MakeXYWH(0, 0, 1, 1);
- SkRect top = SkRect::MakeXYWH(1, 0, dstRect.width() - 2, 1);
- SkRect topRight = SkRect::MakeXYWH(dstRect.width() - 1, 0, 1, 1);
- SkRect left = SkRect::MakeXYWH(0, 1, 1, dstRect.height() - 2);
- SkRect interior = dstRect.makeInset(1, 1);
- SkRect right = SkRect::MakeXYWH(dstRect.width() - 1, 1, 1, dstRect.height() - 2);
- SkRect bottomLeft = SkRect::MakeXYWH(0, dstRect.height() - 1, 1, 1);
- SkRect bottom = SkRect::MakeXYWH(1, dstRect.height() - 1, dstRect.width() - 2, 1);
- SkRect bottomRight = SkRect::MakeXYWH(dstRect.width() - 1, dstRect.height() - 1, 1, 1);
- this->drawRect(context, srcTexture, dst, matrix, clip, topLeft, kTopLeft_BoundaryMode, bounds);
- this->drawRect(context, srcTexture, dst, matrix, clip, top, kTop_BoundaryMode, bounds);
- this->drawRect(context, srcTexture, dst, matrix, clip, topRight, kTopRight_BoundaryMode,
- bounds);
- this->drawRect(context, srcTexture, dst, matrix, clip, left, kLeft_BoundaryMode, bounds);
- this->drawRect(context, srcTexture, dst, matrix, clip, interior, kInterior_BoundaryMode,
- bounds);
- this->drawRect(context, srcTexture, dst, matrix, clip, right, kRight_BoundaryMode, bounds);
- this->drawRect(context, srcTexture, dst, matrix, clip, bottomLeft, kBottomLeft_BoundaryMode,
- bounds);
- this->drawRect(context, srcTexture, dst, matrix, clip, bottom, kBottom_BoundaryMode, bounds);
- this->drawRect(context, srcTexture, dst, matrix, clip, bottomRight, kBottomRight_BoundaryMode,
- bounds);
- WrapTexture(dst, bounds.width(), bounds.height(), result);
- return true;
-}
-#endif
-
-class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal {
+class SkDiffuseLightingImageFilter : public SkLightingImageFilter {
public:
static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, SkScalar kd, SkImageFilter*,
const CropRect*);
@@ -419,20 +290,20 @@
SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale,
SkScalar kd, SkImageFilter* input, const CropRect* cropRect);
void flatten(SkWriteBuffer& buffer) const override;
- bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
- SkBitmap* result, SkIPoint* offset) const override;
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
+ SkBitmap* result, SkIPoint* offset) const override;
#if SK_SUPPORT_GPU
- GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&,
- const SkIRect& bounds, BoundaryMode) const override;
+ virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const SkMatrix&,
+ const SkIRect& bounds) const override;
#endif
private:
friend class SkLightingImageFilter;
- typedef SkLightingImageFilterInternal INHERITED;
+ typedef SkLightingImageFilter INHERITED;
SkScalar fKD;
};
-class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal {
+class SkSpecularLightingImageFilter : public SkLightingImageFilter {
public:
static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale,
SkScalar ks, SkScalar shininess, SkImageFilter*, const CropRect*);
@@ -447,32 +318,30 @@
SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScalar ks,
SkScalar shininess, SkImageFilter* input, const CropRect*);
void flatten(SkWriteBuffer& buffer) const override;
- bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
- SkBitmap* result, SkIPoint* offset) const override;
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
+ SkBitmap* result, SkIPoint* offset) const override;
#if SK_SUPPORT_GPU
- GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&,
- const SkIRect& bounds, BoundaryMode) const override;
+ virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const SkMatrix&,
+ const SkIRect& bounds) const override;
#endif
private:
SkScalar fKS;
SkScalar fShininess;
friend class SkLightingImageFilter;
- typedef SkLightingImageFilterInternal INHERITED;
+ typedef SkLightingImageFilter INHERITED;
};
#if SK_SUPPORT_GPU
class GrLightingEffect : public GrSingleTextureEffect {
public:
- GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceScale,
- const SkMatrix& matrix, BoundaryMode boundaryMode);
+ GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceScale, const SkMatrix& matrix);
virtual ~GrLightingEffect();
const SkLight* light() const { return fLight; }
SkScalar surfaceScale() const { return fSurfaceScale; }
const SkMatrix& filterMatrix() const { return fFilterMatrix; }
- BoundaryMode boundaryMode() const { return fBoundaryMode; }
protected:
bool onIsEqual(const GrFragmentProcessor&) const override;
@@ -487,7 +356,6 @@
const SkLight* fLight;
SkScalar fSurfaceScale;
SkMatrix fFilterMatrix;
- BoundaryMode fBoundaryMode;
};
class GrDiffuseLightingEffect : public GrLightingEffect {
@@ -496,14 +364,12 @@
const SkLight* light,
SkScalar surfaceScale,
const SkMatrix& matrix,
- SkScalar kd,
- BoundaryMode boundaryMode) {
+ SkScalar kd) {
return SkNEW_ARGS(GrDiffuseLightingEffect, (texture,
light,
surfaceScale,
matrix,
- kd,
- boundaryMode));
+ kd));
}
const char* name() const override { return "DiffuseLighting"; }
@@ -521,8 +387,7 @@
const SkLight* light,
SkScalar surfaceScale,
const SkMatrix& matrix,
- SkScalar kd,
- BoundaryMode boundaryMode);
+ SkScalar kd);
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
typedef GrLightingEffect INHERITED;
@@ -536,15 +401,13 @@
SkScalar surfaceScale,
const SkMatrix& matrix,
SkScalar ks,
- SkScalar shininess,
- BoundaryMode boundaryMode) {
+ SkScalar shininess) {
return SkNEW_ARGS(GrSpecularLightingEffect, (texture,
light,
surfaceScale,
matrix,
ks,
- shininess,
- boundaryMode));
+ shininess));
}
const char* name() const override { return "SpecularLighting"; }
@@ -564,8 +427,7 @@
SkScalar surfaceScale,
const SkMatrix& matrix,
SkScalar ks,
- SkScalar shininess,
- BoundaryMode boundaryMode);
+ SkScalar shininess);
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
typedef GrLightingEffect INHERITED;
@@ -619,7 +481,8 @@
class GrGLDistantLight : public GrGLLight {
public:
virtual ~GrGLDistantLight() {}
- void setData(const GrGLProgramDataManager&, const SkLight* light) const override;
+ virtual void setData(const GrGLProgramDataManager&,
+ const SkLight* light) const override;
void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override;
private:
@@ -632,7 +495,8 @@
class GrGLPointLight : public GrGLLight {
public:
virtual ~GrGLPointLight() {}
- void setData(const GrGLProgramDataManager&, const SkLight* light) const override;
+ virtual void setData(const GrGLProgramDataManager&,
+ const SkLight* light) const override;
void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override;
private:
@@ -645,7 +509,8 @@
class GrGLSpotLight : public GrGLLight {
public:
virtual ~GrGLSpotLight() {}
- void setData(const GrGLProgramDataManager&, const SkLight* light) const override;
+ virtual void setData(const GrGLProgramDataManager&,
+ const SkLight* light) const override;
void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override;
void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight) override;
@@ -830,11 +695,7 @@
class SkSpotLight : public SkLight {
public:
- SkSpotLight(const SkPoint3& location,
- const SkPoint3& target,
- SkScalar specularExponent,
- SkScalar cutoffAngle,
- SkColor color)
+ SkSpotLight(const SkPoint3& location, const SkPoint3& target, SkScalar specularExponent, SkScalar cutoffAngle, SkColor color)
: INHERITED(color),
fLocation(location),
fTarget(target),
@@ -862,14 +723,7 @@
SkPoint3 target(target2.fX, target2.fY, SkScalarAve(targetZ.fX, targetZ.fY));
SkPoint3 s = target - location;
s.normalize();
- return new SkSpotLight(location,
- target,
- fSpecularExponent,
- fCosOuterConeAngle,
- fCosInnerConeAngle,
- fConeScale,
- s,
- color());
+ return new SkSpotLight(location, target, fSpecularExponent, fCosOuterConeAngle, fCosInnerConeAngle, fConeScale, s, color());
}
SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const {
@@ -923,14 +777,7 @@
SkScalarIsFinite(fConeScale));
}
protected:
- SkSpotLight(const SkPoint3& location,
- const SkPoint3& target,
- SkScalar specularExponent,
- SkScalar cosOuterConeAngle,
- SkScalar cosInnerConeAngle,
- SkScalar coneScale,
- const SkPoint3& s,
- const SkPoint3& color)
+ SkSpotLight(const SkPoint3& location, const SkPoint3& target, SkScalar specularExponent, SkScalar cosOuterConeAngle, SkScalar cosInnerConeAngle, SkScalar coneScale, const SkPoint3& s, const SkPoint3& color)
: INHERITED(color),
fLocation(location),
fTarget(target),
@@ -1113,12 +960,8 @@
return SkNEW_ARGS(SkDiffuseLightingImageFilter, (light, surfaceScale, kd, input, cropRect));
}
-SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light,
- SkScalar surfaceScale,
- SkScalar kd,
- SkImageFilter* input,
- const CropRect* cropRect)
- : INHERITED(light, surfaceScale, input, cropRect),
+SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScalar kd, SkImageFilter* input, const CropRect* cropRect)
+ : SkLightingImageFilter(light, surfaceScale, input, cropRect),
fKD(kd)
{
}
@@ -1177,28 +1020,13 @@
bounds.offset(-srcOffset);
switch (transformedLight->type()) {
case SkLight::kDistant_LightType:
- lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType,
- transformedLight,
- src,
- dst,
- surfaceScale(),
- bounds);
+ lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, transformedLight, src, dst, surfaceScale(), bounds);
break;
case SkLight::kPoint_LightType:
- lightBitmap<DiffuseLightingType, SkPointLight>(lightingType,
- transformedLight,
- src,
- dst,
- surfaceScale(),
- bounds);
+ lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, transformedLight, src, dst, surfaceScale(), bounds);
break;
case SkLight::kSpot_LightType:
- lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType,
- transformedLight,
- src,
- dst,
- surfaceScale(),
- bounds);
+ lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, transformedLight, src, dst, surfaceScale(), bounds);
break;
}
@@ -1214,14 +1042,15 @@
#endif
#if SK_SUPPORT_GPU
-GrFragmentProcessor* SkDiffuseLightingImageFilter::getFragmentProcessor(
+bool SkDiffuseLightingImageFilter::asFragmentProcessor(GrFragmentProcessor** fp,
GrTexture* texture,
const SkMatrix& matrix,
- const SkIRect&,
- BoundaryMode boundaryMode
-) const {
- SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255));
- return GrDiffuseLightingEffect::Create(texture, light(), scale, matrix, kd(), boundaryMode);
+ const SkIRect&) const {
+ if (fp) {
+ SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255));
+ *fp = GrDiffuseLightingEffect::Create(texture, light(), scale, matrix, kd());
+ }
+ return true;
}
#endif
@@ -1244,13 +1073,8 @@
(light, surfaceScale, ks, shininess, input, cropRect));
}
-SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light,
- SkScalar surfaceScale,
- SkScalar ks,
- SkScalar shininess,
- SkImageFilter* input,
- const CropRect* cropRect)
- : INHERITED(light, surfaceScale, input, cropRect),
+SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropRect)
+ : SkLightingImageFilter(light, surfaceScale, input, cropRect),
fKS(ks),
fShininess(shininess)
{
@@ -1312,28 +1136,13 @@
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, src, dst, surfaceScale(), bounds);
break;
case SkLight::kPoint_LightType:
- lightBitmap<SpecularLightingType, SkPointLight>(lightingType,
- transformedLight,
- src,
- dst,
- surfaceScale(),
- bounds);
+ lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transformedLight, src, dst, surfaceScale(), bounds);
break;
case SkLight::kSpot_LightType:
- lightBitmap<SpecularLightingType, SkSpotLight>(lightingType,
- transformedLight,
- src,
- dst,
- surfaceScale(),
- bounds);
+ lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, transformedLight, src, dst, surfaceScale(), bounds);
break;
}
return true;
@@ -1348,14 +1157,15 @@
#endif
#if SK_SUPPORT_GPU
-GrFragmentProcessor* SkSpecularLightingImageFilter::getFragmentProcessor(
- GrTexture* texture,
- const SkMatrix& matrix,
- const SkIRect&,
- BoundaryMode boundaryMode) const {
- SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255));
- return GrSpecularLightingEffect::Create(texture, light(), scale, matrix, ks(), shininess(),
- boundaryMode);
+bool SkSpecularLightingImageFilter::asFragmentProcessor(GrFragmentProcessor** fp,
+ GrTexture* texture,
+ const SkMatrix& matrix,
+ const SkIRect&) const {
+ if (fp) {
+ SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255));
+ *fp = GrSpecularLightingEffect::Create(texture, light(), scale, matrix, ks(), shininess());
+ }
+ return true;
}
#endif
@@ -1392,81 +1202,6 @@
}
}
-SkString emitNormalFunc(BoundaryMode mode,
- const char* pointToNormalName,
- const char* sobelFuncName) {
- SkString result;
- switch (mode) {
- case kTopLeft_BoundaryMode:
- result.printf("\treturn %s(%s(0.0, 0.0, m[4], m[5], m[7], m[8], %g),\n"
- "\t %s(0.0, 0.0, m[4], m[7], m[5], m[8], %g),\n"
- "\t surfaceScale);\n",
- pointToNormalName, sobelFuncName, gTwoThirds,
- sobelFuncName, gTwoThirds);
- break;
- case kTop_BoundaryMode:
- result.printf("\treturn %s(%s(0.0, 0.0, m[3], m[5], m[6], m[8], %g),\n"
- "\t %s(0.0, 0.0, m[4], m[7], m[5], m[8], %g),\n"
- "\t surfaceScale);\n",
- pointToNormalName, sobelFuncName, gOneThird,
- sobelFuncName, gOneHalf);
- break;
- case kTopRight_BoundaryMode:
- result.printf("\treturn %s(%s( 0.0, 0.0, m[3], m[4], m[6], m[7], %g),\n"
- "\t %s(m[3], m[6], m[4], m[7], 0.0, 0.0, %g),\n"
- "\t surfaceScale);\n",
- pointToNormalName, sobelFuncName, gTwoThirds,
- sobelFuncName, gTwoThirds);
- break;
- case kLeft_BoundaryMode:
- result.printf("\treturn %s(%s(m[1], m[2], m[4], m[5], m[7], m[8], %g),\n"
- "\t %s( 0.0, 0.0, m[1], m[7], m[2], m[8], %g),\n"
- "\t surfaceScale);\n",
- pointToNormalName, sobelFuncName, gOneHalf,
- sobelFuncName, gOneThird);
- break;
- case kInterior_BoundaryMode:
- result.printf("\treturn %s(%s(m[0], m[2], m[3], m[5], m[6], m[8], %g),\n"
- "\t %s(m[0], m[6], m[1], m[7], m[2], m[8], %g),\n"
- "\t surfaceScale);\n",
- pointToNormalName, sobelFuncName, gOneQuarter,
- sobelFuncName, gOneQuarter);
- break;
- case kRight_BoundaryMode:
- result.printf("\treturn %s(%s(m[0], m[1], m[3], m[4], m[6], m[7], %g),\n"
- "\t %s(m[0], m[6], m[1], m[7], 0.0, 0.0, %g),\n"
- "\t surfaceScale);\n",
- pointToNormalName, sobelFuncName, gOneHalf,
- sobelFuncName, gOneThird);
- break;
- case kBottomLeft_BoundaryMode:
- result.printf("\treturn %s(%s(m[1], m[2], m[4], m[5], 0.0, 0.0, %g),\n"
- "\t %s( 0.0, 0.0, m[1], m[4], m[2], m[5], %g),\n"
- "\t surfaceScale);\n",
- pointToNormalName, sobelFuncName, gTwoThirds,
- sobelFuncName, gTwoThirds);
- break;
- case kBottom_BoundaryMode:
- result.printf("\treturn %s(%s(m[0], m[2], m[3], m[5], 0.0, 0.0, %g),\n"
- "\t %s(m[0], m[3], m[1], m[4], m[2], m[5], %g),\n"
- "\t surfaceScale);\n",
- pointToNormalName, sobelFuncName, gOneThird,
- sobelFuncName, gOneHalf);
- break;
- case kBottomRight_BoundaryMode:
- result.printf("\treturn %s(%s(m[0], m[1], m[3], m[4], 0.0, 0.0, %g),\n"
- "\t %s(m[0], m[3], m[1], m[4], 0.0, 0.0, %g),\n"
- "\t surfaceScale);\n",
- pointToNormalName, sobelFuncName, gTwoThirds,
- sobelFuncName, gTwoThirds);
- break;
- default:
- SkASSERT(false);
- break;
- }
- return result;
-}
-
}
class GrGLLightingEffect : public GrGLFragmentProcessor {
@@ -1474,12 +1209,12 @@
GrGLLightingEffect(const GrProcessor&);
virtual ~GrGLLightingEffect();
- void emitCode(GrGLFPBuilder*,
- const GrFragmentProcessor&,
- const char* outputColor,
- const char* inputColor,
- const TransformedCoordsArray&,
- const TextureSamplerArray&) override;
+ virtual void emitCode(GrGLFPBuilder*,
+ const GrFragmentProcessor&,
+ const char* outputColor,
+ const char* inputColor,
+ const TransformedCoordsArray&,
+ const TextureSamplerArray&) override;
static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder* b);
@@ -1497,7 +1232,6 @@
UniformHandle fImageIncrementUni;
UniformHandle fSurfaceScaleUni;
GrGLLight* fLight;
- BoundaryMode fBoundaryMode;
};
///////////////////////////////////////////////////////////////////////////////
@@ -1534,13 +1268,11 @@
GrLightingEffect::GrLightingEffect(GrTexture* texture,
const SkLight* light,
SkScalar surfaceScale,
- const SkMatrix& matrix,
- BoundaryMode boundaryMode)
+ const SkMatrix& matrix)
: INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture))
, fLight(light)
, fSurfaceScale(surfaceScale)
- , fFilterMatrix(matrix)
- , fBoundaryMode(boundaryMode) {
+ , fFilterMatrix(matrix) {
fLight->ref();
if (light->requiresFragmentPosition()) {
this->setWillReadFragmentPosition();
@@ -1554,8 +1286,7 @@
bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
const GrLightingEffect& s = sBase.cast<GrLightingEffect>();
return fLight->isEqual(*s.fLight) &&
- fSurfaceScale == s.fSurfaceScale &&
- fBoundaryMode == s.fBoundaryMode;
+ fSurfaceScale == s.fSurfaceScale;
}
///////////////////////////////////////////////////////////////////////////////
@@ -1564,9 +1295,8 @@
const SkLight* light,
SkScalar surfaceScale,
const SkMatrix& matrix,
- SkScalar kd,
- BoundaryMode boundaryMode)
- : INHERITED(texture, light, surfaceScale, matrix, boundaryMode), fKD(kd) {
+ SkScalar kd)
+ : INHERITED(texture, light, surfaceScale, matrix), fKD(kd) {
this->initClassID<GrDiffuseLightingEffect>();
}
@@ -1598,9 +1328,8 @@
for (int i = 0; i < 9; i++) {
matrix[i] = random->nextUScalar1();
}
- BoundaryMode mode = static_cast<BoundaryMode>(random->nextU() % kBoundaryModeCount);
return GrDiffuseLightingEffect::Create(textures[GrProcessorUnitTest::kAlphaTextureIdx],
- light, surfaceScale, matrix, kd, mode);
+ light, surfaceScale, matrix, kd);
}
@@ -1609,7 +1338,6 @@
GrGLLightingEffect::GrGLLightingEffect(const GrProcessor& fp) {
const GrLightingEffect& m = fp.cast<GrLightingEffect>();
fLight = m.light()->createGLLight();
- fBoundaryMode = m.boundaryMode();
}
GrGLLightingEffect::~GrGLLightingEffect() {
@@ -1660,23 +1388,27 @@
"pointToNormal",
SK_ARRAY_COUNT(gPointToNormalArgs),
gPointToNormalArgs,
- "\treturn normalize(vec3(-x * scale, -y * scale, 1));\n",
+ "\treturn normalize(vec3(-x * scale, y * scale, 1));\n",
&pointToNormalName);
static const GrGLShaderVar gInteriorNormalArgs[] = {
GrGLShaderVar("m", kFloat_GrSLType, 9),
GrGLShaderVar("surfaceScale", kFloat_GrSLType),
};
- SkString normalBody = emitNormalFunc(fBoundaryMode,
- pointToNormalName.c_str(),
- sobelFuncName.c_str());
- SkString normalName;
+ SkString interiorNormalBody;
+ interiorNormalBody.appendf("\treturn %s(%s(m[0], m[2], m[3], m[5], m[6], m[8], 0.25),\n"
+ "\t %s(m[0], m[6], m[1], m[7], m[2], m[8], 0.25),\n"
+ "\t surfaceScale);\n",
+ pointToNormalName.c_str(),
+ sobelFuncName.c_str(),
+ sobelFuncName.c_str());
+ SkString interiorNormalName;
fsBuilder->emitFunction(kVec3f_GrSLType,
- "normal",
+ "interiorNormal",
SK_ARRAY_COUNT(gInteriorNormalArgs),
gInteriorNormalArgs,
- normalBody.c_str(),
- &normalName);
+ interiorNormalBody.c_str(),
+ &interiorNormalName);
fsBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
fsBuilder->codeAppend("\t\tfloat m[9];\n");
@@ -1685,7 +1417,7 @@
const char* surfScale = builder->getUniformCStr(fSurfaceScaleUni);
int index = 0;
- for (int dy = 1; dy >= -1; dy--) {
+ for (int dy = -1; dy <= 1; dy++) {
for (int dx = -1; dx <= 1; dx++) {
SkString texCoords;
texCoords.appendf("coord + vec2(%d, %d) * %s", dx, dy, imgInc);
@@ -1700,7 +1432,7 @@
fLight->emitSurfaceToLight(builder, arg.c_str());
fsBuilder->codeAppend(";\n");
fsBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ",
- outputColor, lightFunc.c_str(), normalName.c_str(), surfScale);
+ outputColor, lightFunc.c_str(), interiorNormalName.c_str(), surfScale);
fLight->emitLightColor(builder, "surfaceToLight");
fsBuilder->codeAppend(");\n");
SkString modulate;
@@ -1710,8 +1442,7 @@
void GrGLLightingEffect::GenKey(const GrProcessor& proc,
const GrGLCaps& caps, GrProcessorKeyBuilder* b) {
- const GrLightingEffect& lighting = proc.cast<GrLightingEffect>();
- b->add32(lighting.boundaryMode() << 2 | lighting.light()->type());
+ b->add32(proc.cast<GrLightingEffect>().light()->type());
}
void GrGLLightingEffect::setData(const GrGLProgramDataManager& pdman,
@@ -1769,9 +1500,8 @@
SkScalar surfaceScale,
const SkMatrix& matrix,
SkScalar ks,
- SkScalar shininess,
- BoundaryMode boundaryMode)
- : INHERITED(texture, light, surfaceScale, matrix, boundaryMode),
+ SkScalar shininess)
+ : INHERITED(texture, light, surfaceScale, matrix),
fKS(ks),
fShininess(shininess) {
this->initClassID<GrSpecularLightingEffect>();
@@ -1807,9 +1537,8 @@
for (int i = 0; i < 9; i++) {
matrix[i] = random->nextUScalar1();
}
- BoundaryMode mode = static_cast<BoundaryMode>(random->nextU() % kBoundaryModeCount);
return GrSpecularLightingEffect::Create(textures[GrProcessorUnitTest::kAlphaTextureIdx],
- light, surfaceScale, matrix, ks, shininess, mode);
+ light, surfaceScale, matrix, ks, shininess);
}
///////////////////////////////////////////////////////////////////////////////
@@ -1825,10 +1554,7 @@
fKSUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision, "KS", &ks);
fShininessUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType,
- kDefault_GrSLPrecision,
- "Shininess",
- &shininess);
+ kFloat_GrSLType, kDefault_GrSLPrecision, "Shininess", &shininess);
static const GrGLShaderVar gLightArgs[] = {
GrGLShaderVar("normal", kVec3f_GrSLType),
diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp
index 6d2ee01..622713d 100644
--- a/src/effects/SkMagnifierImageFilter.cpp
+++ b/src/effects/SkMagnifierImageFilter.cpp
@@ -25,7 +25,6 @@
public:
static GrFragmentProcessor* Create(GrTexture* texture,
- const SkRect& bounds,
float xOffset,
float yOffset,
float xInvZoom,
@@ -33,7 +32,6 @@
float xInvInset,
float yInvInset) {
return SkNEW_ARGS(GrMagnifierEffect, (texture,
- bounds,
xOffset,
yOffset,
xInvZoom,
@@ -50,22 +48,15 @@
GrGLFragmentProcessor* createGLInstance() const override;
- const SkRect& bounds() const { return fBounds; } // Bounds of source image.
- // Offset to apply to zoomed pixels, (srcRect position / texture size).
float x_offset() const { return fXOffset; }
float y_offset() const { return fYOffset; }
-
- // Scale to apply to zoomed pixels (srcRect size / bounds size).
float x_inv_zoom() const { return fXInvZoom; }
float y_inv_zoom() const { return fYInvZoom; }
-
- // 1/radius over which to transition from unzoomed to zoomed pixels (bounds size / inset).
float x_inv_inset() const { return fXInvInset; }
float y_inv_inset() const { return fYInvInset; }
private:
GrMagnifierEffect(GrTexture* texture,
- const SkRect& bounds,
float xOffset,
float yOffset,
float xInvZoom,
@@ -73,7 +64,6 @@
float xInvInset,
float yInvInset)
: GrSingleTextureEffect(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture))
- , fBounds(bounds)
, fXOffset(xOffset)
, fYOffset(yOffset)
, fXInvZoom(xInvZoom)
@@ -89,7 +79,6 @@
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
- SkRect fBounds;
float fXOffset;
float fYOffset;
float fXInvZoom;
@@ -120,7 +109,6 @@
UniformHandle fOffsetVar;
UniformHandle fInvZoomVar;
UniformHandle fInvInsetVar;
- UniformHandle fBoundsVar;
typedef GrGLFragmentProcessor INHERITED;
};
@@ -146,10 +134,6 @@
GrGLProgramBuilder::kFragment_Visibility |
GrGLProgramBuilder::kVertex_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision, "InvInset");
- fBoundsVar = builder->addUniform(
- GrGLProgramBuilder::kFragment_Visibility |
- GrGLProgramBuilder::kVertex_Visibility,
- kVec4f_GrSLType, kDefault_GrSLPrecision, "Bounds");
GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0);
@@ -158,9 +142,9 @@
builder->getUniformCStr(fOffsetVar),
coords2D.c_str(),
builder->getUniformCStr(fInvZoomVar));
- const char* bounds = builder->getUniformCStr(fBoundsVar);
- fsBuilder->codeAppendf("\t\tvec2 delta = (coord - %s.xy) * %s.zw;\n", bounds, bounds);
- fsBuilder->codeAppendf("\t\tdelta = min(delta, vec2(1.0, 1.0) - delta);\n");
+
+ fsBuilder->codeAppend("\t\tvec2 delta = min(coord, vec2(1.0, 1.0) - coord);\n");
+
fsBuilder->codeAppendf("\t\tdelta = delta * %s;\n", builder->getUniformCStr(fInvInsetVar));
fsBuilder->codeAppend("\t\tfloat weight = 0.0;\n");
@@ -191,8 +175,6 @@
pdman.set2f(fOffsetVar, zoom.x_offset(), zoom.y_offset());
pdman.set2f(fInvZoomVar, zoom.x_inv_zoom(), zoom.y_inv_zoom());
pdman.set2f(fInvInsetVar, zoom.x_inv_inset(), zoom.y_inv_inset());
- pdman.set4f(fBoundsVar, zoom.bounds().x(), zoom.bounds().y(),
- zoom.bounds().width(), zoom.bounds().height());
}
/////////////////////////////////////////////////////////////////////
@@ -224,7 +206,6 @@
GrFragmentProcessor* effect = GrMagnifierEffect::Create(
texture,
- SkRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight)),
(float) width / texture->width(),
(float) height / texture->height(),
texture->width() / (float) x,
@@ -239,8 +220,7 @@
bool GrMagnifierEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
const GrMagnifierEffect& s = sBase.cast<GrMagnifierEffect>();
- return (this->fBounds == s.fBounds &&
- this->fXOffset == s.fXOffset &&
+ return (this->fXOffset == s.fXOffset &&
this->fYOffset == s.fYOffset &&
this->fXInvZoom == s.fXInvZoom &&
this->fYInvZoom == s.fYInvZoom &&
@@ -278,27 +258,18 @@
#if SK_SUPPORT_GPU
bool SkMagnifierImageFilter::asFragmentProcessor(GrFragmentProcessor** fp, GrTexture* texture,
- const SkMatrix&, const SkIRect&bounds) const {
+ const SkMatrix&, const SkIRect&) const {
if (fp) {
- SkScalar yOffset = texture->origin() == kTopLeft_GrSurfaceOrigin ? fSrcRect.y() :
- texture->height() - fSrcRect.height() * texture->height() / bounds.height()
- - fSrcRect.y();
- int boundsY = (texture->origin() == kTopLeft_GrSurfaceOrigin) ? bounds.y() :
- (texture->height() - bounds.height());
- SkRect effectBounds = SkRect::MakeXYWH(
- SkIntToScalar(bounds.x()) / texture->width(),
- SkIntToScalar(boundsY) / texture->height(),
- SkIntToScalar(texture->width()) / bounds.width(),
- SkIntToScalar(texture->height()) / bounds.height());
+ SkScalar yOffset = (texture->origin() == kTopLeft_GrSurfaceOrigin) ? fSrcRect.y() :
+ (texture->height() - (fSrcRect.y() + fSrcRect.height()));
SkScalar invInset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1;
*fp = GrMagnifierEffect::Create(texture,
- effectBounds,
fSrcRect.x() / texture->width(),
yOffset / texture->height(),
- fSrcRect.width() / bounds.width(),
- fSrcRect.height() / bounds.height(),
- bounds.width() * invInset,
- bounds.height() * invInset);
+ fSrcRect.width() / texture->width(),
+ fSrcRect.height() / texture->height(),
+ texture->width() * invInset,
+ texture->height() * invInset);
}
return true;
}
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 021cfba..38a22e6 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -121,15 +121,10 @@
///////////////////////////////////////////////////////////////////////////////
SkGpuDevice* SkGpuDevice::Create(GrRenderTarget* rt, const SkSurfaceProps* props, unsigned flags) {
- return SkGpuDevice::Create(rt, rt->width(), rt->height(), props, flags);
-}
-
-SkGpuDevice* SkGpuDevice::Create(GrRenderTarget* rt, int width, int height,
- const SkSurfaceProps* props, unsigned flags) {
if (!rt || rt->wasDestroyed()) {
return NULL;
}
- return SkNEW_ARGS(SkGpuDevice, (rt, width, height, props, flags));
+ return SkNEW_ARGS(SkGpuDevice, (rt, props, flags));
}
static SkDeviceProperties surfaceprops_to_deviceprops(const SkSurfaceProps* props) {
@@ -148,8 +143,7 @@
}
}
-SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height,
- const SkSurfaceProps* props, unsigned flags)
+SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, const SkSurfaceProps* props, unsigned flags)
: INHERITED(surfaceprops_to_deviceprops(props))
, fSurfaceProps(copy_or_default_props(props))
{
@@ -160,7 +154,7 @@
fRenderTarget = SkRef(rt);
- SkImageInfo info = rt->surfacePriv().info().makeWH(width, height);
+ SkImageInfo info = rt->surfacePriv().info();
SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt));
fLegacyBitmap.setInfo(info);
fLegacyBitmap.setPixelRef(pr)->unref();
@@ -217,7 +211,7 @@
return NULL;
}
- return SkNEW_ARGS(SkGpuDevice, (rt, info.width(), info.height(), props, flags));
+ return SkNEW_ARGS(SkGpuDevice, (rt, props, flags));
}
SkGpuDevice::~SkGpuDevice() {
@@ -742,9 +736,9 @@
return mask;
}
-SkBitmap wrap_texture(GrTexture* texture, int width, int height) {
+SkBitmap wrap_texture(GrTexture* texture) {
SkBitmap result;
- result.setInfo(SkImageInfo::MakeN32Premul(width, height));
+ result.setInfo(texture->surfacePriv().info());
result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (result.info(), texture)))->unref();
return result;
}
@@ -1480,7 +1474,6 @@
}
bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
- int width, int height,
const SkImageFilter* filter,
const SkImageFilter::Context& ctx,
SkBitmap* result, SkIPoint* offset) {
@@ -1491,8 +1484,7 @@
SkDeviceImageFilterProxy proxy(this, SkSurfaceProps(0, getLeakyProperties().pixelGeometry()));
if (filter->canFilterImageGPU()) {
- return filter->filterImageGPU(&proxy, wrap_texture(texture, width, height),
- ctx, result, offset);
+ return filter->filterImageGPU(&proxy, wrap_texture(texture), ctx, result, offset);
} else {
return false;
}
@@ -1531,7 +1523,7 @@
// This cache is transient, and is freed (along with all its contained
// textures) when it goes out of scope.
SkImageFilter::Context ctx(matrix, clipBounds, cache);
- if (this->filterTexture(fContext, texture, w, h, filter, ctx, &filteredBitmap,
+ if (this->filterTexture(fContext, texture, filter, ctx, &filteredBitmap,
&offset)) {
texture = (GrTexture*) filteredBitmap.getTexture();
w = filteredBitmap.width();
@@ -1645,8 +1637,8 @@
// textures) when it goes out of scope.
SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache());
SkImageFilter::Context ctx(matrix, clipBounds, cache);
- if (this->filterTexture(fContext, devTex, device->width(), device->height(),
- filter, ctx, &filteredBitmap, &offset)) {
+ if (this->filterTexture(fContext, devTex, filter, ctx, &filteredBitmap,
+ &offset)) {
devTex = filteredBitmap.getTexture();
w = filteredBitmap.width();
h = filteredBitmap.height();
@@ -1699,8 +1691,7 @@
// must be pushed upstack.
AutoBitmapTexture abt(fContext, src, NULL, &texture);
- return this->filterTexture(fContext, texture, src.width(), src.height(),
- filter, ctx, result, offset);
+ return this->filterTexture(fContext, texture, filter, ctx, result, offset);
}
///////////////////////////////////////////////////////////////////////////////
@@ -1910,8 +1901,7 @@
if (texture) {
SkSurfaceProps props(fSurfaceProps.flags(), cinfo.fPixelGeometry);
- return SkGpuDevice::Create(
- texture->asRenderTarget(), cinfo.fInfo.width(), cinfo.fInfo.height(), &props, flags);
+ return SkGpuDevice::Create(texture->asRenderTarget(), &props, flags);
} else {
SkErrorInternals::SetError( kInternalError_SkError,
"---- failed to create compatible device texture [%d %d]\n",
diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h
index 8c3414b..2db40fc 100644
--- a/src/gpu/SkGpuDevice.h
+++ b/src/gpu/SkGpuDevice.h
@@ -41,13 +41,6 @@
static SkGpuDevice* Create(GrRenderTarget* target, const SkSurfaceProps*, unsigned flags = 0);
/**
- * Creates an SkGpuDevice from a GrRenderTarget whose texture width/height is
- * different than its actual width/height (e.g., approx-match scratch texture).
- */
- static SkGpuDevice* Create(GrRenderTarget* target, int width, int height,
- const SkSurfaceProps*, unsigned flags = 0);
-
- /**
* New device that will create an offscreen renderTarget based on the ImageInfo and
* sampleCount. The Budgeted param controls whether the device's backing store counts against
* the resource cache budget. On failure, returns NULL.
@@ -74,7 +67,7 @@
GrRenderTarget* accessRenderTarget() override;
SkImageInfo imageInfo() const override {
- return fLegacyBitmap.info();
+ return fRenderTarget ? fRenderTarget->surfacePriv().info() : SkImageInfo::MakeUnknown();
}
const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
@@ -128,7 +121,7 @@
const SkImageFilter::Context&,
SkBitmap*, SkIPoint*) override;
- bool filterTexture(GrContext*, GrTexture*, int width, int height, const SkImageFilter*,
+ bool filterTexture(GrContext*, GrTexture*, const SkImageFilter*,
const SkImageFilter::Context&,
SkBitmap* result, SkIPoint* offset);
@@ -154,7 +147,7 @@
SkBitmap fLegacyBitmap;
bool fNeedClear;
- SkGpuDevice(GrRenderTarget*, int width, int height, const SkSurfaceProps*, unsigned flags);
+ SkGpuDevice(GrRenderTarget*, const SkSurfaceProps*, unsigned flags);
SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;