aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-04-28 15:09:34 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-28 15:09:34 -0700
commit4df1656f0f728ed428c3ab8f7beb19703b27c28e (patch)
tree6c3c7fd910308f6e2b12a05df43be1f7cc279825
parent175dd9b5e3d7d749738dac743d2ac360b5340187 (diff)
Tighten up SkSpecialSurface factory functions
-rw-r--r--src/core/SkSpecialImage.cpp15
-rw-r--r--src/core/SkSpecialSurface.cpp38
-rw-r--r--src/core/SkSpecialSurface.h11
-rw-r--r--tests/ImageFilterTest.cpp9
-rw-r--r--tests/SpecialSurfaceTest.cpp30
5 files changed, 36 insertions, 67 deletions
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp
index f18e6a7c7c..420b3f1e23 100644
--- a/src/core/SkSpecialImage.cpp
+++ b/src/core/SkSpecialImage.cpp
@@ -252,10 +252,12 @@ public:
#if SK_SUPPORT_GPU
GrTexture* texture = as_IB(fImage.get())->peekTexture();
if (texture) {
- GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info, *texture->getContext()->caps());
- desc.fFlags = kRenderTarget_GrSurfaceFlag;
+ GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *texture->getContext()->caps());
- return SkSpecialSurface::MakeRenderTarget(texture->getContext(), desc);
+ return SkSpecialSurface::MakeRenderTarget(texture->getContext(),
+ info.width(),
+ info.height(),
+ config);
}
#endif
return SkSpecialSurface::MakeRaster(info, nullptr);
@@ -528,10 +530,11 @@ public:
return nullptr;
}
- GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info, *fTexture->getContext()->caps());
- desc.fFlags = kRenderTarget_GrSurfaceFlag;
+ GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fTexture->getContext()->caps());
- return SkSpecialSurface::MakeRenderTarget(fTexture->getContext(), desc);
+ return SkSpecialSurface::MakeRenderTarget(fTexture->getContext(),
+ info.width(), info.height(),
+ config);
}
sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override {
diff --git a/src/core/SkSpecialSurface.cpp b/src/core/SkSpecialSurface.cpp
index 2973aa1f9b..eeefb2afa8 100644
--- a/src/core/SkSpecialSurface.cpp
+++ b/src/core/SkSpecialSurface.cpp
@@ -113,6 +113,7 @@ sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRaster(const SkImageInfo& info,
class SkSpecialSurface_Gpu : public SkSpecialSurface_Base {
public:
SkSpecialSurface_Gpu(sk_sp<GrTexture> texture,
+ int width, int height,
const SkIRect& subset,
const SkSurfaceProps* props)
: INHERITED(subset, props)
@@ -120,13 +121,14 @@ public:
SkASSERT(fTexture->asRenderTarget());
- SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderTarget(), props,
- SkGpuDevice::kUninit_InitContents));
+ sk_sp<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderTarget(), width, height,
+ props,
+ SkGpuDevice::kUninit_InitContents));
if (!device) {
return;
}
- fCanvas.reset(new SkCanvas(device));
+ fCanvas.reset(new SkCanvas(device.get()));
fCanvas->clipRect(SkRect::Make(subset));
}
@@ -146,31 +148,27 @@ private:
typedef SkSpecialSurface_Base INHERITED;
};
-sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(const SkIRect& subset,
- sk_sp<GrTexture> texture,
- const SkSurfaceProps* props) {
- if (!texture->asRenderTarget()) {
- return nullptr;
- }
-
- return sk_make_sp<SkSpecialSurface_Gpu>(std::move(texture), subset, props);
-}
-
sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context,
- const GrSurfaceDesc& desc,
- const SkSurfaceProps* props) {
- if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) {
+ int width, int height,
+ GrPixelConfig config) {
+ if (!context) {
return nullptr;
}
- sk_sp<GrTexture> temp(context->textureProvider()->createApproxTexture(desc));
- if (!temp) {
+ GrSurfaceDesc desc;
+ desc.fFlags = kRenderTarget_GrSurfaceFlag;
+ desc.fWidth = width;
+ desc.fHeight = height;
+ desc.fConfig = config;
+
+ sk_sp<GrTexture> tex(context->textureProvider()->createApproxTexture(desc));
+ if (!tex) {
return nullptr;
}
- const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight);
+ const SkIRect subset = SkIRect::MakeWH(width, height);
- return sk_make_sp<SkSpecialSurface_Gpu>(std::move(temp), subset, props);
+ return sk_make_sp<SkSpecialSurface_Gpu>(std::move(tex), width, height, subset, nullptr);
}
#endif
diff --git a/src/core/SkSpecialSurface.h b/src/core/SkSpecialSurface.h
index 2135347e35..d971648202 100644
--- a/src/core/SkSpecialSurface.h
+++ b/src/core/SkSpecialSurface.h
@@ -52,17 +52,12 @@ public:
#if SK_SUPPORT_GPU
/**
- * Use an existing (renderTarget-capable) GrTexture as the backing store.
- */
- static sk_sp<SkSpecialSurface> MakeFromTexture(const SkIRect& subset, sk_sp<GrTexture>,
- const SkSurfaceProps* = nullptr);
-
- /**
* Allocate a new GPU-backed SkSpecialSurface. If the requested surface cannot
* be created, nullptr will be returned.
*/
- static sk_sp<SkSpecialSurface> MakeRenderTarget(GrContext*, const GrSurfaceDesc&,
- const SkSurfaceProps* = nullptr);
+ static sk_sp<SkSpecialSurface> MakeRenderTarget(GrContext*,
+ int width, int height,
+ GrPixelConfig config);
#endif
/**
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index 54e9a60007..56b3aaf5cd 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -370,12 +370,9 @@ static sk_sp<SkImageFilter> make_blue(sk_sp<SkImageFilter> input,
static sk_sp<SkSpecialSurface> create_empty_special_surface(GrContext* context, int widthHeight) {
#if SK_SUPPORT_GPU
if (context) {
- GrSurfaceDesc desc;
- desc.fConfig = kSkia8888_GrPixelConfig;
- desc.fFlags = kRenderTarget_GrSurfaceFlag;
- desc.fWidth = widthHeight;
- desc.fHeight = widthHeight;
- return SkSpecialSurface::MakeRenderTarget(context, desc);
+ return SkSpecialSurface::MakeRenderTarget(context,
+ widthHeight, widthHeight,
+ kSkia8888_GrPixelConfig);
} else
#endif
{
diff --git a/tests/SpecialSurfaceTest.cpp b/tests/SpecialSurfaceTest.cpp
index 8c560fef79..3c351a527c 100644
--- a/tests/SpecialSurfaceTest.cpp
+++ b/tests/SpecialSurfaceTest.cpp
@@ -79,35 +79,11 @@ DEF_TEST(SpecialSurface_Raster2, reporter) {
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SpecialSurface_Gpu1, reporter, ctxInfo) {
- GrSurfaceDesc desc;
- desc.fConfig = kSkia8888_GrPixelConfig;
- desc.fFlags = kRenderTarget_GrSurfaceFlag;
- desc.fWidth = kSmallerSize;
- desc.fHeight = kSmallerSize;
-
- sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeRenderTarget(ctxInfo.fGrContext, desc));
+ sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeRenderTarget(ctxInfo.fGrContext,
+ kSmallerSize, kSmallerSize,
+ kSkia8888_GrPixelConfig));
test_surface(surf, reporter, 0);
}
-// test the more flexible factory
-DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SpecialSurface_Gpu2, reporter, ctxInfo) {
- GrSurfaceDesc desc;
- desc.fConfig = kSkia8888_GrPixelConfig;
- desc.fFlags = kRenderTarget_GrSurfaceFlag;
- desc.fWidth = kFullSize;
- desc.fHeight = kFullSize;
-
- sk_sp<GrTexture> temp(ctxInfo.fGrContext->textureProvider()->createApproxTexture(desc));
- SkASSERT_RELEASE(temp);
-
- const SkIRect subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
-
- sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeFromTexture(subset, std::move(temp)));
-
- test_surface(surf, reporter, kPad);
-
- // TODO: check that the clear didn't escape the active region
-}
-
#endif