Add SkSurface_Gpu::MakeWrappedRenderTarget method
This is pulled out of https://skia-review.googlesource.com/c/skia/+/101480 (Implement GPU/OpList DDLs) Change-Id: I12b1ac346c7c1fa10f2120bc92bee63c93fc2249 Reviewed-on: https://skia-review.googlesource.com/102101 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
9c17391cef
commit
d5f9cdd4b3
@ -100,7 +100,7 @@ DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
|
||||
}
|
||||
|
||||
sk_sp<GrSurfaceContext> tContext = context->contextPriv().makeWrappedSurfaceContext(
|
||||
std::move(proxy), nullptr);
|
||||
std::move(proxy));
|
||||
|
||||
if (!tContext) {
|
||||
return;
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
}
|
||||
|
||||
// TODO: remove this. It is just scaffolding to get something up & running
|
||||
bool draw(SkSurface*);
|
||||
bool draw(SkSurface*) const;
|
||||
|
||||
private:
|
||||
const SkSurfaceCharacterization fCharacterization;
|
||||
|
@ -79,7 +79,7 @@ std::unique_ptr<SkDeferredDisplayList> SkDeferredDisplayListRecorder::detach() {
|
||||
|
||||
// Placeholder. Ultimately, the SkSurface_Gpu will pass the wrapped opLists to its
|
||||
// renderTargetContext.
|
||||
bool SkDeferredDisplayList::draw(SkSurface* surface) {
|
||||
bool SkDeferredDisplayList::draw(SkSurface* surface) const {
|
||||
surface->getCanvas()->drawImage(fImage.get(), 0, 0);
|
||||
return true;
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ public:
|
||||
}
|
||||
|
||||
sk_sp<GrSurfaceContext> sContext = fContext->contextPriv().makeWrappedSurfaceContext(
|
||||
fTextureProxy, nullptr);
|
||||
fTextureProxy);
|
||||
if (!sContext) {
|
||||
return false;
|
||||
}
|
||||
|
@ -25,7 +25,9 @@
|
||||
#include "GrTexture.h"
|
||||
#include "GrTextureContext.h"
|
||||
#include "GrTracing.h"
|
||||
|
||||
#include "SkConvertPixels.h"
|
||||
#include "SkDeferredDisplayList.h"
|
||||
#include "SkGr.h"
|
||||
#include "SkJSONWriter.h"
|
||||
#include "SkMakeUnique.h"
|
||||
@ -263,6 +265,13 @@ bool GrContext::init(const GrContextOptions& options) {
|
||||
prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kSmall;
|
||||
}
|
||||
|
||||
if (!fResourceCache) {
|
||||
// DDL TODO: remove this crippling of the path renderer chain
|
||||
// Disable the small path renderer bc of the proxies in the atlas. They need to be
|
||||
// unified when the opLists are added back to the destination drawing manager.
|
||||
prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kSmall;
|
||||
}
|
||||
|
||||
GrAtlasTextContext::Options atlasTextContextOptions;
|
||||
atlasTextContextOptions.fMaxDistanceFieldFontSize = options.fGlyphsAsPathsFontSize;
|
||||
atlasTextContextOptions.fMinDistanceFieldFontSize = options.fMinDistanceFieldFontSize;
|
||||
@ -800,14 +809,16 @@ void GrContextPriv::flushSurfaceIO(GrSurfaceProxy* proxy) {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
sk_sp<GrSurfaceContext> GrContextPriv::makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy> proxy,
|
||||
sk_sp<SkColorSpace> colorSpace) {
|
||||
sk_sp<SkColorSpace> colorSpace,
|
||||
const SkSurfaceProps* props) {
|
||||
ASSERT_SINGLE_OWNER_PRIV
|
||||
|
||||
if (proxy->asRenderTargetProxy()) {
|
||||
return this->drawingManager()->makeRenderTargetContext(std::move(proxy),
|
||||
std::move(colorSpace), nullptr);
|
||||
std::move(colorSpace), props);
|
||||
} else {
|
||||
SkASSERT(proxy->asTextureProxy());
|
||||
SkASSERT(!props);
|
||||
return this->drawingManager()->makeTextureContext(std::move(proxy), std::move(colorSpace));
|
||||
}
|
||||
}
|
||||
@ -828,7 +839,7 @@ sk_sp<GrSurfaceContext> GrContextPriv::makeDeferredSurfaceContext(const GrSurfac
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return this->makeWrappedSurfaceContext(std::move(proxy), nullptr);
|
||||
return this->makeWrappedSurfaceContext(std::move(proxy));
|
||||
}
|
||||
|
||||
sk_sp<GrTextureContext> GrContextPriv::makeBackendTextureContext(const GrBackendTexture& tex,
|
||||
@ -903,7 +914,6 @@ void GrContextPriv::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBO
|
||||
fContext->fDrawingManager->addOnFlushCallbackObject(onFlushCBObject);
|
||||
}
|
||||
|
||||
|
||||
static inline GrPixelConfig GrPixelConfigFallback(GrPixelConfig config) {
|
||||
switch (config) {
|
||||
case kAlpha_8_GrPixelConfig:
|
||||
|
@ -29,7 +29,9 @@ public:
|
||||
|
||||
GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); }
|
||||
|
||||
sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>, sk_sp<SkColorSpace>);
|
||||
sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>,
|
||||
sk_sp<SkColorSpace> = nullptr,
|
||||
const SkSurfaceProps* = nullptr);
|
||||
|
||||
sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc&,
|
||||
GrMipMapped,
|
||||
|
@ -54,7 +54,7 @@ bool GrProxyProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTexturePr
|
||||
// If there is already a GrResource with this key then the caller has violated the normal
|
||||
// usage pattern of uniquely keyed resources (e.g., they have created one w/o first seeing
|
||||
// if it already existed in the cache).
|
||||
SkASSERT(!fResourceCache->findAndRefUniqueResource(key));
|
||||
SkASSERT(!fResourceCache || !fResourceCache->findAndRefUniqueResource(key));
|
||||
|
||||
// Uncached resources can never have a unique key, unless they're wrapped resources. Wrapped
|
||||
// resources are a special case: the unique keys give us a weak ref so that we can reuse the
|
||||
@ -133,6 +133,10 @@ sk_sp<GrTextureProxy> GrProxyProvider::findOrCreateProxyByUniqueKey(const GrUniq
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!fResourceCache) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GrGpuResource* resource = fResourceCache->findAndRefUniqueResource(key);
|
||||
if (!resource) {
|
||||
return nullptr;
|
||||
|
@ -140,8 +140,8 @@ sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc,
|
||||
SkBackingFit::kExact,
|
||||
budgeted);
|
||||
if (proxy) {
|
||||
sk_sp<GrSurfaceContext> sContext =
|
||||
context->contextPriv().makeWrappedSurfaceContext(std::move(proxy), nullptr);
|
||||
sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
|
||||
std::move(proxy));
|
||||
if (sContext) {
|
||||
if (sContext->writePixels(srcInfo, mipLevel.fPixels, mipLevel.fRowBytes, 0, 0)) {
|
||||
return sk_ref_sp(sContext->asTextureProxy()->priv().peekTexture());
|
||||
|
@ -177,7 +177,7 @@ sk_sp<GrTextureProxy> GrCopyBaseMipMapToTextureProxy(GrContext* ctx, GrTexturePr
|
||||
}
|
||||
|
||||
// Copy the base layer to our proxy
|
||||
sk_sp<GrSurfaceContext> sContext = ctx->contextPriv().makeWrappedSurfaceContext(proxy, nullptr);
|
||||
sk_sp<GrSurfaceContext> sContext = ctx->contextPriv().makeWrappedSurfaceContext(proxy);
|
||||
SkASSERT(sContext);
|
||||
SkAssertResult(sContext->copy(baseProxy));
|
||||
|
||||
|
@ -231,8 +231,7 @@ void GrTextureStripAtlas::lockTexture() {
|
||||
fKeyTable.rewind();
|
||||
}
|
||||
SkASSERT(proxy);
|
||||
fTexContext = fDesc.fContext->contextPriv().makeWrappedSurfaceContext(std::move(proxy),
|
||||
nullptr);
|
||||
fTexContext = fDesc.fContext->contextPriv().makeWrappedSurfaceContext(std::move(proxy));
|
||||
}
|
||||
|
||||
void GrTextureStripAtlas::unlockTexture() {
|
||||
|
@ -144,8 +144,7 @@ static bool save_pixels(GrContext* context, GrSurfaceProxy* sProxy, const char*
|
||||
}
|
||||
|
||||
sk_sp<GrSurfaceContext> sContext(context->contextPriv().makeWrappedSurfaceContext(
|
||||
sk_ref_sp(sProxy),
|
||||
nullptr));
|
||||
sk_ref_sp(sProxy)));
|
||||
if (!sContext || !sContext->asTextureProxy()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ public:
|
||||
}
|
||||
|
||||
virtual bool onCharacterize(SkSurfaceCharacterization*) const { return false; }
|
||||
virtual bool onDraw(SkDeferredDisplayList*) { return false; }
|
||||
virtual bool onDraw(const SkDeferredDisplayList*) { return false; }
|
||||
|
||||
inline SkCanvas* getCachedCanvas();
|
||||
inline sk_sp<SkImage> refCachedImage();
|
||||
|
@ -195,14 +195,14 @@ bool SkSurface_Gpu::isCompatible(const SkSurfaceCharacterization& data) const {
|
||||
data.surfaceProps() == rtc->surfaceProps();
|
||||
}
|
||||
|
||||
bool SkSurface_Gpu::onDraw(SkDeferredDisplayList* dl) {
|
||||
if (!this->isCompatible(dl->characterization())) {
|
||||
bool SkSurface_Gpu::onDraw(const SkDeferredDisplayList* ddl) {
|
||||
if (!this->isCompatible(ddl->characterization())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ultimately need to pass opLists from the DeferredDisplayList on to the
|
||||
// SkGpuDevice's renderTargetContext.
|
||||
return dl->draw(this);
|
||||
return ddl->draw(this);
|
||||
}
|
||||
|
||||
|
||||
@ -264,6 +264,23 @@ sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext* ctx, SkBudgeted budgeted
|
||||
return sk_make_sp<SkSurface_Gpu>(std::move(device));
|
||||
}
|
||||
|
||||
sk_sp<SkSurface> SkSurface_Gpu::MakeWrappedRenderTarget(GrContext* context,
|
||||
sk_sp<GrRenderTargetContext> rtc) {
|
||||
if (!context) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc),
|
||||
rtc->width(), rtc->height(),
|
||||
SkGpuDevice::kUninit_InitContents));
|
||||
if (!device) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return sk_make_sp<SkSurface_Gpu>(std::move(device));
|
||||
}
|
||||
|
||||
|
||||
sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, const GrBackendTexture& tex,
|
||||
GrSurfaceOrigin origin, int sampleCnt,
|
||||
sk_sp<SkColorSpace> colorSpace,
|
||||
|
@ -19,6 +19,9 @@ public:
|
||||
SkSurface_Gpu(sk_sp<SkGpuDevice>);
|
||||
~SkSurface_Gpu() override;
|
||||
|
||||
// This is an internal-only factory
|
||||
static sk_sp<SkSurface> MakeWrappedRenderTarget(GrContext*, sk_sp<GrRenderTargetContext>);
|
||||
|
||||
GrBackendObject onGetTextureHandle(BackendHandleAccess) override;
|
||||
bool onGetRenderTargetHandle(GrBackendObject*, BackendHandleAccess) override;
|
||||
SkCanvas* onNewCanvas() override;
|
||||
@ -31,7 +34,7 @@ public:
|
||||
bool onWait(int numSemaphores, const GrBackendSemaphore* waitSemaphores) override;
|
||||
bool onCharacterize(SkSurfaceCharacterization*) const override;
|
||||
bool isCompatible(const SkSurfaceCharacterization&) const;
|
||||
bool onDraw(SkDeferredDisplayList*) override;
|
||||
bool onDraw(const SkDeferredDisplayList*) override;
|
||||
|
||||
SkGpuDevice* getDevice() { return fDevice.get(); }
|
||||
|
||||
|
@ -86,8 +86,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
|
||||
}
|
||||
|
||||
sk_sp<GrSurfaceContext> dstContext =
|
||||
context->contextPriv().makeWrappedSurfaceContext(std::move(dst),
|
||||
nullptr);
|
||||
context->contextPriv().makeWrappedSurfaceContext(std::move(dst));
|
||||
|
||||
bool result = dstContext->copy(src.get(), srcRect, dstPoint);
|
||||
|
||||
|
@ -61,7 +61,7 @@ void runFPTest(skiatest::Reporter* reporter, GrContext* context,
|
||||
}
|
||||
|
||||
sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
|
||||
std::move(fpProxy), nullptr);
|
||||
std::move(fpProxy));
|
||||
REPORTER_ASSERT(reporter, sContext);
|
||||
|
||||
bool result = context->contextPriv().readSurfacePixels(sContext.get(),
|
||||
|
@ -204,7 +204,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter,
|
||||
// queued up copy) before we delete the backend texture. Thus we use readPixels here
|
||||
// just to force the synchronization.
|
||||
sk_sp<GrSurfaceContext> surfContext =
|
||||
context->contextPriv().makeWrappedSurfaceContext(genProxy, nullptr);
|
||||
context->contextPriv().makeWrappedSurfaceContext(genProxy);
|
||||
|
||||
SkBitmap bitmap;
|
||||
bitmap.allocPixels(imageInfo);
|
||||
|
@ -196,7 +196,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(InitialTextureClear, reporter, context_info)
|
||||
}
|
||||
|
||||
auto texCtx = context->contextPriv().makeWrappedSurfaceContext(
|
||||
std::move(proxy), nullptr);
|
||||
std::move(proxy));
|
||||
SkImageInfo info = SkImageInfo::Make(
|
||||
kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
||||
memset(data.get(), 0xAB, kSize * kSize * sizeof(uint32_t));
|
||||
|
@ -86,7 +86,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
sContext = context->contextPriv().makeWrappedSurfaceContext(std::move(proxy), nullptr);
|
||||
sContext = context->contextPriv().makeWrappedSurfaceContext(std::move(proxy));
|
||||
if (!sContext) {
|
||||
return;
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ static void run_test(skiatest::Reporter* reporter, GrContext* context,
|
||||
SkASSERT(proxy);
|
||||
|
||||
sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
|
||||
std::move(proxy), nullptr);
|
||||
std::move(proxy));
|
||||
|
||||
SkAssertResult(sContext->readPixels(dstInfo, readBuffer.begin(), 0, 0, 0));
|
||||
|
||||
|
@ -468,7 +468,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) {
|
||||
bmp.rowBytes());
|
||||
|
||||
sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
|
||||
std::move(proxy), nullptr);
|
||||
std::move(proxy));
|
||||
|
||||
test_readpixels_texture(reporter, std::move(sContext));
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
|
||||
return;
|
||||
}
|
||||
sk_sp<GrSurfaceContext> sContext(context->contextPriv().makeWrappedSurfaceContext(
|
||||
std::move(proxy), nullptr));
|
||||
std::move(proxy)));
|
||||
|
||||
const SkImageInfo ii = SkImageInfo::MakeA8(X_SIZE, Y_SIZE);
|
||||
sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii));
|
||||
@ -179,7 +179,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
|
||||
}
|
||||
|
||||
sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
|
||||
std::move(proxy), nullptr);
|
||||
std::move(proxy));
|
||||
|
||||
for (auto rowBytes : kRowBytes) {
|
||||
size_t nonZeroRowBytes = rowBytes ? rowBytes : X_SIZE;
|
||||
|
@ -143,7 +143,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) {
|
||||
false, "RectangleTexture-copy-from");
|
||||
|
||||
sk_sp<GrSurfaceContext> rectContext = context->contextPriv().makeWrappedSurfaceContext(
|
||||
std::move(rectProxy), nullptr);
|
||||
std::move(rectProxy));
|
||||
SkASSERT(rectContext);
|
||||
|
||||
test_read_pixels(reporter, rectContext.get(), refPixels, "RectangleTexture-read");
|
||||
|
@ -78,8 +78,7 @@ void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, GrPixe
|
||||
srcBuffer, 0);
|
||||
REPORTER_ASSERT(reporter, proxy);
|
||||
if (proxy) {
|
||||
sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
|
||||
proxy, nullptr);
|
||||
sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(proxy);
|
||||
|
||||
SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kOpaque_SkAlphaType);
|
||||
|
||||
@ -110,8 +109,7 @@ void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, GrPixe
|
||||
proxy = proxyProvider->createTextureProxy(surfDesc, SkBudgeted::kNo, srcBuffer, 0);
|
||||
REPORTER_ASSERT(reporter, proxy);
|
||||
if (proxy) {
|
||||
sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
|
||||
proxy, nullptr);
|
||||
sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(proxy);
|
||||
|
||||
SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kOpaque_SkAlphaType);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user