Add flush() to SkImage.

This allows a client to ensure all uses of a texture-backed image have
been flushed.

Does nothing if the image isn't texture-backed.

The implementation adds support for triggering a flush if any of a set
of proxies are used rather than just a single proxy.

Change-Id: I358882d9737e63c6e69b924c0767f49b8f8f36ec
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/212405
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Brian Salomon 2019-05-09 09:03:57 -04:00 committed by Skia Commit-Bot
parent dbded16fad
commit d0503a72ac
25 changed files with 303 additions and 121 deletions

View File

@ -726,6 +726,23 @@ public:
*/
bool isValid(GrContext* context) const;
/** Flushes any pending uses of texture-backed images in the GPU backend. If the image is not
texture-backed (including promise texture images) or if the the GrContext does not
have the same context ID as the context backing the image then this is a no-op.
If the image was not used in any non-culled draws recorded on the passed GrContext then
this is a no-op unless the GrFlushInfo contains semaphores, a finish proc, or uses
kSyncCpu_GrFlushFlag. Those are respected even when the image has not been used.
@param context the context on which to flush pending usages of the image.
@param info flush options
@return one of: GrSemaphoresSubmitted::kYes, GrSemaphoresSubmitted::kNo
*/
GrSemaphoresSubmitted flush(GrContext* context, const GrFlushInfo& flushInfo);
/** Version of flush() that uses a default GrFlushInfo. */
void flush(GrContext*);
/** Retrieves the back-end texture. If SkImage has no back-end texture, an invalid
object is returned. Call GrBackendTexture::isValid to determine if the result
is valid.

View File

@ -264,7 +264,7 @@ GrSemaphoresSubmitted GrContext::flush(const GrFlushInfo& info) {
return GrSemaphoresSubmitted::kNo;
}
return this->drawingManager()->flush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess,
return this->drawingManager()->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess,
info);
}

View File

@ -24,12 +24,12 @@
#include "src/image/SkImage_Base.h"
#include "src/image/SkImage_Gpu.h"
#define ASSERT_OWNED_PROXY_PRIV(P) \
#define ASSERT_OWNED_PROXY(P) \
SkASSERT(!(P) || !((P)->peekTexture()) || (P)->peekTexture()->getContext() == fContext)
#define ASSERT_SINGLE_OWNER_PRIV \
#define ASSERT_SINGLE_OWNER \
SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fContext->singleOwner());)
#define RETURN_IF_ABANDONED_PRIV if (fContext->abandoned()) { return; }
#define RETURN_FALSE_IF_ABANDONED_PRIV if (fContext->abandoned()) { return false; }
#define RETURN_VALUE_IF_ABANDONED(value) if (fContext->abandoned()) { return (value); }
#define RETURN_IF_ABANDONED RETURN_VALUE_IF_ABANDONED(void)
sk_sp<const GrCaps> GrContextPriv::refCaps() const {
return fContext->refCaps();
@ -103,7 +103,7 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeDeferredRenderTargetContextWithF
sk_sp<GrTextureContext> GrContextPriv::makeBackendTextureContext(const GrBackendTexture& tex,
GrSurfaceOrigin origin,
sk_sp<SkColorSpace> colorSpace) {
ASSERT_SINGLE_OWNER_PRIV
ASSERT_SINGLE_OWNER
sk_sp<GrSurfaceProxy> proxy = this->proxyProvider()->wrapBackendTexture(
tex, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
@ -122,7 +122,7 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContex
const SkSurfaceProps* props,
ReleaseProc releaseProc,
ReleaseContext releaseCtx) {
ASSERT_SINGLE_OWNER_PRIV
ASSERT_SINGLE_OWNER
SkASSERT(sampleCnt > 0);
sk_sp<GrTextureProxy> proxy(this->proxyProvider()->wrapRenderableBackendTexture(
@ -143,7 +143,7 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendRenderTargetRenderTargetC
const SkSurfaceProps* surfaceProps,
ReleaseProc releaseProc,
ReleaseContext releaseCtx) {
ASSERT_SINGLE_OWNER_PRIV
ASSERT_SINGLE_OWNER
sk_sp<GrSurfaceProxy> proxy = this->proxyProvider()->wrapBackendRenderTarget(
backendRT, origin, releaseProc, releaseCtx);
@ -162,7 +162,7 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureAsRenderTargetRend
int sampleCnt,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props) {
ASSERT_SINGLE_OWNER_PRIV
ASSERT_SINGLE_OWNER
SkASSERT(sampleCnt > 0);
sk_sp<GrSurfaceProxy> proxy(
this->proxyProvider()->wrapBackendTextureAsRenderTarget(tex, origin, sampleCnt));
@ -177,7 +177,7 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureAsRenderTargetRend
sk_sp<GrRenderTargetContext> GrContextPriv::makeVulkanSecondaryCBRenderTargetContext(
const SkImageInfo& imageInfo, const GrVkDrawableInfo& vkInfo, const SkSurfaceProps* props) {
ASSERT_SINGLE_OWNER_PRIV
ASSERT_SINGLE_OWNER
sk_sp<GrSurfaceProxy> proxy(
this->proxyProvider()->wrapVulkanSecondaryCBAsRenderTarget(imageInfo, vkInfo));
if (!proxy) {
@ -189,23 +189,22 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeVulkanSecondaryCBRenderTargetCon
props);
}
void GrContextPriv::flush(GrSurfaceProxy* proxy) {
ASSERT_SINGLE_OWNER_PRIV
RETURN_IF_ABANDONED_PRIV
ASSERT_OWNED_PROXY_PRIV(proxy);
fContext->drawingManager()->flush(proxy, SkSurface::BackendSurfaceAccess::kNoAccess,
GrFlushInfo());
GrSemaphoresSubmitted GrContextPriv::flushSurfaces(GrSurfaceProxy* proxies[], int numProxies,
const GrFlushInfo& info) {
ASSERT_SINGLE_OWNER
RETURN_VALUE_IF_ABANDONED(GrSemaphoresSubmitted::kNo)
GR_CREATE_TRACE_MARKER_CONTEXT("GrContextPriv", "flushSurfaces", fContext);
SkASSERT(numProxies >= 0);
SkASSERT(!numProxies || proxies);
for (int i = 0; i < numProxies; ++i) {
SkASSERT(proxies[i]);
ASSERT_OWNED_PROXY(proxies[i]);
}
return fContext->drawingManager()->flushSurfaces(
proxies, numProxies, SkSurface::BackendSurfaceAccess::kNoAccess, info);
}
void GrContextPriv::flushSurface(GrSurfaceProxy* proxy) {
ASSERT_SINGLE_OWNER_PRIV
RETURN_IF_ABANDONED_PRIV
SkASSERT(proxy);
ASSERT_OWNED_PROXY_PRIV(proxy);
fContext->drawingManager()->flushSurface(proxy,
SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo());
}
void GrContextPriv::flushSurface(GrSurfaceProxy* proxy) { this->flushSurfaces(&proxy, 1, {}); }
static bool valid_premul_color_type(GrColorType ct) {
switch (ct) {
@ -277,11 +276,11 @@ bool GrContextPriv::readSurfacePixels(GrSurfaceContext* src, int left, int top,
int height, GrColorType dstColorType,
SkColorSpace* dstColorSpace, void* buffer, size_t rowBytes,
uint32_t pixelOpsFlags) {
ASSERT_SINGLE_OWNER_PRIV
RETURN_FALSE_IF_ABANDONED_PRIV
ASSERT_SINGLE_OWNER
RETURN_VALUE_IF_ABANDONED(false)
SkASSERT(src);
SkASSERT(buffer);
ASSERT_OWNED_PROXY_PRIV(src->asSurfaceProxy());
ASSERT_OWNED_PROXY(src->asSurfaceProxy());
GR_CREATE_TRACE_MARKER_CONTEXT("GrContextPriv", "readSurfacePixels", fContext);
GrSurfaceProxy* srcProxy = src->asSurfaceProxy();
@ -431,7 +430,7 @@ bool GrContextPriv::readSurfacePixels(GrSurfaceContext* src, int left, int top,
sk_bzero(buffer, tempPixmap.computeByteSize());
}
this->flush(srcProxy);
this->flushSurface(srcProxy);
if (!fContext->fGpu->readPixels(srcSurface, left, top, width, height, allowedColorType, buffer,
rowBytes)) {
@ -461,11 +460,11 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceContext* dst, int left, int top,
int height, GrColorType srcColorType,
SkColorSpace* srcColorSpace, const void* buffer,
size_t rowBytes, uint32_t pixelOpsFlags) {
ASSERT_SINGLE_OWNER_PRIV
RETURN_FALSE_IF_ABANDONED_PRIV
ASSERT_SINGLE_OWNER
RETURN_VALUE_IF_ABANDONED(false)
SkASSERT(dst);
SkASSERT(buffer);
ASSERT_OWNED_PROXY_PRIV(dst->asSurfaceProxy());
ASSERT_OWNED_PROXY(dst->asSurfaceProxy());
GR_CREATE_TRACE_MARKER_CONTEXT("GrContextPriv", "writeSurfacePixels", fContext);
if (GrColorType::kUnknown == srcColorType) {
@ -632,7 +631,7 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceContext* dst, int left, int top,
// giving the drawing manager the chance of skipping the flush (i.e., by passing in the
// destination proxy)
// TODO: should this policy decision just be moved into the drawing manager?
this->flush(caps->preferVRAMUseOverFlushes() ? dstProxy : nullptr);
this->flushSurface(caps->preferVRAMUseOverFlushes() ? dstProxy : nullptr);
return this->getGpu()->writePixels(dstSurface, left, top, width, height, srcColorType, buffer,
rowBytes);

View File

@ -164,22 +164,18 @@ public:
const SkImageInfo&, const GrVkDrawableInfo&, const SkSurfaceProps* = nullptr);
/**
* Call to ensure all drawing to the context has been issued to the
* underlying 3D API.
* The 'proxy' parameter is a hint. If it is supplied the context will guarantee that
* the draws required for that proxy are flushed but it could do more. If no 'proxy' is
* provided then all current work will be flushed.
*/
void flush(GrSurfaceProxy*);
/**
* Finalizes all pending reads and writes to the surface and also performs an MSAA resolve
* if necessary.
* Finalizes all pending reads and writes to the surfaces and also performs an MSAA resolves
* if necessary. The GrSurfaceProxy array is treated as a hint. If it is supplied the context
* will guarantee that the draws required for those proxies are flushed but it could do more.
* If no array is provided then all current work will be flushed.
*
* It is not necessary to call this before reading the render target via Skia/GrContext.
* GrContext will detect when it must perform a resolve before reading pixels back from the
* surface or using it as a texture.
*/
GrSemaphoresSubmitted flushSurfaces(GrSurfaceProxy*[], int numProxies, const GrFlushInfo&);
/** Version of above that flushes for a single proxy and uses a default GrFlushInfo. */
void flushSurface(GrSurfaceProxy*);
/**

View File

@ -194,9 +194,12 @@ void GrDrawingManager::freeGpuResources() {
}
// MDB TODO: make use of the 'proxy' parameter.
GrSemaphoresSubmitted GrDrawingManager::flush(GrSurfaceProxy* proxy,
GrSemaphoresSubmitted GrDrawingManager::flush(GrSurfaceProxy* proxies[],
int numProxies,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info) {
SkASSERT(numProxies >= 0);
SkASSERT(!numProxies || proxies);
GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "flush", fContext);
if (fFlushing || this->wasAbandoned()) {
@ -208,9 +211,14 @@ GrSemaphoresSubmitted GrDrawingManager::flush(GrSurfaceProxy* proxy,
SkDEBUGCODE(this->validate());
if (kNone_GrFlushFlags == info.fFlags && !info.fNumSemaphores && !info.fFinishedProc &&
proxy && !this->isDDLTarget(proxy) && !fDAG.isUsed(proxy)) {
return GrSemaphoresSubmitted::kNo;
if (kNone_GrFlushFlags == info.fFlags && !info.fNumSemaphores && !info.fFinishedProc) {
bool canSkip = numProxies > 0;
for (int i = 0; i < numProxies && canSkip; ++i) {
canSkip = !fDAG.isUsed(proxies[i]) && !this->isDDLTarget(proxies[i]);
}
if (canSkip) {
return GrSemaphoresSubmitted::kNo;
}
}
auto direct = fContext->priv().asDirectContext();
@ -349,7 +357,7 @@ GrSemaphoresSubmitted GrDrawingManager::flush(GrSurfaceProxy* proxy,
opMemoryPool->isEmpty();
#endif
GrSemaphoresSubmitted result = gpu->finishFlush(proxy, access, info);
GrSemaphoresSubmitted result = gpu->finishFlush(proxies, numProxies, access, info);
flushState.deinstantiateProxyTracker()->deinstantiateAllProxies();
@ -432,7 +440,7 @@ bool GrDrawingManager::executeOpLists(int startIndex, int stopIndex, GrOpFlushSt
onFlushOpList = nullptr;
(*numOpListsExecuted)++;
if (*numOpListsExecuted >= kMaxOpListsBeforeFlush) {
flushState->gpu()->finishFlush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess,
flushState->gpu()->finishFlush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess,
GrFlushInfo());
*numOpListsExecuted = 0;
}
@ -450,7 +458,7 @@ bool GrDrawingManager::executeOpLists(int startIndex, int stopIndex, GrOpFlushSt
}
(*numOpListsExecuted)++;
if (*numOpListsExecuted >= kMaxOpListsBeforeFlush) {
flushState->gpu()->finishFlush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess,
flushState->gpu()->finishFlush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess,
GrFlushInfo());
*numOpListsExecuted = 0;
}
@ -469,13 +477,15 @@ bool GrDrawingManager::executeOpLists(int startIndex, int stopIndex, GrOpFlushSt
return anyOpListsExecuted;
}
GrSemaphoresSubmitted GrDrawingManager::flushSurface(
GrSurfaceProxy* proxy, SkSurface::BackendSurfaceAccess access, const GrFlushInfo& info) {
GrSemaphoresSubmitted GrDrawingManager::flushSurfaces(GrSurfaceProxy* proxies[], int n,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info) {
if (this->wasAbandoned()) {
return GrSemaphoresSubmitted::kNo;
}
SkDEBUGCODE(this->validate());
SkASSERT(proxy);
SkASSERT(proxies);
SkASSERT(n > 0);
auto direct = fContext->priv().asDirectContext();
if (!direct) {
@ -488,21 +498,25 @@ GrSemaphoresSubmitted GrDrawingManager::flushSurface(
}
// TODO: It is important to upgrade the drawingmanager to just flushing the
// portion of the DAG required by 'proxy' in order to restore some of the
// portion of the DAG required by 'proxies' in order to restore some of the
// semantics of this method.
GrSemaphoresSubmitted result = this->flush(proxy, access, info);
if (!proxy->isInstantiated()) {
return result;
GrSemaphoresSubmitted result = this->flush(proxies, n, access, info);
for (int i = 0; i < n; ++i) {
if (!proxies[i]->isInstantiated()) {
return result;
}
}
GrSurface* surface = proxy->peekSurface();
if (auto* rt = surface->asRenderTarget()) {
gpu->resolveRenderTarget(rt);
}
if (auto* tex = surface->asTexture()) {
if (tex->texturePriv().mipMapped() == GrMipMapped::kYes &&
tex->texturePriv().mipMapsAreDirty()) {
gpu->regenerateMipMapLevels(tex);
for (int i = 0; i < n; ++i) {
GrSurface* surface = proxies[i]->peekSurface();
if (auto* rt = surface->asRenderTarget()) {
gpu->resolveRenderTarget(rt);
}
if (auto* tex = surface->asTexture()) {
if (tex->texturePriv().mipMapped() == GrMipMapped::kYes &&
tex->texturePriv().mipMapsAreDirty()) {
gpu->regenerateMipMapLevels(tex);
}
}
}
@ -731,7 +745,7 @@ void GrDrawingManager::flushIfNecessary() {
auto resourceCache = direct->priv().getResourceCache();
if (resourceCache && resourceCache->requestsFlush()) {
this->flush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo());
this->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo());
resourceCache->purgeAsNeeded();
}
}

View File

@ -71,9 +71,15 @@ public:
static bool ProgramUnitTest(GrContext* context, int maxStages, int maxLevels);
GrSemaphoresSubmitted flushSurface(GrSurfaceProxy*,
GrSemaphoresSubmitted flushSurfaces(GrSurfaceProxy* proxies[],
int cnt,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info);
GrSemaphoresSubmitted flushSurface(GrSurfaceProxy* proxy,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info);
const GrFlushInfo& info) {
return this->flushSurfaces(&proxy, 1, access, info);
}
void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
@ -147,7 +153,8 @@ private:
// return true if any opLists were actually executed; false otherwise
bool executeOpLists(int startIndex, int stopIndex, GrOpFlushState*, int* numOpListsExecuted);
GrSemaphoresSubmitted flush(GrSurfaceProxy* proxy,
GrSemaphoresSubmitted flush(GrSurfaceProxy* proxies[],
int numProxies,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo&);

View File

@ -412,7 +412,8 @@ int GrGpu::findOrAssignSamplePatternKey(GrRenderTarget* renderTarget) {
return fSamplePatternDictionary.findOrAssignSamplePatternKey(sampleLocations);
}
GrSemaphoresSubmitted GrGpu::finishFlush(GrSurfaceProxy* proxy,
GrSemaphoresSubmitted GrGpu::finishFlush(GrSurfaceProxy* proxies[],
int n,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info) {
this->stats()->incNumFinishFlushes();
@ -436,7 +437,7 @@ GrSemaphoresSubmitted GrGpu::finishFlush(GrSurfaceProxy* proxy,
}
}
}
this->onFinishFlush(proxy, access, info);
this->onFinishFlush(proxies, n, access, info);
return this->caps()->semaphoreSupport() ? GrSemaphoresSubmitted::kYes
: GrSemaphoresSubmitted::kNo;
}

View File

@ -303,8 +303,8 @@ public:
// Provides a hook for post-flush actions (e.g. Vulkan command buffer submits). This will also
// insert any numSemaphore semaphores on the gpu and set the backendSemaphores to match the
// inserted semaphores.
GrSemaphoresSubmitted finishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
const GrFlushInfo&);
GrSemaphoresSubmitted finishFlush(GrSurfaceProxy*[], int n,
SkSurface::BackendSurfaceAccess access, const GrFlushInfo&);
virtual void submit(GrGpuCommandBuffer*) = 0;
@ -547,7 +547,7 @@ private:
const SkIRect& srcRect, const SkIPoint& dstPoint,
bool canDiscardOutsideDstRect) = 0;
virtual void onFinishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
virtual void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access,
const GrFlushInfo&) = 0;
#ifdef SK_ENABLE_DUMP_GPU

View File

@ -4274,7 +4274,7 @@ GrGLAttribArrayState* GrGLGpu::HWVertexArrayState::bindInternalVertexArray(GrGLG
return attribState;
}
void GrGLGpu::onFinishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
void GrGLGpu::onFinishFlush(GrSurfaceProxy*[], int, SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info) {
// If we inserted semaphores during the flush, we need to call GLFlush.
bool insertedSemaphore = info.fNumSemaphores > 0 && this->caps()->semaphoreSupport();

View File

@ -295,7 +295,7 @@ private:
void flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSwizzle&);
void onFinishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access,
const GrFlushInfo&) override;
bool waitSync(GrGLsync, uint64_t timeout, bool flush);

View File

@ -111,7 +111,7 @@ private:
void onResolveRenderTarget(GrRenderTarget* target) override { return; }
void onFinishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info) override {
if (info.fFinishedProc) {
info.fFinishedProc(info.fFinishedContext);

View File

@ -184,7 +184,7 @@ private:
void onResolveRenderTarget(GrRenderTarget* target) override { return; }
void onFinishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info) override {
if (info.fFlags & kSyncCpu_GrFlushFlag) {
this->submitCommandBuffer(kForce_SyncQueue);

View File

@ -1889,21 +1889,25 @@ void GrVkGpu::addImageMemoryBarrier(const GrVkResource* resource,
barrier);
}
void GrVkGpu::onFinishFlush(GrSurfaceProxy* proxy, SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info) {
void GrVkGpu::onFinishFlush(GrSurfaceProxy* proxies[], int n,
SkSurface::BackendSurfaceAccess access, const GrFlushInfo& info) {
SkASSERT(n >= 0);
SkASSERT(!n || proxies);
// Submit the current command buffer to the Queue. Whether we inserted semaphores or not does
// not effect what we do here.
if (proxy && access == SkSurface::BackendSurfaceAccess::kPresent) {
if (n && access == SkSurface::BackendSurfaceAccess::kPresent) {
GrVkImage* image;
SkASSERT(proxy->isInstantiated());
if (GrTexture* tex = proxy->peekTexture()) {
image = static_cast<GrVkTexture*>(tex);
} else {
GrRenderTarget* rt = proxy->peekRenderTarget();
SkASSERT(rt);
image = static_cast<GrVkRenderTarget*>(rt);
for (int i = 0; i < n; ++i) {
SkASSERT(proxies[i]->isInstantiated());
if (GrTexture* tex = proxies[i]->peekTexture()) {
image = static_cast<GrVkTexture*>(tex);
} else {
GrRenderTarget* rt = proxies[i]->peekRenderTarget();
SkASSERT(rt);
image = static_cast<GrVkRenderTarget*>(rt);
}
image->prepareForPresent(this);
}
image->prepareForPresent(this);
}
if (info.fFlags & kSyncCpu_GrFlushFlag) {
this->submitCommandBuffer(kForce_SyncQueue, info.fFinishedProc, info.fFinishedContext);

View File

@ -225,7 +225,7 @@ private:
GrSurfaceOrigin srcOrigin, const SkIRect& srcRect,
const SkIPoint& dstPoint, bool canDiscardOutsideDstRect) override;
void onFinishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
void onFinishFlush(GrSurfaceProxy*[], int, SkSurface::BackendSurfaceAccess access,
const GrFlushInfo&) override;
// Ends and submits the current command buffer to the queue and then creates a new command

View File

@ -160,6 +160,12 @@ bool SkImage::isValid(GrContext* context) const {
return as_IB(this)->onIsValid(context);
}
GrSemaphoresSubmitted SkImage::flush(GrContext* context, const GrFlushInfo& flushInfo) {
return as_IB(this)->onFlush(context, flushInfo);
}
void SkImage::flush(GrContext* context) { as_IB(this)->onFlush(context, {}); }
#else
GrTexture* SkImage::getTexture() const { return nullptr; }
@ -178,6 +184,12 @@ bool SkImage::isValid(GrContext* context) const {
return as_IB(this)->onIsValid(context);
}
GrSemaphoresSubmitted SkImage::flush(GrContext*, const GrFlushInfo&) {
return GrSemaphoresSubmitted::kNo;
}
void SkImage::flush(GrContext*) {}
#endif
///////////////////////////////////////////////////////////////////////////////

View File

@ -48,6 +48,10 @@ public:
virtual GrContext* context() const { return nullptr; }
#if SK_SUPPORT_GPU
virtual GrSemaphoresSubmitted onFlush(GrContext* context, const GrFlushInfo&) {
return GrSemaphoresSubmitted::kNo;
}
// Return the proxy if this image is backed by a single proxy. For YUVA images, this
// will return nullptr unless the YUVA planes have been converted to RGBA in which case
// that single backing proxy will be returned.

View File

@ -64,6 +64,15 @@ SkImage_Gpu::SkImage_Gpu(sk_sp<GrContext> context, uint32_t uniqueID, SkAlphaTyp
SkImage_Gpu::~SkImage_Gpu() {}
GrSemaphoresSubmitted SkImage_Gpu::onFlush(GrContext* context, const GrFlushInfo& info) {
if (!context || !fContext->priv().matches(context) || fContext->abandoned()) {
return GrSemaphoresSubmitted::kNo;
}
GrSurfaceProxy* p[1] = {fProxy.get()};
return context->priv().flushSurfaces(p, 1, info);
}
sk_sp<SkImage> SkImage_Gpu::onMakeColorTypeAndColorSpace(GrRecordingContext* context,
SkColorType targetCT,
sk_sp<SkColorSpace> targetCS) const {
@ -656,7 +665,8 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
GrFlushInfo info;
info.fFlags = kSyncCpu_GrFlushFlag;
drawingManager->flush(proxy.get(), SkSurface::BackendSurfaceAccess::kNoAccess, info);
GrSurfaceProxy* p[1] = {proxy.get()};
drawingManager->flush(p, 1, SkSurface::BackendSurfaceAccess::kNoAccess, info);
return image;
}

View File

@ -26,6 +26,8 @@ public:
sk_sp<SkColorSpace>);
~SkImage_Gpu() override;
GrSemaphoresSubmitted onFlush(GrContext*, const GrFlushInfo&) override;
GrTextureProxy* peekProxy() const override {
return fProxy.get();
}

View File

@ -103,6 +103,21 @@ bool SkImage_GpuYUVA::setupMipmapsForPlanes(GrRecordingContext* context) const {
//////////////////////////////////////////////////////////////////////////////////////////////////
GrSemaphoresSubmitted SkImage_GpuYUVA::onFlush(GrContext* context, const GrFlushInfo& info) {
if (!context || !fContext->priv().matches(context) || fContext->abandoned()) {
return GrSemaphoresSubmitted::kNo;
}
GrSurfaceProxy* proxies[5] = {fProxies[0].get(), fProxies[1].get(),
fProxies[2].get(), fProxies[3].get(), nullptr};
int numProxies = fNumProxies;
if (fRGBProxy) {
proxies[fNumProxies] = fRGBProxy.get();
++numProxies;
}
return context->priv().flushSurfaces(proxies, numProxies, info);
}
GrTextureProxy* SkImage_GpuYUVA::peekProxy() const {
return fRGBProxy.get();
}

View File

@ -29,6 +29,8 @@ public:
GrSurfaceOrigin, sk_sp<SkColorSpace>);
~SkImage_GpuYUVA() override;
GrSemaphoresSubmitted onFlush(GrContext*, const GrFlushInfo&) override;
// This returns the single backing proxy if the YUV channels have already been flattened but
// nullptr if they have not.
GrTextureProxy* peekProxy() const override;
@ -56,6 +58,8 @@ public:
// Returns a ref-ed texture proxy with miplevels
sk_sp<GrTextureProxy> asMippedTextureProxyRef(GrRecordingContext*) const;
bool testingOnly_IsFlattened() const { return SkToBool(fRGBProxy); }
/**
* This is the implementation of SkDeferredDisplayListRecorder::makeYUVAPromiseTexture.
*/

View File

@ -313,7 +313,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages, int ma
GrDrawRandomOp(&random, renderTargetContext.get(), std::move(paint));
}
// Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes)
drawingManager->flush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo());
drawingManager->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo());
const GrBackendFormat format =
context->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
@ -342,7 +342,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages, int ma
auto blockFP = BlockInputFragmentProcessor::Make(std::move(fp));
paint.addColorFragmentProcessor(std::move(blockFP));
GrDrawRandomOp(&random, renderTargetContext.get(), std::move(paint));
drawingManager->flush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess,
drawingManager->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess,
GrFlushInfo());
}
}

View File

@ -43,9 +43,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FlushFinishedProcTest, reporter, ctxInfo) {
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info);
SkCanvas* canvas = surface->getCanvas();
// We flush the surface first just to get rid of any discards/clears that got recorded from
// making the surface.
surface->flush();
canvas->clear(SK_ColorGREEN);
auto image = surface->makeImageSnapshot();
GrFlushInfo flushInfoSyncCpu;
flushInfoSyncCpu.fFlags = kSyncCpu_GrFlushFlag;
ctx->flush(flushInfoSyncCpu);
@ -78,9 +78,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FlushFinishedProcTest, reporter, ctxInfo) {
ctx->flush(flushInfoSyncCpu);
REPORTER_ASSERT(reporter, count == 2);
// Test flushing via the GrContext
canvas->clear(SK_ColorBLUE);
ctx->flush(flushInfoFinishedProc);
// Test flushing via the SkImage
canvas->drawImage(image, 0, 0);
image->flush(ctx, flushInfoFinishedProc);
if (expectAsyncCallback) {
// On Vulkan the command buffer we just submitted may or may not have finished immediately
// so the finish proc may not have been called.
@ -91,10 +91,23 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FlushFinishedProcTest, reporter, ctxInfo) {
ctx->flush(flushInfoSyncCpu);
REPORTER_ASSERT(reporter, count == 3);
// Test flushing via the GrContext
canvas->clear(SK_ColorBLUE);
ctx->flush(flushInfoFinishedProc);
if (expectAsyncCallback) {
// On Vulkan the command buffer we just submitted may or may not have finished immediately
// so the finish proc may not have been called.
REPORTER_ASSERT(reporter, count == 3 || count == 4);
} else {
REPORTER_ASSERT(reporter, count == 4);
}
ctx->flush(flushInfoSyncCpu);
REPORTER_ASSERT(reporter, count == 4);
// There is no work on the surface so flushing may immediately call the finished proc.
ctx->flush(flushInfoFinishedProc);
REPORTER_ASSERT(reporter, count == 3 || count == 4);
busy_wait_for_callback(&count, 4, ctx, reporter);
REPORTER_ASSERT(reporter, count == 4 || count == 5);
busy_wait_for_callback(&count, 5, ctx, reporter);
count = 0;
int count2 = 0;

View File

@ -20,24 +20,23 @@
#include "include/core/SkSerialProcs.h"
#include "include/core/SkStream.h"
#include "include/core/SkSurface.h"
#include "include/gpu/GrContextThreadSafeProxy.h"
#include "include/gpu/GrTexture.h"
#include "src/core/SkAutoPixmapStorage.h"
#include "src/core/SkColorSpacePriv.h"
#include "src/core/SkImagePriv.h"
#include "src/core/SkMakeUnique.h"
#include "src/core/SkUtils.h"
#include "src/image/SkImage_Base.h"
#include "tests/Test.h"
#include "tests/TestUtils.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include "include/gpu/GrContextThreadSafeProxy.h"
#include "include/gpu/GrTexture.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrGpu.h"
#include "src/gpu/GrResourceCache.h"
#include "src/gpu/SkGr.h"
#include "src/image/SkImage_Base.h"
#include "src/image/SkImage_GpuYUVA.h"
#include "tests/Test.h"
#include "tests/TestUtils.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
using namespace sk_gpu_test;
@ -1377,3 +1376,76 @@ DEF_TEST(Image_nonfinite_dst, reporter) {
}
}
DEF_GPUTEST_FOR_ALL_CONTEXTS(ImageFlush, reporter, ctxInfo) {
auto c = ctxInfo.grContext();
auto ii = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
auto s = SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kYes, ii, 1, nullptr);
s->getCanvas()->clear(SK_ColorRED);
auto i0 = s->makeImageSnapshot();
s->getCanvas()->clear(SK_ColorBLUE);
auto i1 = s->makeImageSnapshot();
s->getCanvas()->clear(SK_ColorGREEN);
// Make a YUVA image.
SkAutoPixmapStorage pm;
pm.alloc(SkImageInfo::Make(1, 1, kAlpha_8_SkColorType, kPremul_SkAlphaType));
const SkPixmap pmaps[] = {pm, pm, pm, pm};
SkYUVAIndex indices[] = {{0, SkColorChannel::kA}, {1, SkColorChannel::kA},
{2, SkColorChannel::kA}, {3, SkColorChannel::kA}};
auto i2 = SkImage::MakeFromYUVAPixmaps(c, kJPEG_SkYUVColorSpace, pmaps, indices,
SkISize::Make(1, 1), kTopLeft_GrSurfaceOrigin, false);
// Flush all the setup work we did above and then make little lambda that reports the flush
// count delta since the last time it was called.
c->flush();
auto numFlushes = [c, flushCnt = c->priv().getGpu()->stats()->numFinishFlushes()]() mutable {
int curr = c->priv().getGpu()->stats()->numFinishFlushes();
int n = curr - flushCnt;
flushCnt = curr;
return n;
};
// Images aren't used therefore flush is ignored.
i0->flush(c);
i1->flush(c);
i2->flush(c);
REPORTER_ASSERT(reporter, numFlushes() == 0);
// Syncing forces the flush to happen even if the images aren't used.
GrFlushInfo syncInfo;
syncInfo.fFlags = kSyncCpu_GrFlushFlag;
i0->flush(c, syncInfo);
REPORTER_ASSERT(reporter, numFlushes() == 1);
i1->flush(c, syncInfo);
REPORTER_ASSERT(reporter, numFlushes() == 1);
i2->flush(c, syncInfo);
REPORTER_ASSERT(reporter, numFlushes() == 1);
// Use image 1
s->getCanvas()->drawImage(i1, 0, 0);
// Flushing image 0 should do nothing.
i0->flush(c);
REPORTER_ASSERT(reporter, numFlushes() == 0);
// Flushing image 1 should flush.
i1->flush(c);
REPORTER_ASSERT(reporter, numFlushes() == 1);
// Flushing image 2 should do nothing.
i2->flush(c);
REPORTER_ASSERT(reporter, numFlushes() == 0);
// Use image 2
s->getCanvas()->drawImage(i2, 0, 0);
// Flushing image 0 should do nothing.
i0->flush(c);
REPORTER_ASSERT(reporter, numFlushes() == 0);
// Flushing image 1 do nothing.
i1->flush(c);
REPORTER_ASSERT(reporter, numFlushes() == 0);
// Flushing image 2 should flush.
i2->flush(c);
REPORTER_ASSERT(reporter, numFlushes() == 1);
// Since we just did a simple image draw it should not have been flattened.
REPORTER_ASSERT(reporter,
!static_cast<SkImage_GpuYUVA*>(as_IB(i2.get()))->testingOnly_IsFlattened());
}

View File

@ -104,11 +104,13 @@ void draw_child(skiatest::Reporter* reporter,
check_pixels(reporter, bitmap);
}
enum class FlushType { kSurface, kImage, kContext };
void surface_semaphore_test(skiatest::Reporter* reporter,
const sk_gpu_test::ContextInfo& mainInfo,
const sk_gpu_test::ContextInfo& childInfo1,
const sk_gpu_test::ContextInfo& childInfo2,
bool flushContext) {
FlushType flushType) {
GrContext* mainCtx = mainInfo.grContext();
if (!mainCtx->priv().caps()->semaphoreSupport()) {
return;
@ -121,7 +123,11 @@ void surface_semaphore_test(skiatest::Reporter* reporter,
ii, 0, kTopLeft_GrSurfaceOrigin,
nullptr));
SkCanvas* mainCanvas = mainSurface->getCanvas();
mainCanvas->clear(SK_ColorBLUE);
auto blueSurface = mainSurface->makeSurface(ii);
blueSurface->getCanvas()->clear(SK_ColorBLUE);
auto blueImage = blueSurface->makeImageSnapshot();
blueSurface.reset();
mainCanvas->drawImage(blueImage, 0, 0);
SkAutoTArray<GrBackendSemaphore> semaphores(2);
#ifdef SK_VULKAN
@ -146,10 +152,16 @@ void surface_semaphore_test(skiatest::Reporter* reporter,
GrFlushInfo info;
info.fNumSemaphores = 2;
info.fSignalSemaphores = semaphores.get();
if (flushContext) {
mainCtx->flush(info);
} else {
mainSurface->flush(SkSurface::BackendSurfaceAccess::kNoAccess, info);
switch (flushType) {
case FlushType::kSurface:
mainSurface->flush(SkSurface::BackendSurfaceAccess::kNoAccess, info);
break;
case FlushType::kImage:
blueImage->flush(mainCtx, info);
break;
case FlushType::kContext:
mainCtx->flush(info);
break;
}
sk_sp<SkImage> mainImage = mainSurface->makeImageSnapshot();
@ -179,7 +191,7 @@ DEF_GPUTEST(SurfaceSemaphores, reporter, options) {
#endif
for (int typeInt = 0; typeInt < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++typeInt) {
for (auto flushContext : { false, true }) {
for (auto flushType : {FlushType::kSurface, FlushType::kImage, FlushType::kContext}) {
sk_gpu_test::GrContextFactory::ContextType contextType =
(sk_gpu_test::GrContextFactory::ContextType) typeInt;
// Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on
@ -207,7 +219,7 @@ DEF_GPUTEST(SurfaceSemaphores, reporter, options) {
continue;
}
surface_semaphore_test(reporter, ctxInfo, child1, child2, flushContext);
surface_semaphore_test(reporter, ctxInfo, child1, child2, flushType);
}
}
}

View File

@ -275,7 +275,7 @@ void basic_transfer_from_test(skiatest::Reporter* reporter, const sk_gpu_test::C
GrFlushInfo flushInfo;
flushInfo.fFlags = kSyncCpu_GrFlushFlag;
if (context->priv().caps()->mapBufferFlags() & GrCaps::kAsyncRead_MapFlag) {
gpu->finishFlush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
gpu->finishFlush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
}
const auto* map = reinterpret_cast<const GrColor*>(buffer->map());
@ -304,7 +304,7 @@ void basic_transfer_from_test(skiatest::Reporter* reporter, const sk_gpu_test::C
++expectedTransferCnt;
if (context->priv().caps()->mapBufferFlags() & GrCaps::kAsyncRead_MapFlag) {
gpu->finishFlush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
gpu->finishFlush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
}
map = reinterpret_cast<const GrColor*>(buffer->map());