Reduce usage of MakeRenderTargetDirect

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2187573002

Review-Url: https://codereview.chromium.org/2187573002
This commit is contained in:
robertphillips 2016-07-26 11:38:17 -07:00 committed by Commit bot
parent 3a0dbde1cf
commit 7e92276554
12 changed files with 73 additions and 74 deletions

View File

@ -140,11 +140,19 @@ public:
* Return a new surface whose contents will be drawn to an offscreen
* render target, allocated by the surface.
*/
static sk_sp<SkSurface> MakeRenderTarget(
GrContext*, SkBudgeted, const SkImageInfo&, int sampleCount, const SkSurfaceProps*);
static sk_sp<SkSurface> MakeRenderTarget(GrContext*, SkBudgeted, const SkImageInfo&,
int sampleCount, GrSurfaceOrigin,
const SkSurfaceProps*);
static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
const SkImageInfo& info, int sampleCount,
const SkSurfaceProps* props) {
return MakeRenderTarget(context, budgeted, info, sampleCount,
kBottomLeft_GrSurfaceOrigin, props);
}
static sk_sp<SkSurface> MakeRenderTarget(GrContext* gr, SkBudgeted b, const SkImageInfo& info) {
return MakeRenderTarget(gr, b, info, 0, nullptr);
return MakeRenderTarget(gr, b, info, 0, kBottomLeft_GrSurfaceOrigin, nullptr);
}
#ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API

View File

@ -281,6 +281,7 @@ public:
}
const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
SkColorSpace* getColorSpace() const { return fColorSpace.get(); }
GrSurfaceOrigin origin() const { return fRenderTarget->origin(); }
bool wasAbandoned() const;

View File

@ -124,14 +124,15 @@ sk_sp<SkBaseDevice> SkGpuDevice::Make(sk_sp<GrDrawContext> drawContext,
sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted,
const SkImageInfo& info, int sampleCount,
GrSurfaceOrigin origin,
const SkSurfaceProps* props, InitContents init) {
unsigned flags;
if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) {
return nullptr;
}
sk_sp<GrDrawContext> drawContext(CreateDrawContext(context, budgeted, info,
sampleCount, props));
sk_sp<GrDrawContext> drawContext(MakeDrawContext(context, budgeted, info,
sampleCount, origin, props));
if (!drawContext) {
return nullptr;
}
@ -153,11 +154,12 @@ SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, int width, int height
}
}
sk_sp<GrDrawContext> SkGpuDevice::CreateDrawContext(GrContext* context,
SkBudgeted budgeted,
const SkImageInfo& origInfo,
int sampleCount,
const SkSurfaceProps* surfaceProps) {
sk_sp<GrDrawContext> SkGpuDevice::MakeDrawContext(GrContext* context,
SkBudgeted budgeted,
const SkImageInfo& origInfo,
int sampleCount,
GrSurfaceOrigin origin,
const SkSurfaceProps* surfaceProps) {
if (kUnknown_SkColorType == origInfo.colorType() ||
origInfo.width() < 0 || origInfo.height() < 0) {
return nullptr;
@ -188,7 +190,7 @@ sk_sp<GrDrawContext> SkGpuDevice::CreateDrawContext(GrContext* context,
return context->newDrawContext(SkBackingFit::kExact, // Why exact?
origInfo.width(), origInfo.height(),
config, sk_ref_sp(cs), sampleCount,
kDefault_GrSurfaceOrigin, surfaceProps, budgeted);
origin, surfaceProps, budgeted);
}
sk_sp<SkSpecialImage> SkGpuDevice::filterTexture(const SkDraw& draw,
@ -276,11 +278,12 @@ void SkGpuDevice::replaceDrawContext(bool shouldRetainContent) {
SkBudgeted budgeted = fRenderTarget->resourcePriv().isBudgeted();
sk_sp<GrDrawContext> newDC(CreateDrawContext(this->context(),
budgeted,
this->imageInfo(),
fDrawContext->numColorSamples(),
&this->surfaceProps()));
sk_sp<GrDrawContext> newDC(MakeDrawContext(this->context(),
budgeted,
this->imageInfo(),
fDrawContext->numColorSamples(),
fDrawContext->origin(),
&this->surfaceProps()));
if (!newDC) {
return;
}
@ -1769,7 +1772,7 @@ sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfa
// TODO: Change the signature of newSurface to take a budgeted parameter.
static const SkBudgeted kBudgeted = SkBudgeted::kNo;
return SkSurface::MakeRenderTarget(fContext, kBudgeted, info, fDrawContext->desc().fSampleCnt,
&props);
fDrawContext->origin(), &props);
}
SkImageFilterCache* SkGpuDevice::getImageFilterCache() {

View File

@ -62,7 +62,8 @@ public:
* the resource cache budget. On failure, returns nullptr.
*/
static sk_sp<SkGpuDevice> Make(GrContext*, SkBudgeted, const SkImageInfo&,
int sampleCount, const SkSurfaceProps*, InitContents);
int sampleCount, GrSurfaceOrigin,
const SkSurfaceProps*, InitContents);
~SkGpuDevice() override {}
@ -265,11 +266,12 @@ private:
bool drawDashLine(const SkPoint pts[2], const SkPaint& paint);
void drawStrokedLine(const SkPoint pts[2], const SkDraw&, const SkPaint&);
static sk_sp<GrDrawContext> CreateDrawContext(GrContext*,
SkBudgeted,
const SkImageInfo&,
int sampleCount,
const SkSurfaceProps*);
static sk_sp<GrDrawContext> MakeDrawContext(GrContext*,
SkBudgeted,
const SkImageInfo&,
int sampleCount,
GrSurfaceOrigin,
const SkSurfaceProps*);
friend class GrAtlasTextContext;
friend class SkSurface_Gpu; // for access to surfaceProps

View File

@ -228,8 +228,8 @@ sk_sp<SkSurface> SkSurface::MakeRenderTargetDirect(GrRenderTarget*, sk_sp<SkColo
return nullptr;
}
sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext*, SkBudgeted, const SkImageInfo&, int,
const SkSurfaceProps*) {
sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext*, SkBudgeted, const SkImageInfo&,
int, GrSurfaceOrigin, const SkSurfaceProps*) {
return nullptr;
}

View File

@ -67,10 +67,11 @@ SkCanvas* SkSurface_Gpu::onNewCanvas() {
sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) {
int sampleCount = fDevice->accessDrawContext()->numColorSamples();
GrSurfaceOrigin origin = fDevice->accessDrawContext()->origin();
// TODO: Make caller specify this (change virtual signature of onNewSurface).
static const SkBudgeted kBudgeted = SkBudgeted::kNo;
return SkSurface::MakeRenderTarget(fDevice->context(), kBudgeted, info, sampleCount,
&this->props());
origin, &this->props());
}
sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, ForceCopyMode forceCopyMode) {
@ -145,9 +146,9 @@ sk_sp<SkSurface> SkSurface::MakeRenderTargetDirect(GrRenderTarget* target,
sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext* ctx, SkBudgeted budgeted,
const SkImageInfo& info, int sampleCount,
const SkSurfaceProps* props) {
GrSurfaceOrigin origin, const SkSurfaceProps* props) {
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(
ctx, budgeted, info, sampleCount, props, SkGpuDevice::kClear_InitContents));
ctx, budgeted, info, sampleCount, origin, props, SkGpuDevice::kClear_InitContents));
if (!device) {
return nullptr;
}

View File

@ -81,7 +81,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_GPUDevice, reporter, ctxInfo) {
SkImageInfo ii = SkImageInfo::MakeN32Premul(2*kWidth, 2*kHeight);
sk_sp<SkBaseDevice> gpuDev(SkGpuDevice::Make(context, SkBudgeted::kNo, ii,
0, nullptr, SkGpuDevice::kClear_InitContents));
0, kBottomLeft_GrSurfaceOrigin, nullptr,
SkGpuDevice::kClear_InitContents));
SkBitmap bm;
SkAssertResult(bm.tryAllocN32Pixels(kWidth, kHeight));

View File

@ -387,17 +387,10 @@ DEF_TEST(ReadPixels, reporter) {
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Gpu, reporter, ctxInfo) {
const SkImageInfo ii = SkImageInfo::MakeN32Premul(DEV_W, DEV_H);
for (auto& origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) {
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = DEV_W;
desc.fHeight = DEV_H;
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fOrigin = origin;
SkAutoTUnref<GrTexture> surfaceTexture(
ctxInfo.grContext()->textureProvider()->createTexture(desc, SkBudgeted::kNo));
auto surface(SkSurface::MakeRenderTargetDirect(surfaceTexture->asRenderTarget(), nullptr));
desc.fFlags = kNone_GrSurfaceFlags;
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo,
ii, 0, origin, nullptr));
test_readpixels(reporter, surface, kLast_BitmapInit);
}
}

View File

@ -41,12 +41,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
bool match;
static const size_t kRowBytes[] = {0, X_SIZE, X_SIZE + 1, 2 * X_SIZE - 1};
for (int rt = 0; rt < 2; ++rt) {
{
GrSurfaceDesc desc;
// let Skia know we will be using this texture as a render target
desc.fFlags = rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags;
// it is a single channel texture
desc.fConfig = kAlpha_8_GrPixelConfig;
desc.fFlags = kNone_GrSurfaceFlags;
desc.fConfig = kAlpha_8_GrPixelConfig; // it is a single channel texture
desc.fWidth = X_SIZE;
desc.fHeight = Y_SIZE;
@ -54,14 +52,16 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
memset(alphaData, 0, X_SIZE * Y_SIZE);
SkAutoTUnref<GrTexture> texture(
ctxInfo.grContext()->textureProvider()->createTexture(desc, SkBudgeted::kNo, alphaData,
0));
0));
if (!texture) {
if (!rt) {
ERRORF(reporter, "Could not create alpha texture.");
}
continue;
ERRORF(reporter, "Could not create alpha texture.");
return;
}
const SkImageInfo ii = SkImageInfo::MakeA8(X_SIZE, Y_SIZE);
sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(ctxInfo.grContext(),
SkBudgeted::kNo, ii));
// create a distinctive texture
for (int y = 0; y < Y_SIZE; ++y) {
for (int x = 0; x < X_SIZE; ++x) {
@ -87,14 +87,12 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
// make sure the original & read back versions match
SkString msg;
msg.printf("rt:%d, rb:%d A8", rt, SkToU32(rowBytes));
msg.printf("rb:%d A8", SkToU32(rowBytes));
validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), nonZeroRowBytes,
alphaData, msg);
// Now try writing on the single channel texture (if we could create as a RT).
if (texture->asRenderTarget()) {
sk_sp<SkSurface> surf(SkSurface::MakeRenderTargetDirect(texture->asRenderTarget(),
nullptr));
// Now try writing to a single channel surface (if we could create one).
if (surf) {
SkCanvas* canvas = surf->getCanvas();
SkPaint paint;
@ -106,8 +104,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
canvas->drawRect(rect, paint);
memset(readback.get(), kClearValue, nonZeroRowBytes * Y_SIZE);
result = texture->readPixels(0, 0, desc.fWidth, desc.fHeight,
desc.fConfig, readback.get(), rowBytes);
result = surf->readPixels(ii, readback.get(), nonZeroRowBytes, 0, 0);
REPORTER_ASSERT_MESSAGE(reporter, result, "A8 readPixels after clear failed");
match = true;

View File

@ -56,7 +56,7 @@ static sk_sp<SkSurface> create_gpu_surface(GrContext* context, SkAlphaType at =
if (requestedInfo) {
*requestedInfo = info;
}
return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr);
return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);
}
static sk_sp<SkSurface> create_gpu_scratch_surface(GrContext* context,
SkAlphaType at = kPremul_SkAlphaType,
@ -65,7 +65,7 @@ static sk_sp<SkSurface> create_gpu_scratch_surface(GrContext* context,
if (requestedInfo) {
*requestedInfo = info;
}
return SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 0, nullptr);
return SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info);
}
#endif
@ -79,8 +79,7 @@ DEF_TEST(SurfaceEmpty, reporter) {
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, ctxInfo) {
const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
REPORTER_ASSERT(reporter, nullptr ==
SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo, info, 0,
nullptr));
SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo, info));
}
#endif
@ -335,13 +334,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, ctxInfo) {
desc.fHeight = 10;
desc.fFlags = kRenderTarget_GrBackendTextureFlag;
desc.fTextureHandle = textureObject;
GrTexture* texture = context->textureProvider()->wrapBackendTexture(desc);
{
auto surface(SkSurface::MakeRenderTargetDirect(texture->asRenderTarget(), nullptr));
sk_sp<SkSurface> surface(SkSurface::MakeFromBackendTexture(context, desc, nullptr));
test_unique_image_snap(reporter, surface.get(), true, imageBackingStore,
surfaceBackingStore);
}
texture->unref();
context->getGpu()->deleteTestingOnlyBackendTexture(textureObject);
}
}

View File

@ -407,16 +407,11 @@ DEF_TEST(WritePixels, reporter) {
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WritePixels_Gpu, reporter, ctxInfo) {
const SkImageInfo ii = SkImageInfo::MakeN32Premul(DEV_W, DEV_H);
for (auto& origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = DEV_W;
desc.fHeight = DEV_H;
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fOrigin = origin;
SkAutoTUnref<GrTexture> texture(
ctxInfo.grContext()->textureProvider()->createTexture(desc, SkBudgeted::kNo));
auto surface(SkSurface::MakeRenderTargetDirect(texture->asRenderTarget(), nullptr));
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo,
ii, 0, origin, nullptr));
test_write_pixels(reporter, surface.get());
}
}

View File

@ -26,8 +26,7 @@ DEF_TEST(skbug5221, r) {
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(skbug5221_GPU, r, contextInfo) {
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(contextInfo.grContext(), SkBudgeted::kYes,
SkImageInfo::MakeN32Premul(256, 256), 0,
nullptr));
SkImageInfo::MakeN32Premul(256, 256)));
test(surface->getCanvas());
}
#endif