Tighten up SkSpecialSurface factory functions

This is split out of https://codereview.chromium.org/1930013002/ ((Mostly) Retract GrRenderTarget from SkGpuDevice)

GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1925313002

Review-Url: https://codereview.chromium.org/1925313002
This commit is contained in:
robertphillips 2016-04-28 15:09:34 -07:00 committed by Commit bot
parent 175dd9b5e3
commit 4df1656f0f
5 changed files with 36 additions and 67 deletions

View File

@ -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 {

View File

@ -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

View File

@ -51,18 +51,13 @@ public:
sk_sp<SkSpecialImage> makeImageSnapshot();
#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
/**

View File

@ -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
{

View File

@ -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