From f440cecbfdf1910104f36aedd0e963da2ae8b6a8 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Fri, 19 Jan 2018 11:51:20 -0500 Subject: Move more internal methods from GrContext to GrContextPriv TBR=bsalomon@google.com Change-Id: Ia8cf0e0d30451c69bc7a08215aafa6abe6e0ddbe Reviewed-on: https://skia-review.googlesource.com/97080 Commit-Queue: Robert Phillips Reviewed-by: Greg Daniel --- bench/GrResourceCacheBench.cpp | 4 +- bench/SKPBench.cpp | 3 +- gm/imagefromyuvtextures.cpp | 5 +- gm/rectangletexture.cpp | 3 +- include/gpu/GrContext.h | 4 - src/atlastext/SkAtlasTextTarget.cpp | 2 +- src/atlastext/SkInternalAtlasTextContext.cpp | 12 ++- src/gpu/GrContextPriv.h | 6 ++ src/gpu/GrDrawingManager.cpp | 17 ++-- src/gpu/GrRenderTargetOpList.cpp | 5 +- src/gpu/GrRenderTargetOpList.h | 2 +- src/gpu/GrTextureAdjuster.cpp | 4 +- src/gpu/GrTextureMaker.cpp | 8 +- src/gpu/text/GrAtlasTextBlob.cpp | 33 ++++---- src/gpu/text/GrAtlasTextBlob.h | 8 +- src/gpu/text/GrAtlasTextContext.cpp | 64 ++++++++------ src/gpu/text/GrTextUtils.cpp | 4 +- src/gpu/text/GrTextUtils.h | 20 ++--- src/image/SkImage_Gpu.cpp | 6 +- tests/EGLImageTest.cpp | 6 +- tests/GLProgramsTest.cpp | 2 +- tests/GrMipMappedTest.cpp | 35 ++++---- tests/GrPorterDuffTest.cpp | 9 +- tests/GrSurfaceTest.cpp | 5 +- tests/ImageTest.cpp | 5 +- tests/PrimitiveProcessorTest.cpp | 15 ++-- tests/ResourceAllocatorTest.cpp | 9 +- tests/ResourceCacheTest.cpp | 122 +++++++++++++++------------ tests/SRGBMipMapTest.cpp | 2 +- tests/SurfaceSemaphoreTest.cpp | 7 +- tests/SurfaceTest.cpp | 33 +++++--- tests/TransferPixelsTest.cpp | 17 ++-- tests/VkHeapTests.cpp | 7 +- tests/VkWrapTests.cpp | 7 +- tests/WritePixelsTest.cpp | 7 +- tools/gpu/GrTest.cpp | 2 +- 36 files changed, 287 insertions(+), 213 deletions(-) diff --git a/bench/GrResourceCacheBench.cpp b/bench/GrResourceCacheBench.cpp index c48aed5e0b..a530e628e8 100644 --- a/bench/GrResourceCacheBench.cpp +++ b/bench/GrResourceCacheBench.cpp @@ -83,7 +83,7 @@ protected: cache->purgeAllUnlocked(); SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes()); - GrGpu* gpu = context->getGpu(); + GrGpu* gpu = context->contextPriv().getGpu(); for (int i = 0; i < loops; ++i) { populate_cache(gpu, CACHE_SIZE_COUNT, fKeyData32Count); @@ -129,7 +129,7 @@ protected: cache->purgeAllUnlocked(); SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes()); - GrGpu* gpu = fContext->getGpu(); + GrGpu* gpu = fContext->contextPriv().getGpu(); populate_cache(gpu, CACHE_SIZE_COUNT, fKeyData32Count); } diff --git a/bench/SKPBench.cpp b/bench/SKPBench.cpp index 013ec53cda..4fbb1bba29 100644 --- a/bench/SKPBench.cpp +++ b/bench/SKPBench.cpp @@ -12,6 +12,7 @@ #if SK_SUPPORT_GPU #include "GrContext.h" +#include "GrContextPriv.h" #endif // These CPU tile sizes are not good per se, but they are similar to what Chrome uses. @@ -189,7 +190,7 @@ void SKPBench::getGpuStats(SkCanvas* canvas, SkTArray* keys, SkTArray< context->flush(); context->freeGpuResources(); context->resetContext(); - context->getGpu()->resetShaderCacheForTesting(); + context->contextPriv().getGpu()->resetShaderCacheForTesting(); draw_pic_for_stats(canvas, context, fPic.get(), keys, values, "first_frame"); // draw second frame diff --git a/gm/imagefromyuvtextures.cpp b/gm/imagefromyuvtextures.cpp index 6334611666..a14674db5a 100644 --- a/gm/imagefromyuvtextures.cpp +++ b/gm/imagefromyuvtextures.cpp @@ -12,6 +12,7 @@ #if SK_SUPPORT_GPU #include "GrContext.h" +#include "GrContextPriv.h" #include "GrGpu.h" #include "GrTest.h" #include "SkBitmap.h" @@ -94,7 +95,7 @@ protected: } void createYUVTextures(GrContext* context, GrBackendTexture yuvTextures[3]) { - GrGpu* gpu = context->getGpu(); + GrGpu* gpu = context->contextPriv().getGpu(); if (!gpu) { return; } @@ -112,7 +113,7 @@ protected: void deleteYUVTextures(GrContext* context, GrBackendTexture yuvTextures[3]) { - GrGpu* gpu = context->getGpu(); + GrGpu* gpu = context->contextPriv().getGpu(); if (!gpu) { return; } diff --git a/gm/rectangletexture.cpp b/gm/rectangletexture.cpp index 2fb64be90e..1ce915bf52 100644 --- a/gm/rectangletexture.cpp +++ b/gm/rectangletexture.cpp @@ -13,6 +13,7 @@ #include "GrBackendSurface.h" #include "GrContext.h" +#include "GrContextPriv.h" #include "GrGpu.h" #include "GrTest.h" #include "gl/GrGLContext.h" @@ -61,7 +62,7 @@ protected: if (!context) { return nullptr; } - GrGpu* gpu = context->getGpu(); + GrGpu* gpu = context->contextPriv().getGpu(); if (!gpu) { return nullptr; } diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 6b5d7500fa..dd6c6f8f39 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -300,10 +300,6 @@ public: /////////////////////////////////////////////////////////////////////////// // Functions intended for internal use only. - GrGpu* getGpu() { return fGpu.get(); } - const GrGpu* getGpu() const { return fGpu.get(); } - GrAtlasGlyphCache* getAtlasGlyphCache() { return fAtlasGlyphCache; } - GrTextBlobCache* getTextBlobCache() { return fTextBlobCache.get(); } bool abandoned() const; /** Reset GPU stats */ diff --git a/src/atlastext/SkAtlasTextTarget.cpp b/src/atlastext/SkAtlasTextTarget.cpp index 0a318e0c8e..d80c7a45d7 100644 --- a/src/atlastext/SkAtlasTextTarget.cpp +++ b/src/atlastext/SkAtlasTextTarget.cpp @@ -183,7 +183,7 @@ void GrAtlasTextOp::executeForTextTarget(SkAtlasTextTarget* target) { FlushInfo flushInfo; SkAutoGlyphCache glyphCache; auto& context = target->context()->internal(); - auto* atlasGlyphCache = context.grContext()->getAtlasGlyphCache(); + auto* atlasGlyphCache = context.grContext()->contextPriv().getAtlasGlyphCache(); for (int i = 0; i < fGeoCount; ++i) { GrAtlasTextBlob::VertexRegenerator regenerator( fGeoData[i].fBlob, fGeoData[i].fRun, fGeoData[i].fSubRun, fGeoData[i].fViewMatrix, diff --git a/src/atlastext/SkInternalAtlasTextContext.cpp b/src/atlastext/SkInternalAtlasTextContext.cpp index fba0cbcdbe..58b8788943 100644 --- a/src/atlastext/SkInternalAtlasTextContext.cpp +++ b/src/atlastext/SkInternalAtlasTextContext.cpp @@ -7,6 +7,7 @@ #include "SkInternalAtlasTextContext.h" #include "GrContext.h" +#include "GrContextPriv.h" #include "SkAtlasTextContext.h" #include "SkAtlasTextRenderer.h" #include "text/GrAtlasGlyphCache.h" @@ -36,17 +37,20 @@ SkInternalAtlasTextContext::SkInternalAtlasTextContext(sk_spgetAtlasGlyphCache()->getAtlasPageCount(kA8_GrMaskFormat)); +#ifdef SK_DEBUG + auto atlasGlyphCache = fGrContext->contextPriv().getAtlasGlyphCache(); + SkASSERT(1 == atlasGlyphCache->getAtlasPageCount(kA8_GrMaskFormat)); +#endif fRenderer->deleteTexture(fDistanceFieldAtlas.fTextureHandle); } } GrAtlasGlyphCache* SkInternalAtlasTextContext::atlasGlyphCache() { - return fGrContext->getAtlasGlyphCache(); + return fGrContext->contextPriv().getAtlasGlyphCache(); } GrTextBlobCache* SkInternalAtlasTextContext::textBlobCache() { - return fGrContext->getTextBlobCache(); + return fGrContext->contextPriv().getTextBlobCache(); } GrDeferredUploadToken SkInternalAtlasTextContext::addInlineUpload( @@ -80,7 +84,7 @@ void SkInternalAtlasTextContext::recordDraw(const void* srcVertexData, int glyph } void SkInternalAtlasTextContext::flush() { - auto* atlasGlyphCache = fGrContext->getAtlasGlyphCache(); + auto* atlasGlyphCache = fGrContext->contextPriv().getAtlasGlyphCache(); if (!fDistanceFieldAtlas.fProxy) { SkASSERT(1 == atlasGlyphCache->getAtlasPageCount(kA8_GrMaskFormat)); fDistanceFieldAtlas.fProxy = atlasGlyphCache->getProxies(kA8_GrMaskFormat)->get(); diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h index bbf67a569a..2ce3947658 100644 --- a/src/gpu/GrContextPriv.h +++ b/src/gpu/GrContextPriv.h @@ -175,6 +175,12 @@ public: GrResourceCache* getResourceCache() { return fContext->fResourceCache; } + GrGpu* getGpu() { return fContext->fGpu.get(); } + const GrGpu* getGpu() const { return fContext->fGpu.get(); } + + GrAtlasGlyphCache* getAtlasGlyphCache() { return fContext->fAtlasGlyphCache; } + GrTextBlobCache* getTextBlobCache() { return fContext->fTextBlobCache.get(); } + private: explicit GrContextPriv(GrContext* context) : fContext(context) {} GrContextPriv(const GrContextPriv&); // unimpl diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp index 3f6c77379a..302da06c07 100644 --- a/src/gpu/GrDrawingManager.cpp +++ b/src/gpu/GrDrawingManager.cpp @@ -121,8 +121,9 @@ GrSemaphoresSubmitted GrDrawingManager::internalFlush(GrSurfaceProxy*, SkASSERT(result); #endif - GrOpFlushState flushState(fContext->getGpu(), - fContext->contextPriv().resourceProvider(), + GrGpu* gpu = fContext->contextPriv().getGpu(); + + GrOpFlushState flushState(gpu, fContext->contextPriv().resourceProvider(), &fTokenTracker); GrOnFlushResourceProvider onFlushProvider(this); @@ -193,8 +194,7 @@ GrSemaphoresSubmitted GrDrawingManager::internalFlush(GrSurfaceProxy*, fOpLists.reset(); - GrSemaphoresSubmitted result = fContext->getGpu()->finishFlush(numSemaphores, - backendSemaphores); + GrSemaphoresSubmitted result = gpu->finishFlush(numSemaphores, backendSemaphores); // We always have to notify the cache when it requested a flush so it can reset its state. if (flushed || type == GrResourceCache::FlushType::kCacheRequested) { @@ -299,10 +299,11 @@ GrSemaphoresSubmitted GrDrawingManager::prepareSurfaceForExternalIO( return result; } + GrGpu* gpu = fContext->contextPriv().getGpu(); GrSurface* surface = proxy->priv().peekSurface(); - if (fContext->getGpu() && surface->asRenderTarget()) { - fContext->getGpu()->resolveRenderTarget(surface->asRenderTarget(), proxy->origin()); + if (gpu && surface->asRenderTarget()) { + gpu->resolveRenderTarget(surface->asRenderTarget(), proxy->origin()); } return result; } @@ -322,8 +323,10 @@ sk_sp GrDrawingManager::newRTOpList(GrRenderTargetProxy* r fOpLists.back()->makeClosed(*fContext->caps()); } + auto resourceProvider = fContext->contextPriv().resourceProvider(); + sk_sp opList(new GrRenderTargetOpList(rtp, - fContext->getGpu(), + resourceProvider, fContext->getAuditTrail())); SkASSERT(rtp->getLastOpList() == opList.get()); diff --git a/src/gpu/GrRenderTargetOpList.cpp b/src/gpu/GrRenderTargetOpList.cpp index 0f62bc6a35..0c806bfe2c 100644 --- a/src/gpu/GrRenderTargetOpList.cpp +++ b/src/gpu/GrRenderTargetOpList.cpp @@ -24,9 +24,10 @@ static const int kMaxOpLookback = 10; static const int kMaxOpLookahead = 10; -GrRenderTargetOpList::GrRenderTargetOpList(GrRenderTargetProxy* proxy, GrGpu* gpu, +GrRenderTargetOpList::GrRenderTargetOpList(GrRenderTargetProxy* proxy, + GrResourceProvider* resourceProvider, GrAuditTrail* auditTrail) - : INHERITED(gpu->getContext()->contextPriv().resourceProvider(), proxy, auditTrail) + : INHERITED(resourceProvider, proxy, auditTrail) , fLastClipStackGenID(SK_InvalidUniqueID) SkDEBUGCODE(, fNumClips(0)) { } diff --git a/src/gpu/GrRenderTargetOpList.h b/src/gpu/GrRenderTargetOpList.h index 5803d38f37..6b736338f7 100644 --- a/src/gpu/GrRenderTargetOpList.h +++ b/src/gpu/GrRenderTargetOpList.h @@ -32,7 +32,7 @@ private: using DstProxy = GrXferProcessor::DstProxy; public: - GrRenderTargetOpList(GrRenderTargetProxy*, GrGpu*, GrAuditTrail*); + GrRenderTargetOpList(GrRenderTargetProxy*, GrResourceProvider*, GrAuditTrail*); ~GrRenderTargetOpList() override; diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp index b307607c7e..fbfffb3bb8 100644 --- a/src/gpu/GrTextureAdjuster.cpp +++ b/src/gpu/GrTextureAdjuster.cpp @@ -75,8 +75,8 @@ sk_sp GrTextureAdjuster::refTextureProxySafeForParams(const GrSa return nullptr; } - if (!fContext->getGpu()->isACopyNeededForTextureParams(proxy.get(), params, ©Params, - scaleAdjust)) { + GrGpu* gpu = fContext->contextPriv().getGpu(); + if (!gpu->isACopyNeededForTextureParams(proxy.get(), params, ©Params, scaleAdjust)) { return proxy; } diff --git a/src/gpu/GrTextureMaker.cpp b/src/gpu/GrTextureMaker.cpp index 1fc5f7a0ee..5043675a0d 100644 --- a/src/gpu/GrTextureMaker.cpp +++ b/src/gpu/GrTextureMaker.cpp @@ -28,16 +28,16 @@ sk_sp GrTextureMaker::refTextureProxyForParams(const GrSamplerSt *texColorSpace = this->getColorSpace(dstColorSpace); } + GrGpu* gpu = fContext->contextPriv().getGpu(); sk_sp original(this->refOriginalTextureProxy(willBeMipped, dstColorSpace, AllowedTexGenType::kCheap)); if (original) { - if (!fContext->getGpu()->isACopyNeededForTextureParams(original.get(), params, ©Params, - scaleAdjust)) { + if (!gpu->isACopyNeededForTextureParams(original.get(), params, ©Params, scaleAdjust)) { return original; } } else { - if (!fContext->getGpu()->isACopyNeededForTextureParams(this->width(), this->height(), - params, ©Params, scaleAdjust)) { + if (!gpu->isACopyNeededForTextureParams(this->width(), this->height(), + params, ©Params, scaleAdjust)) { return this->refOriginalTextureProxy(willBeMipped, dstColorSpace, AllowedTexGenType::kAny); } diff --git a/src/gpu/text/GrAtlasTextBlob.cpp b/src/gpu/text/GrAtlasTextBlob.cpp index df848db6f7..8c3cefe33f 100644 --- a/src/gpu/text/GrAtlasTextBlob.cpp +++ b/src/gpu/text/GrAtlasTextBlob.cpp @@ -348,7 +348,7 @@ static void calculate_translation(bool applyVM, } } -void GrAtlasTextBlob::flushBigGlyphs(GrContext* context, GrTextUtils::Target* target, +void GrAtlasTextBlob::flushBigGlyphs(GrTextUtils::Target* target, const GrClip& clip, const SkPaint& paint, const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipBounds) { @@ -367,11 +367,11 @@ void GrAtlasTextBlob::flushBigGlyphs(GrContext* context, GrTextUtils::Target* ta } } -void GrAtlasTextBlob::flushBigRun(GrContext* context, GrTextUtils::Target* target, - const SkSurfaceProps& props, const SkTextBlobRunIterator& it, - const GrClip& clip, const GrTextUtils::Paint& paint, - SkDrawFilter* drawFilter, const SkMatrix& viewMatrix, - const SkIRect& clipBounds, SkScalar x, SkScalar y) { +void GrAtlasTextBlob::flushBigRun(GrTextUtils::Target* target, + const SkSurfaceProps& props, const SkTextBlobRunIterator& it, + const GrClip& clip, const GrTextUtils::Paint& paint, + SkDrawFilter* drawFilter, const SkMatrix& viewMatrix, + const SkIRect& clipBounds, SkScalar x, SkScalar y) { size_t textLen = it.glyphCount() * sizeof(uint16_t); const SkPoint& offset = it.offset(); @@ -382,24 +382,24 @@ void GrAtlasTextBlob::flushBigRun(GrContext* context, GrTextUtils::Target* targe switch (it.positioning()) { case SkTextBlob::kDefault_Positioning: - GrTextUtils::DrawBigText(context, target, clip, runPaint, viewMatrix, + GrTextUtils::DrawBigText(target, clip, runPaint, viewMatrix, (const char*)it.glyphs(), textLen, x + offset.x(), y + offset.y(), clipBounds); break; case SkTextBlob::kHorizontal_Positioning: - GrTextUtils::DrawBigPosText(context, target, props, clip, runPaint, viewMatrix, + GrTextUtils::DrawBigPosText(target, props, clip, runPaint, viewMatrix, (const char*)it.glyphs(), textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()), clipBounds); break; case SkTextBlob::kFull_Positioning: - GrTextUtils::DrawBigPosText(context, target, props, clip, runPaint, viewMatrix, + GrTextUtils::DrawBigPosText(target, props, clip, runPaint, viewMatrix, (const char*)it.glyphs(), textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds); break; } } -void GrAtlasTextBlob::flushCached(GrContext* context, GrTextUtils::Target* target, +void GrAtlasTextBlob::flushCached(GrAtlasGlyphCache* atlasGlyphCache, GrTextUtils::Target* target, const SkTextBlob* blob, const SkSurfaceProps& props, const GrDistanceFieldAdjustTable* distanceAdjustTable, const GrTextUtils::Paint& paint, SkDrawFilter* drawFilter, @@ -410,19 +410,20 @@ void GrAtlasTextBlob::flushCached(GrContext* context, GrTextUtils::Target* targe SkTextBlobRunIterator it(blob); for (int run = 0; !it.done(); it.next(), run++) { if (fRuns[run].fTooBigForAtlas) { - this->flushBigRun(context, target, props, it, clip, paint, drawFilter, viewMatrix, + this->flushBigRun(target, props, it, clip, paint, drawFilter, viewMatrix, clipBounds, x, y); continue; } this->flushRun(target, clip, run, viewMatrix, x, y, paint, props, distanceAdjustTable, - context->getAtlasGlyphCache()); + atlasGlyphCache); } // Now flush big glyphs - this->flushBigGlyphs(context, target, clip, paint, viewMatrix, x, y, clipBounds); + this->flushBigGlyphs(target, clip, paint, viewMatrix, x, y, clipBounds); } -void GrAtlasTextBlob::flushThrowaway(GrContext* context, GrTextUtils::Target* target, +void GrAtlasTextBlob::flushThrowaway(GrAtlasGlyphCache* atlasGlyphCache, + GrTextUtils::Target* target, const SkSurfaceProps& props, const GrDistanceFieldAdjustTable* distanceAdjustTable, const GrTextUtils::Paint& paint, const GrClip& clip, @@ -430,11 +431,11 @@ void GrAtlasTextBlob::flushThrowaway(GrContext* context, GrTextUtils::Target* ta SkScalar x, SkScalar y) { for (int run = 0; run < fRunCount; run++) { this->flushRun(target, clip, run, viewMatrix, x, y, paint, props, distanceAdjustTable, - context->getAtlasGlyphCache()); + atlasGlyphCache); } // Now flush big glyphs - this->flushBigGlyphs(context, target, clip, paint, viewMatrix, x, y, clipBounds); + this->flushBigGlyphs(target, clip, paint, viewMatrix, x, y, clipBounds); } std::unique_ptr GrAtlasTextBlob::test_makeOp( diff --git a/src/gpu/text/GrAtlasTextBlob.h b/src/gpu/text/GrAtlasTextBlob.h index b93632fcfe..2b4047bdd6 100644 --- a/src/gpu/text/GrAtlasTextBlob.h +++ b/src/gpu/text/GrAtlasTextBlob.h @@ -195,14 +195,14 @@ public: const SkMatrix& viewMatrix, SkScalar x, SkScalar y); // flush a GrAtlasTextBlob associated with a SkTextBlob - void flushCached(GrContext* context, GrTextUtils::Target*, const SkTextBlob* blob, + void flushCached(GrAtlasGlyphCache*, GrTextUtils::Target*, const SkTextBlob* blob, const SkSurfaceProps& props, const GrDistanceFieldAdjustTable* distanceAdjustTable, const GrTextUtils::Paint&, SkDrawFilter* drawFilter, const GrClip& clip, const SkMatrix& viewMatrix, const SkIRect& clipBounds, SkScalar x, SkScalar y); // flush a throwaway GrAtlasTextBlob *not* associated with an SkTextBlob - void flushThrowaway(GrContext* context, GrTextUtils::Target*, const SkSurfaceProps& props, + void flushThrowaway(GrAtlasGlyphCache*, GrTextUtils::Target*, const SkSurfaceProps& props, const GrDistanceFieldAdjustTable* distanceAdjustTable, const GrTextUtils::Paint& paint, const GrClip& clip, const SkMatrix& viewMatrix, const SkIRect& clipBounds, SkScalar x, @@ -295,11 +295,11 @@ private: const GrDistanceFieldAdjustTable* distanceAdjustTable, GrAtlasGlyphCache* cache); - void flushBigGlyphs(GrContext* context, GrTextUtils::Target*, const GrClip& clip, + void flushBigGlyphs(GrTextUtils::Target*, const GrClip& clip, const SkPaint& paint, const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipBounds); - void flushBigRun(GrContext* context, GrTextUtils::Target*, const SkSurfaceProps& props, + void flushBigRun(GrTextUtils::Target*, const SkSurfaceProps& props, const SkTextBlobRunIterator& it, const GrClip& clip, const GrTextUtils::Paint& paint, SkDrawFilter* drawFilter, const SkMatrix& viewMatrix, const SkIRect& clipBounds, SkScalar x, diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp index bdbc600cc1..9fef8e39a3 100644 --- a/src/gpu/text/GrAtlasTextContext.cpp +++ b/src/gpu/text/GrAtlasTextContext.cpp @@ -6,6 +6,7 @@ */ #include "GrAtlasTextContext.h" #include "GrContext.h" +#include "GrContextPriv.h" #include "GrTextBlobCache.h" #include "SkDistanceFieldGen.h" #include "SkDraw.h" @@ -121,7 +122,9 @@ void GrAtlasTextContext::drawTextBlob(GrContext* context, GrTextUtils::Target* t drawFilter); uint32_t scalerContextFlags = ComputeScalerContextFlags(target->colorSpaceInfo()); - GrTextBlobCache* cache = context->getTextBlobCache(); + auto atlasGlyphCache = context->contextPriv().getAtlasGlyphCache(); + GrTextBlobCache* textBlobCache = context->contextPriv().getTextBlobCache(); + if (canCache) { bool hasLCD = HasLCD(blob); @@ -141,7 +144,7 @@ void GrAtlasTextContext::drawTextBlob(GrContext* context, GrTextUtils::Target* t key.fHasBlur = SkToBool(mf); key.fCanonicalColor = canonicalColor; key.fScalerContextFlags = scalerContextFlags; - cacheBlob = cache->find(key); + cacheBlob = textBlobCache->find(key); } GrTextUtils::Paint paint(&skPaint, &target->colorSpaceInfo()); @@ -150,21 +153,21 @@ void GrAtlasTextContext::drawTextBlob(GrContext* context, GrTextUtils::Target* t // We have to remake the blob because changes may invalidate our masks. // TODO we could probably get away reuse most of the time if the pointer is unique, // but we'd have to clear the subrun information - cache->remove(cacheBlob.get()); - cacheBlob = cache->makeCachedBlob(blob, key, blurRec, skPaint); - this->regenerateTextBlob(cacheBlob.get(), context->getAtlasGlyphCache(), + textBlobCache->remove(cacheBlob.get()); + cacheBlob = textBlobCache->makeCachedBlob(blob, key, blurRec, skPaint); + this->regenerateTextBlob(cacheBlob.get(), atlasGlyphCache, *context->caps()->shaderCaps(), paint, scalerContextFlags, viewMatrix, props, blob, x, y, drawFilter); } else { - cache->makeMRU(cacheBlob.get()); + textBlobCache->makeMRU(cacheBlob.get()); if (CACHE_SANITY_CHECK) { int glyphCount = 0; int runCount = 0; GrTextBlobCache::BlobGlyphCount(&glyphCount, &runCount, blob); - sk_sp sanityBlob(cache->makeBlob(glyphCount, runCount)); + sk_sp sanityBlob(textBlobCache->makeBlob(glyphCount, runCount)); sanityBlob->setupKey(key, blurRec, skPaint); - this->regenerateTextBlob(sanityBlob.get(), context->getAtlasGlyphCache(), + this->regenerateTextBlob(sanityBlob.get(), atlasGlyphCache, *context->caps()->shaderCaps(), paint, scalerContextFlags, viewMatrix, props, blob, x, y, drawFilter); GrAtlasTextBlob::AssertEqual(*sanityBlob, *cacheBlob); @@ -172,16 +175,16 @@ void GrAtlasTextContext::drawTextBlob(GrContext* context, GrTextUtils::Target* t } } else { if (canCache) { - cacheBlob = cache->makeCachedBlob(blob, key, blurRec, skPaint); + cacheBlob = textBlobCache->makeCachedBlob(blob, key, blurRec, skPaint); } else { - cacheBlob = cache->makeBlob(blob); + cacheBlob = textBlobCache->makeBlob(blob); } - this->regenerateTextBlob(cacheBlob.get(), context->getAtlasGlyphCache(), + this->regenerateTextBlob(cacheBlob.get(), atlasGlyphCache, *context->caps()->shaderCaps(), paint, scalerContextFlags, viewMatrix, props, blob, x, y, drawFilter); } - cacheBlob->flushCached(context, target, blob, props, fDistanceAdjustTable.get(), paint, + cacheBlob->flushCached(atlasGlyphCache, target, blob, props, fDistanceAdjustTable.get(), paint, drawFilter, clip, viewMatrix, clipBounds, x, y); } @@ -318,23 +321,27 @@ void GrAtlasTextContext::drawText(GrContext* context, GrTextUtils::Target* targe if (context->abandoned()) { return; } + + auto atlasGlyphCache = context->contextPriv().getAtlasGlyphCache(); + auto textBlobCache = context->contextPriv().getTextBlobCache(); + GrTextUtils::Paint paint(&skPaint, &target->colorSpaceInfo()); - if (this->canDraw(context->getAtlasGlyphCache(), skPaint, viewMatrix, props, + if (this->canDraw(atlasGlyphCache, skPaint, viewMatrix, props, *context->caps()->shaderCaps())) { sk_sp blob( - this->makeDrawTextBlob(context->getTextBlobCache(), context->getAtlasGlyphCache(), + this->makeDrawTextBlob(textBlobCache, atlasGlyphCache, *context->caps()->shaderCaps(), paint, ComputeScalerContextFlags(target->colorSpaceInfo()), viewMatrix, props, text, byteLength, x, y)); if (blob) { - blob->flushThrowaway(context, target, props, fDistanceAdjustTable.get(), paint, clip, - viewMatrix, regionClipBounds, x, y); + blob->flushThrowaway(atlasGlyphCache, target, props, fDistanceAdjustTable.get(), paint, + clip, viewMatrix, regionClipBounds, x, y); } return; } // fall back to drawing as a path or scaled glyph - GrTextUtils::DrawBigText(context, target, clip, paint, viewMatrix, text, byteLength, x, y, + GrTextUtils::DrawBigText(target, clip, paint, viewMatrix, text, byteLength, x, y, regionClipBounds); } @@ -347,22 +354,27 @@ void GrAtlasTextContext::drawPosText(GrContext* context, GrTextUtils::Target* ta GrTextUtils::Paint paint(&skPaint, &target->colorSpaceInfo()); if (context->abandoned()) { return; - } else if (this->canDraw(context->getAtlasGlyphCache(), skPaint, viewMatrix, props, - *context->caps()->shaderCaps())) { + } + + auto atlasGlyphCache = context->contextPriv().getAtlasGlyphCache(); + auto textBlobCache = context->contextPriv().getTextBlobCache(); + + if (this->canDraw(atlasGlyphCache, skPaint, viewMatrix, props, + *context->caps()->shaderCaps())) { sk_sp blob(this->makeDrawPosTextBlob( - context->getTextBlobCache(), context->getAtlasGlyphCache(), + textBlobCache, atlasGlyphCache, *context->caps()->shaderCaps(), paint, ComputeScalerContextFlags(target->colorSpaceInfo()), viewMatrix, props, text, byteLength, pos, scalarsPerPosition, offset)); if (blob) { - blob->flushThrowaway(context, target, props, fDistanceAdjustTable.get(), paint, clip, - viewMatrix, regionClipBounds, offset.fX, offset.fY); + blob->flushThrowaway(atlasGlyphCache, target, props, fDistanceAdjustTable.get(), paint, + clip, viewMatrix, regionClipBounds, offset.fX, offset.fY); } return; } // fall back to drawing as a path or scaled glyph - GrTextUtils::DrawBigPosText(context, target, props, clip, paint, viewMatrix, text, + GrTextUtils::DrawBigPosText(target, props, clip, paint, viewMatrix, text, byteLength, pos, scalarsPerPosition, offset, regionClipBounds); } @@ -836,16 +848,18 @@ GR_DRAW_OP_TEST_DEFINE(GrAtlasTextOp) { SkScalar x = SkIntToScalar(xInt); SkScalar y = SkIntToScalar(yInt); + auto atlasGlyphCache = context->contextPriv().getAtlasGlyphCache(); + // right now we don't handle textblobs, nor do we handle drawPosText. Since we only intend to // test the text op with this unit test, that is okay. sk_sp blob(gTextContext->makeDrawTextBlob( - context->getTextBlobCache(), context->getAtlasGlyphCache(), + context->contextPriv().getTextBlobCache(), atlasGlyphCache, *context->caps()->shaderCaps(), utilsPaint, GrAtlasTextContext::kTextBlobOpScalerContextFlags, viewMatrix, gSurfaceProps, text, static_cast(textLen), x, y)); return blob->test_makeOp(textLen, 0, 0, viewMatrix, x, y, utilsPaint, gSurfaceProps, - gTextContext->dfAdjustTable(), context->getAtlasGlyphCache(), + gTextContext->dfAdjustTable(), atlasGlyphCache, rtc->textTarget()); } diff --git a/src/gpu/text/GrTextUtils.cpp b/src/gpu/text/GrTextUtils.cpp index 20a3a5c52c..d4a80e0600 100644 --- a/src/gpu/text/GrTextUtils.cpp +++ b/src/gpu/text/GrTextUtils.cpp @@ -78,7 +78,7 @@ bool GrTextUtils::ShouldDisableLCD(const SkPaint& paint) { paint.isFakeBoldText() || paint.getStyle() != SkPaint::kFill_Style; } -void GrTextUtils::DrawBigText(GrContext* context, GrTextUtils::Target* target, +void GrTextUtils::DrawBigText(GrTextUtils::Target* target, const GrClip& clip, const SkPaint& paint, const SkMatrix& viewMatrix, const char text[], size_t byteLength, SkScalar x, SkScalar y, const SkIRect& clipBounds) { @@ -104,7 +104,7 @@ void GrTextUtils::DrawBigText(GrContext* context, GrTextUtils::Target* target, } } -void GrTextUtils::DrawBigPosText(GrContext* context, GrTextUtils::Target* target, +void GrTextUtils::DrawBigPosText(GrTextUtils::Target* target, const SkSurfaceProps& props, const GrClip& clip, const SkPaint& origPaint, const SkMatrix& viewMatrix, const char text[], size_t byteLength, const SkScalar pos[], diff --git a/src/gpu/text/GrTextUtils.h b/src/gpu/text/GrTextUtils.h index 3b1968decd..252cd7c626 100644 --- a/src/gpu/text/GrTextUtils.h +++ b/src/gpu/text/GrTextUtils.h @@ -129,17 +129,17 @@ public: static bool ShouldDisableLCD(const SkPaint& paint); // Functions for drawing large text either as paths or (for color emoji) as scaled glyphs - static void DrawBigText(GrContext*, GrTextUtils::Target*, const GrClip& clip, - const SkPaint& paint, const SkMatrix& viewMatrix, const char text[], - size_t byteLength, SkScalar x, SkScalar y, + static void DrawBigText(GrTextUtils::Target*, const GrClip& clip, + const SkPaint& paint, const SkMatrix& viewMatrix, const char text[], + size_t byteLength, SkScalar x, SkScalar y, + const SkIRect& clipBounds); + + static void DrawBigPosText(GrTextUtils::Target*, + const SkSurfaceProps& props, const GrClip& clip, + const SkPaint& paint, const SkMatrix& viewMatrix, + const char text[], size_t byteLength, const SkScalar pos[], + int scalarsPerPosition, const SkPoint& offset, const SkIRect& clipBounds); - - static void DrawBigPosText(GrContext* context, GrTextUtils::Target*, - const SkSurfaceProps& props, const GrClip& clip, - const SkPaint& paint, const SkMatrix& viewMatrix, - const char text[], size_t byteLength, const SkScalar pos[], - int scalarsPerPosition, const SkPoint& offset, - const SkIRect& clipBounds); }; #endif diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index d078de1f20..304a4cd6d0 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -590,7 +590,8 @@ sk_sp SkImage::MakeCrossContextFromEncoded(GrContext* context, sk_spcontextPriv().prepareSurfaceForExternalIO(proxy.get()); - sk_sp sema = context->getGpu()->prepareTextureForCrossContextUsage(texture.get()); + GrGpu* gpu = context->contextPriv().getGpu(); + sk_sp sema = gpu->prepareTextureForCrossContextUsage(texture.get()); auto gen = GrBackendTextureImageGenerator::Make(std::move(texture), proxy->origin(), std::move(sema), codecImage->alphaType(), @@ -625,8 +626,9 @@ sk_sp SkImage::MakeCrossContextFromPixmap(GrContext* context, const SkP // Flush any writes or uploads context->contextPriv().prepareSurfaceForExternalIO(proxy.get()); + GrGpu* gpu = context->contextPriv().getGpu(); - sk_sp sema = context->getGpu()->prepareTextureForCrossContextUsage(texture.get()); + sk_sp sema = gpu->prepareTextureForCrossContextUsage(texture.get()); auto gen = GrBackendTextureImageGenerator::Make(std::move(texture), proxy->origin(), std::move(sema), pixmap.alphaType(), diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp index efa7de20d7..dac78a89c0 100644 --- a/tests/EGLImageTest.cpp +++ b/tests/EGLImageTest.cpp @@ -28,7 +28,7 @@ static void cleanup(GLTestContext* glctx0, GrGLuint texID0, GLTestContext* glctx glctx1->makeCurrent(); if (grctx1) { if (backendTex1 && backendTex1->isValid()) { - GrGLGpu* gpu1 = static_cast(grctx1->getGpu()); + GrGLGpu* gpu1 = static_cast(grctx1->contextPriv().getGpu()); gpu1->deleteTestingOnlyBackendTexture(backendTex1); } } @@ -53,7 +53,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { if (kGLES_GrGLStandard != glCtx0->gl()->fStandard) { return; } - GrGLGpu* gpu0 = static_cast(context0->getGpu()); + GrGLGpu* gpu0 = static_cast(context0->contextPriv().getGpu()); if (!gpu0->glCaps().shaderCaps()->externalTextureSupport()) { return; } @@ -83,7 +83,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { // Use GL Context 1 to create a texture unknown to GrContext. context1->flush(); - GrGpu* gpu1 = context1->getGpu(); + GrGpu* gpu1 = context1->contextPriv().getGpu(); static const int kSize = 100; backendTexture1 = gpu1->createTestingOnlyBackendTexture(nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp index cf920957be..6c2e8d2f04 100644 --- a/tests/GLProgramsTest.cpp +++ b/tests/GLProgramsTest.cpp @@ -348,7 +348,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages, int ma static int get_glprograms_max_stages(const sk_gpu_test::ContextInfo& ctxInfo) { GrContext* context = ctxInfo.grContext(); - GrGLGpu* gpu = static_cast(context->getGpu()); + GrGLGpu* gpu = static_cast(context->contextPriv().getGpu()); int maxStages = 6; if (kGLES_GrGLStandard == gpu->glStandard()) { // We've had issues with driver crashes and HW limits being exceeded with many effects on diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp index df1e8ee901..006fd00a28 100644 --- a/tests/GrMipMappedTest.cpp +++ b/tests/GrMipMappedTest.cpp @@ -37,12 +37,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) { if (!context->caps()->mipMapSupport()) { return; } + GrGpu* gpu = context->contextPriv().getGpu(); + for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) { for (auto isRT : {false, true}) { // CreateTestingOnlyBackendTexture currently doesn't support uploading data to mip maps // so we don't send any. However, we pretend there is data for the checks below which is // fine since we are never actually using these textures for any work on the gpu. - GrBackendTexture backendTex = context->getGpu()->createTestingOnlyBackendTexture( + GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, isRT, mipMapped); sk_sp proxy; @@ -69,7 +71,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) { } REPORTER_ASSERT(reporter, proxy); if (!proxy) { - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); return; } @@ -78,7 +80,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) { GrTexture* texture = proxy->priv().peekTexture(); REPORTER_ASSERT(reporter, texture); if (!texture) { - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); return; } @@ -92,7 +94,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) { } else { REPORTER_ASSERT(reporter, GrMipMapped::kNo == texture->texturePriv().mipMapped()); } - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); } } } @@ -104,9 +106,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, if (!context->caps()->mipMapSupport()) { return; } + GrGpu* gpu = context->contextPriv().getGpu(); + for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) { for (auto willUseMips : {false, true}) { - GrBackendTexture backendTex = context->getGpu()->createTestingOnlyBackendTexture( + GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, false, mipMapped); sk_sp image = SkImage::MakeFromTexture(context, backendTex, @@ -118,7 +122,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, GrTextureProxy* proxy = as_IB(image)->peekProxy(); REPORTER_ASSERT(reporter, proxy); if (!proxy) { - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); return; } @@ -127,7 +131,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, sk_sp texture = sk_ref_sp(proxy->priv().peekTexture()); REPORTER_ASSERT(reporter, texture); if (!texture) { - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); return; } @@ -135,7 +139,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, texture, kTopLeft_GrSurfaceOrigin, nullptr, kPremul_SkAlphaType, nullptr); REPORTER_ASSERT(reporter, imageGen); if (!imageGen) { - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); return; } @@ -151,7 +155,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, REPORTER_ASSERT(reporter, genProxy); if (!genProxy) { - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); return; } @@ -164,7 +168,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, GrTexture* genTexture = genProxy->priv().peekTexture(); REPORTER_ASSERT(reporter, genTexture); if (!genTexture) { - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); return; } @@ -202,7 +206,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, bitmap.allocPixels(imageInfo); surfContext->readPixels(imageInfo, bitmap.getPixels(), 0, 0, 0, 0); - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); } } } @@ -216,12 +220,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxIn } auto resourceProvider = context->contextPriv().resourceProvider(); + GrGpu* gpu = context->contextPriv().getGpu(); for (auto willUseMips : {false, true}) { for (auto isWrapped : {false, true}) { GrMipMapped mipMapped = willUseMips ? GrMipMapped::kYes : GrMipMapped::kNo; sk_sp surface; - GrBackendTexture backendTex = context->getGpu()->createTestingOnlyBackendTexture( + GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, true, mipMapped); if (isWrapped) { surface = SkSurface::MakeFromBackendTexture(context, @@ -240,7 +245,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxIn } REPORTER_ASSERT(reporter, surface); if (!surface) { - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); } SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice(); GrTextureProxy* texProxy = device->accessRenderTargetContext()->asTextureProxy(); @@ -253,7 +258,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxIn sk_sp image = surface->makeImageSnapshot(); REPORTER_ASSERT(reporter, image); if (!image) { - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); } texProxy = as_IB(image)->peekProxy(); REPORTER_ASSERT(reporter, mipMapped == texProxy->mipMapped()); @@ -265,7 +270,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxIn // Must flush the context to make sure all the cmds (copies, etc.) from above are sent // to the gpu before we delete the backendHandle. context->flush(); - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); } } } diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp index 6c1f209527..7e938c7761 100644 --- a/tests/GrPorterDuffTest.cpp +++ b/tests/GrPorterDuffTest.cpp @@ -30,7 +30,7 @@ static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps); static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const GrCaps& caps); DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrPorterDuff, reporter, ctxInfo) { - const GrCaps& caps = *ctxInfo.grContext()->getGpu()->caps(); + const GrCaps& caps = *ctxInfo.grContext()->contextPriv().getGpu()->caps(); if (!caps.shaderCaps()->dualSourceBlendingSupport()) { SK_ABORT("Null context does not support dual source blending."); return; @@ -1061,6 +1061,7 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, options) { return; } + GrGpu* gpu = ctx->contextPriv().getGpu(); GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider(); const GrCaps& caps = *ctx->caps(); if (caps.shaderCaps()->dualSourceBlendingSupport()) { @@ -1069,8 +1070,8 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, options) { } GrBackendTexture backendTex = - ctx->getGpu()->createTestingOnlyBackendTexture(nullptr, 100, 100, kRGBA_8888_GrPixelConfig, - false, GrMipMapped::kNo); + gpu->createTestingOnlyBackendTexture(nullptr, 100, 100, kRGBA_8888_GrPixelConfig, + false, GrMipMapped::kNo); GrXferProcessor::DstProxy fakeDstProxy; { @@ -1101,7 +1102,7 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, options) { } } } - ctx->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); } #endif diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index eab930145c..72a92a709d 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -25,6 +25,7 @@ DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); auto resourceProvider = context->contextPriv().resourceProvider(); + GrGpu* gpu = context->contextPriv().getGpu(); GrSurfaceDesc desc; desc.fFlags = kRenderTarget_GrSurfaceFlag; @@ -51,7 +52,7 @@ DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) { REPORTER_ASSERT(reporter, tex1.get() == tex1->asTexture()); REPORTER_ASSERT(reporter, static_cast(tex1.get()) == tex1->asTexture()); - GrBackendTexture backendTex = context->getGpu()->createTestingOnlyBackendTexture( + GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( nullptr, 256, 256, kRGBA_8888_GrPixelConfig, false, GrMipMapped::kNo); sk_sp texRT2 = resourceProvider->wrapRenderableBackendTexture( @@ -66,7 +67,7 @@ DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) { REPORTER_ASSERT(reporter, static_cast(texRT2->asRenderTarget()) == static_cast(texRT2->asTexture())); - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); } // This test checks that the isConfigTexturable and isConfigRenderable are diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 078bd7c1bd..83ff47c256 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -723,8 +723,9 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c std::unique_ptr pixels(new uint32_t[kWidth * kHeight]); GrContext* ctx = ctxInfo.grContext(); + GrGpu* gpu = ctx->contextPriv().getGpu(); - GrBackendTexture backendTex = ctxInfo.grContext()->getGpu()->createTestingOnlyBackendTexture( + GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true, GrMipMapped::kNo); TextureReleaseChecker releaseChecker; @@ -756,7 +757,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c refImg.reset(nullptr); // force a release of the image REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); - ctxInfo.grContext()->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); } static void test_cross_context_image(skiatest::Reporter* reporter, const GrContextOptions& options, diff --git a/tests/PrimitiveProcessorTest.cpp b/tests/PrimitiveProcessorTest.cpp index b8b9e6f3ce..406d5e2104 100644 --- a/tests/PrimitiveProcessorTest.cpp +++ b/tests/PrimitiveProcessorTest.cpp @@ -111,6 +111,9 @@ private: DEF_GPUTEST_FOR_ALL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); +#if GR_GPU_STATS + GrGpu* gpu = context->contextPriv().getGpu(); +#endif sk_sp renderTargetContext(context->makeDeferredRenderTargetContext( SkBackingFit::kApprox, @@ -128,23 +131,23 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) { context->flush(); context->resetGpuStats(); #if GR_GPU_STATS - REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 0); - REPORTER_ASSERT(reporter, context->getGpu()->stats()->numFailedDraws() == 0); + REPORTER_ASSERT(reporter, gpu->stats()->numDraws() == 0); + REPORTER_ASSERT(reporter, gpu->stats()->numFailedDraws() == 0); #endif GrPaint grPaint; // This one should succeed. renderTargetContext->priv().testingOnly_addDrawOp(Op::Make(attribCnt)); context->flush(); #if GR_GPU_STATS - REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 1); - REPORTER_ASSERT(reporter, context->getGpu()->stats()->numFailedDraws() == 0); + REPORTER_ASSERT(reporter, gpu->stats()->numDraws() == 1); + REPORTER_ASSERT(reporter, gpu->stats()->numFailedDraws() == 0); #endif context->resetGpuStats(); renderTargetContext->priv().testingOnly_addDrawOp(Op::Make(attribCnt + 1)); context->flush(); #if GR_GPU_STATS - REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 0); - REPORTER_ASSERT(reporter, context->getGpu()->stats()->numFailedDraws() == 1); + REPORTER_ASSERT(reporter, gpu->stats()->numDraws() == 0); + REPORTER_ASSERT(reporter, gpu->stats()->numFailedDraws() == 1); #endif } #endif diff --git a/tests/ResourceAllocatorTest.cpp b/tests/ResourceAllocatorTest.cpp index 55a7766944..121cf86345 100644 --- a/tests/ResourceAllocatorTest.cpp +++ b/tests/ResourceAllocatorTest.cpp @@ -47,16 +47,17 @@ static sk_sp make_deferred(GrProxyProvider* proxyProvider, const static sk_sp make_backend(GrContext* context, const ProxyParams& p, GrBackendTexture* backendTex) { GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); + GrGpu* gpu = context->contextPriv().getGpu(); - *backendTex = context->getGpu()->createTestingOnlyBackendTexture(nullptr, p.fSize, p.fSize, - p.fConfig, false, - GrMipMapped::kNo); + *backendTex = gpu->createTestingOnlyBackendTexture(nullptr, p.fSize, p.fSize, + p.fConfig, false, + GrMipMapped::kNo); return proxyProvider->createWrappedTextureProxy(*backendTex, p.fOrigin); } static void cleanup_backend(GrContext* context, GrBackendTexture* backendTex) { - context->getGpu()->deleteTestingOnlyBackendTexture(backendTex); + context->contextPriv().getGpu()->deleteTestingOnlyBackendTexture(backendTex); } // Basic test that two proxies with overlapping intervals and compatible descriptors are diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index dd122a0dea..34ed4f7328 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -200,7 +200,7 @@ DEF_GPUTEST_FOR_CONTEXTS(ResourceCacheStencilBuffers, &is_rendering_and_not_angl DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); GrResourceProvider* resourceProvider = context->contextPriv().resourceProvider(); - GrGpu* gpu = context->getGpu(); + GrGpu* gpu = context->contextPriv().getGpu(); // this test is only valid for GL if (!gpu || !gpu->glContextForTesting()) { return; @@ -370,12 +370,13 @@ static void test_no_key(skiatest::Reporter* reporter) { Mock mock(10, 30000); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); // Create a bunch of resources with no keys - TestResource* a = new TestResource(context->getGpu()); - TestResource* b = new TestResource(context->getGpu()); - TestResource* c = new TestResource(context->getGpu()); - TestResource* d = new TestResource(context->getGpu()); + TestResource* a = new TestResource(gpu); + TestResource* b = new TestResource(gpu); + TestResource* c = new TestResource(gpu); + TestResource* d = new TestResource(gpu); a->setSize(11); b->setSize(12); c->setSize(13); @@ -427,21 +428,21 @@ static void test_budgeting(skiatest::Reporter* reporter) { Mock mock(10, 300); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); GrUniqueKey uniqueKey; make_unique_key<0>(&uniqueKey, 0); // Create a scratch, a unique, and a wrapped resource TestResource* scratch = - TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, TestResource::kB_SimulatedProperty); + TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty); scratch->setSize(10); - TestResource* unique = new TestResource(context->getGpu()); + TestResource* unique = new TestResource(gpu); unique->setSize(11); unique->resourcePriv().setUniqueKey(uniqueKey); - TestResource* wrapped = TestResource::CreateWrapped(context->getGpu()); + TestResource* wrapped = TestResource::CreateWrapped(gpu); wrapped->setSize(12); - TestResource* unbudgeted = - new TestResource(context->getGpu(), SkBudgeted::kNo); + TestResource* unbudgeted = new TestResource(gpu, SkBudgeted::kNo); unbudgeted->setSize(13); // Make sure we can add a unique key to the wrapped resource @@ -483,7 +484,7 @@ static void test_budgeting(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); // Now try freeing the budgeted resources first - wrapped = TestResource::CreateWrapped(context->getGpu()); + wrapped = TestResource::CreateWrapped(gpu); scratch->setSize(12); unique->unref(); REPORTER_ASSERT(reporter, 11 == cache->getPurgeableBytes()); @@ -524,6 +525,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) { Mock mock(10, 30000); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); GrUniqueKey uniqueKey; make_unique_key<0>(&uniqueKey, 0); @@ -534,7 +536,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) { TestResource* unbudgeted; // A large uncached or wrapped resource shouldn't evict anything. - scratch = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, + scratch = TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty); scratch->setSize(10); @@ -545,7 +547,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 10 == cache->getBudgetedResourceBytes()); REPORTER_ASSERT(reporter, 10 == cache->getPurgeableBytes()); - unique = new TestResource(context->getGpu()); + unique = new TestResource(gpu); unique->setSize(11); unique->resourcePriv().setUniqueKey(uniqueKey); unique->unref(); @@ -556,7 +558,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes()); size_t large = 2 * cache->getResourceBytes(); - unbudgeted = new TestResource(context->getGpu(), SkBudgeted::kNo, large); + unbudgeted = new TestResource(gpu, SkBudgeted::kNo, large); REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); @@ -570,7 +572,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes()); - wrapped = TestResource::CreateWrapped(context->getGpu(), large); + wrapped = TestResource::CreateWrapped(gpu, large); REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); @@ -598,10 +600,10 @@ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter); Mock mock(10, 300); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); TestResource* resource = - TestResource::CreateScratch(context->getGpu(), SkBudgeted::kNo, - TestResource::kA_SimulatedProperty); + TestResource::CreateScratch(gpu, SkBudgeted::kNo, TestResource::kA_SimulatedProperty); GrScratchKey key; TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key); @@ -662,12 +664,13 @@ static void test_duplicate_scratch_key(skiatest::Reporter* reporter) { Mock mock(5, 30000); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); // Create two resources that have the same scratch key. - TestResource* a = TestResource::CreateScratch(context->getGpu(), + TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty); - TestResource* b = TestResource::CreateScratch(context->getGpu(), + TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty); a->setSize(11); @@ -709,11 +712,12 @@ static void test_remove_scratch_key(skiatest::Reporter* reporter) { Mock mock(5, 30000); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); // Create two resources that have the same scratch key. - TestResource* a = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, + TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty); - TestResource* b = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, + TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty); a->unref(); b->unref(); @@ -768,11 +772,12 @@ static void test_scratch_key_consistency(skiatest::Reporter* reporter) { Mock mock(5, 30000); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); // Create two resources that have the same scratch key. - TestResource* a = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, + TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty); - TestResource* b = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, + TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty); a->unref(); b->unref(); @@ -827,12 +832,13 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) { Mock mock(5, 30000); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); GrUniqueKey key; make_unique_key<0>(&key, 0); // Create two resources that we will attempt to register with the same unique key. - TestResource* a = new TestResource(context->getGpu()); + TestResource* a = new TestResource(gpu); a->setSize(11); // Set key on resource a. @@ -849,7 +855,7 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); // Create resource b and set the same key. It should replace a's unique key cache entry. - TestResource* b = new TestResource(context->getGpu()); + TestResource* b = new TestResource(gpu); b->setSize(12); b->resourcePriv().setUniqueKey(key); REPORTER_ASSERT(reporter, b == cache->findAndRefUniqueResource(key)); @@ -869,7 +875,7 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) { // Now replace b with c, but make sure c can start with one unique key and change it to b's key. // Also make b be unreffed when replacement occurs. b->unref(); - TestResource* c = new TestResource(context->getGpu()); + TestResource* c = new TestResource(gpu); GrUniqueKey differentKey; make_unique_key<0>(&differentKey, 1); c->setSize(13); @@ -906,7 +912,7 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) { { GrUniqueKey key2; make_unique_key<0>(&key2, 0); - sk_sp d(new TestResource(context->getGpu())); + sk_sp d(new TestResource(gpu)); int foo = 4132; key2.setCustomData(SkData::MakeWithCopy(&foo, sizeof(foo))); d->resourcePriv().setUniqueKey(key2); @@ -922,6 +928,7 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) { Mock mock(5, 30000); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); GrUniqueKey key1, key2, key3; make_unique_key<0>(&key1, 1); @@ -929,9 +936,9 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) { make_unique_key<0>(&key3, 3); // Add three resources to the cache. Only c is usable as scratch. - TestResource* a = new TestResource(context->getGpu()); - TestResource* b = new TestResource(context->getGpu()); - TestResource* c = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, + TestResource* a = new TestResource(gpu); + TestResource* b = new TestResource(gpu); + TestResource* c = TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kA_SimulatedProperty); a->resourcePriv().setUniqueKey(key1); b->resourcePriv().setUniqueKey(key2); @@ -990,13 +997,14 @@ static void test_cache_chained_purge(skiatest::Reporter* reporter) { Mock mock(3, 30000); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); GrUniqueKey key1, key2; make_unique_key<0>(&key1, 1); make_unique_key<0>(&key2, 2); - TestResource* a = new TestResource(context->getGpu()); - TestResource* b = new TestResource(context->getGpu()); + TestResource* a = new TestResource(gpu); + TestResource* b = new TestResource(gpu); a->resourcePriv().setUniqueKey(key1); b->resourcePriv().setUniqueKey(key2); @@ -1032,12 +1040,13 @@ static void test_resource_size_changed(skiatest::Reporter* reporter) { Mock mock(3, 30000); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); - TestResource* a = new TestResource(context->getGpu()); + TestResource* a = new TestResource(gpu); a->resourcePriv().setUniqueKey(key1); a->unref(); - TestResource* b = new TestResource(context->getGpu()); + TestResource* b = new TestResource(gpu); b->resourcePriv().setUniqueKey(key2); b->unref(); @@ -1061,13 +1070,14 @@ static void test_resource_size_changed(skiatest::Reporter* reporter) { Mock mock(2, 300); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); - TestResource* a = new TestResource(context->getGpu()); + TestResource* a = new TestResource(gpu); a->setSize(100); a->resourcePriv().setUniqueKey(key1); a->unref(); - TestResource* b = new TestResource(context->getGpu()); + TestResource* b = new TestResource(gpu); b->setSize(100); b->resourcePriv().setUniqueKey(key2); b->unref(); @@ -1100,6 +1110,7 @@ static void test_timestamp_wrap(skiatest::Reporter* reporter) { Mock mock(kBudgetCnt, kBudgetSize); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); // Pick a random number of resources to add before the timestamp will wrap. cache->changeTimestamp(SK_MaxU32 - random.nextULessThan(kCount + 1)); @@ -1116,7 +1127,7 @@ static void test_timestamp_wrap(skiatest::Reporter* reporter) { GrUniqueKey key; make_unique_key<0>(&key, j); - TestResource* r = new TestResource(context->getGpu()); + TestResource* r = new TestResource(gpu); r->resourcePriv().setUniqueKey(key); if (random.nextU() % kLockedFreq) { // Make this is purgeable. @@ -1156,6 +1167,7 @@ static void test_flush(skiatest::Reporter* reporter) { Mock mock(1000000, 1000000); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); // The current cache impl will round the max flush count to the next power of 2. So we choose a // power of two here to keep things simpler. @@ -1165,7 +1177,7 @@ static void test_flush(skiatest::Reporter* reporter) { { // Insert a resource and send a flush notification kFlushCount times. for (int i = 0; i < kFlushCount; ++i) { - TestResource* r = new TestResource(context->getGpu()); + TestResource* r = new TestResource(gpu); GrUniqueKey k; make_unique_key<1>(&k, i); r->resourcePriv().setUniqueKey(k); @@ -1195,7 +1207,7 @@ static void test_flush(skiatest::Reporter* reporter) { { GrGpuResource* refedResources[kFlushCount >> 1]; for (int i = 0; i < kFlushCount; ++i) { - TestResource* r = new TestResource(context->getGpu()); + TestResource* r = new TestResource(gpu); GrUniqueKey k; make_unique_key<1>(&k, i); r->resourcePriv().setUniqueKey(k); @@ -1236,7 +1248,7 @@ static void test_flush(skiatest::Reporter* reporter) { // eviction. context->flush(); for (int i = 0; i < 10; ++i) { - TestResource* r = new TestResource(context->getGpu()); + TestResource* r = new TestResource(gpu); GrUniqueKey k; make_unique_key<1>(&k, i); r->resourcePriv().setUniqueKey(k); @@ -1253,6 +1265,7 @@ static void test_time_purge(skiatest::Reporter* reporter) { Mock mock(1000000, 1000000); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); static constexpr int kCnts[] = {1, 10, 1024}; auto nowish = []() { @@ -1271,7 +1284,7 @@ static void test_time_purge(skiatest::Reporter* reporter) { { // Insert resources and get time points between each addition. for (int i = 0; i < cnt; ++i) { - TestResource* r = new TestResource(context->getGpu()); + TestResource* r = new TestResource(gpu); GrUniqueKey k; make_unique_key<1>(&k, i); r->resourcePriv().setUniqueKey(k); @@ -1302,7 +1315,7 @@ static void test_time_purge(skiatest::Reporter* reporter) { { std::unique_ptr refedResources(new GrGpuResource*[cnt / 2]); for (int i = 0; i < cnt; ++i) { - TestResource* r = new TestResource(context->getGpu()); + TestResource* r = new TestResource(gpu); GrUniqueKey k; make_unique_key<1>(&k, i); r->resourcePriv().setUniqueKey(k); @@ -1337,7 +1350,7 @@ static void test_time_purge(skiatest::Reporter* reporter) { // eviction context->flush(); for (int i = 0; i < 10; ++i) { - TestResource* r = new TestResource(context->getGpu()); + TestResource* r = new TestResource(gpu); GrUniqueKey k; make_unique_key<1>(&k, i); r->resourcePriv().setUniqueKey(k); @@ -1355,6 +1368,7 @@ static void test_partial_purge(skiatest::Reporter* reporter) { Mock mock(6, 100); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); enum TestsCase { kOnlyScratch_TestCase = 0, @@ -1374,9 +1388,9 @@ static void test_partial_purge(skiatest::Reporter* reporter) { make_unique_key<0>(&key3, 3); // Add three unique resources to the cache. - TestResource *unique1 = new TestResource(context->getGpu()); - TestResource *unique2 = new TestResource(context->getGpu()); - TestResource *unique3 = new TestResource(context->getGpu()); + TestResource *unique1 = new TestResource(gpu); + TestResource *unique2 = new TestResource(gpu); + TestResource *unique3 = new TestResource(gpu); unique1->resourcePriv().setUniqueKey(key1); unique2->resourcePriv().setUniqueKey(key2); @@ -1387,9 +1401,9 @@ static void test_partial_purge(skiatest::Reporter* reporter) { unique3->setSize(12); // Add two scratch resources to the cache. - TestResource *scratch1 = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, + TestResource *scratch1 = TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kA_SimulatedProperty); - TestResource *scratch2 = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, + TestResource *scratch2 = TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty); scratch1->setSize(13); scratch2->setSize(14); @@ -1468,6 +1482,7 @@ static void test_large_resource_count(skiatest::Reporter* reporter) { Mock mock(2 * kResourceCnt, 2 * kResourceCnt + 1000); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); for (int i = 0; i < kResourceCnt; ++i) { GrUniqueKey key1, key2; @@ -1476,12 +1491,12 @@ static void test_large_resource_count(skiatest::Reporter* reporter) { TestResource* resource; - resource = new TestResource(context->getGpu()); + resource = new TestResource(gpu); resource->resourcePriv().setUniqueKey(key1); resource->setSize(1); resource->unref(); - resource = new TestResource(context->getGpu()); + resource = new TestResource(gpu); resource->resourcePriv().setUniqueKey(key2); resource->setSize(1); resource->unref(); @@ -1537,7 +1552,9 @@ static void test_custom_data(skiatest::Reporter* reporter) { static void test_abandoned(skiatest::Reporter* reporter) { Mock mock(10, 300); GrContext* context = mock.context(); - sk_sp resource(new TestResource(context->getGpu())); + GrGpu* gpu = context->contextPriv().getGpu(); + + sk_sp resource(new TestResource(gpu)); context->abandonContext(); REPORTER_ASSERT(reporter, resource->wasDestroyed()); @@ -1571,13 +1588,14 @@ static void test_tags(skiatest::Reporter* reporter) { Mock mock(kNumResources, kNumResources * TestResource::kDefaultSize); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); + GrGpu* gpu = context->contextPriv().getGpu(); SkString tagStr; int tagIdx = 0; int currTagCnt = 0; for (int i = 0; i < kNumResources; ++i, ++currTagCnt) { - sk_sp resource(new TestResource(context->getGpu())); + sk_sp resource(new TestResource(gpu)); GrUniqueKey key; if (currTagCnt == tagIdx) { tagIdx += 1; diff --git a/tests/SRGBMipMapTest.cpp b/tests/SRGBMipMapTest.cpp index 7d6f6a9546..b24b7f77f9 100644 --- a/tests/SRGBMipMapTest.cpp +++ b/tests/SRGBMipMapTest.cpp @@ -169,7 +169,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SRGBMipMaps, reporter, ctxInfo) { // // TODO: Once Vulkan supports legacy mip-mapping, we can promote this to GrCaps. Right now, // Vulkan has most of the functionality, but not the mip-mapping part that's being tested here. - GrGLGpu* glGpu = static_cast(context->getGpu()); + GrGLGpu* glGpu = static_cast(context->contextPriv().getGpu()); if (glGpu->glCaps().srgbDecodeDisableSupport() && glGpu->glCaps().srgbDecodeDisableAffectsMipmaps()) { read_and_check_pixels(reporter, l32RenderTargetContext.get(), expectedLinear, iiRGBA, diff --git a/tests/SurfaceSemaphoreTest.cpp b/tests/SurfaceSemaphoreTest.cpp index b4f63fec41..eea6e37670 100644 --- a/tests/SurfaceSemaphoreTest.cpp +++ b/tests/SurfaceSemaphoreTest.cpp @@ -8,6 +8,7 @@ #include "SkTypes.h" #if SK_SUPPORT_GPU +#include "GrContextPriv.h" #include "GrContextFactory.h" #include "GrTest.h" #include "Test.h" @@ -132,7 +133,7 @@ void surface_semaphore_test(skiatest::Reporter* reporter, #ifdef SK_VULKAN if (kVulkan_GrBackend == mainInfo.backend()) { // Initialize the secondary semaphore instead of having Ganesh create one internally - GrVkGpu* gpu = static_cast(mainCtx->getGpu()); + GrVkGpu* gpu = static_cast(mainCtx->contextPriv().getGpu()); const GrVkInterface* interface = gpu->vkInterface(); VkDevice device = gpu->device(); @@ -235,7 +236,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(EmptySurfaceSemaphoreTest, reporter, ctxInfo) REPORTER_ASSERT(reporter, GrSemaphoresSubmitted::kYes == submitted); if (kOpenGL_GrBackend == ctxInfo.backend()) { - GrGLGpu* gpu = static_cast(ctx->getGpu()); + GrGLGpu* gpu = static_cast(ctx->contextPriv().getGpu()); const GrGLInterface* interface = gpu->glInterface(); GrGLsync sync = semaphore.glSync(); REPORTER_ASSERT(reporter, sync); @@ -246,7 +247,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(EmptySurfaceSemaphoreTest, reporter, ctxInfo) #ifdef SK_VULKAN if (kVulkan_GrBackend == ctxInfo.backend()) { - GrVkGpu* gpu = static_cast(ctx->getGpu()); + GrVkGpu* gpu = static_cast(ctx->contextPriv().getGpu()); const GrVkInterface* interface = gpu->vkInterface(); VkDevice device = gpu->device(); VkQueue queue = gpu->queue(); diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 7f0d9973b5..c06ba240ed 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -584,15 +584,17 @@ DEF_TEST(surface_raster_zeroinitialized, reporter) { #if SK_SUPPORT_GPU static sk_sp create_gpu_surface_backend_texture( GrContext* context, int sampleCnt, uint32_t color, GrBackendTexture* outTexture) { + GrGpu* gpu = context->contextPriv().getGpu(); + const int kWidth = 10; const int kHeight = 10; std::unique_ptr pixels(new uint32_t[kWidth * kHeight]); sk_memset32(pixels.get(), color, kWidth * kHeight); - *outTexture = context->getGpu()->createTestingOnlyBackendTexture( + *outTexture = gpu->createTestingOnlyBackendTexture( pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true, GrMipMapped::kNo); - if (!outTexture->isValid() || !context->getGpu()->isTestingOnlyBackendTexture(*outTexture)) { + if (!outTexture->isValid() || !gpu->isTestingOnlyBackendTexture(*outTexture)) { return nullptr; } @@ -601,7 +603,7 @@ static sk_sp create_gpu_surface_backend_texture( kRGBA_8888_SkColorType, nullptr, nullptr); if (!surface) { - context->getGpu()->deleteTestingOnlyBackendTexture(outTexture); + gpu->deleteTestingOnlyBackendTexture(outTexture); return nullptr; } return surface; @@ -609,15 +611,17 @@ static sk_sp create_gpu_surface_backend_texture( static sk_sp create_gpu_surface_backend_texture_as_render_target( GrContext* context, int sampleCnt, uint32_t color, GrBackendTexture* outTexture) { + GrGpu* gpu = context->contextPriv().getGpu(); + const int kWidth = 10; const int kHeight = 10; std::unique_ptr pixels(new uint32_t[kWidth * kHeight]); sk_memset32(pixels.get(), color, kWidth * kHeight); - *outTexture = context->getGpu()->createTestingOnlyBackendTexture( + *outTexture = gpu->createTestingOnlyBackendTexture( pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true, GrMipMapped::kNo); - if (!outTexture->isValid() || !context->getGpu()->isTestingOnlyBackendTexture(*outTexture)) { + if (!outTexture->isValid() || !gpu->isTestingOnlyBackendTexture(*outTexture)) { return nullptr; } @@ -626,7 +630,7 @@ static sk_sp create_gpu_surface_backend_texture_as_render_target( nullptr, nullptr); if (!surface) { - context->getGpu()->deleteTestingOnlyBackendTexture(outTexture); + gpu->deleteTestingOnlyBackendTexture(outTexture); return nullptr; } return surface; @@ -674,6 +678,7 @@ static void test_surface_clear(skiatest::Reporter* reporter, sk_sp su DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); + GrGpu* gpu = context->contextPriv().getGpu(); std::function(SkSurface*)> grSurfaceContextGetters[] = { [] (SkSurface* s){ @@ -703,7 +708,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) { auto surface = surfaceFunc(context, 0, kOrigColor, &backendTex); test_surface_clear(reporter, surface, grSurfaceGetter, kOrigColor); surface.reset(); - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); } } } @@ -751,7 +756,7 @@ static void test_surface_draw_partially( } DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacePartialDraw_Gpu, reporter, ctxInfo) { - GrGpu* gpu = ctxInfo.grContext()->getGpu(); + GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu(); if (!gpu) { return; } @@ -774,7 +779,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacePartialDraw_Gpu, reporter, ctxInfo) { DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceAttachStencil_Gpu, reporter, ctxInfo) { - GrGpu* gpu = ctxInfo.grContext()->getGpu(); + GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu(); if (!gpu) { return; } @@ -875,6 +880,7 @@ DEF_TEST(SurfaceCreationWithColorSpace, reporter) { #if SK_SUPPORT_GPU DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCreationWithColorSpace_Gpu, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); + bool f16Support = context->caps()->isConfigRenderable(kRGBA_half_GrPixelConfig, false); auto surfaceMaker = [context](const SkImageInfo& info) { return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info); @@ -884,14 +890,16 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCreationWithColorSpace_Gpu, reporter, std::vector backendTextures; auto wrappedSurfaceMaker = [ context, &backendTextures ](const SkImageInfo& info) { + GrGpu* gpu = context->contextPriv().getGpu(); + static const int kSize = 10; GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *context->caps()); - GrBackendTexture backendTex = context->getGpu()->createTestingOnlyBackendTexture( + GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( nullptr, kSize, kSize, config, true, GrMipMapped::kNo); if (!backendTex.isValid() || - !context->getGpu()->isTestingOnlyBackendTexture(backendTex)) { + !gpu->isTestingOnlyBackendTexture(backendTex)) { return sk_sp(nullptr); } backendTextures.push_back(backendTex); @@ -907,8 +915,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCreationWithColorSpace_Gpu, reporter, context->flush(); + GrGpu* gpu = context->contextPriv().getGpu(); for (auto backendTex : backendTextures) { - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); } } #endif diff --git a/tests/TransferPixelsTest.cpp b/tests/TransferPixelsTest.cpp index ee1a233d63..ce8d1edc4f 100755 --- a/tests/TransferPixelsTest.cpp +++ b/tests/TransferPixelsTest.cpp @@ -69,6 +69,7 @@ void basic_transfer_test(skiatest::Reporter* reporter, GrContext* context, GrPix } auto resourceProvider = context->contextPriv().resourceProvider(); + GrGpu* gpu = context->contextPriv().getGpu(); // set up the data const int kTextureWidth = 16; @@ -110,13 +111,13 @@ void basic_transfer_test(skiatest::Reporter* reporter, GrContext* context, GrPix // transfer full data bool result; - result = context->getGpu()->transferPixels(tex.get(), 0, 0, kTextureWidth, kTextureHeight, - config, buffer.get(), 0, rowBytes); + result = gpu->transferPixels(tex.get(), 0, 0, kTextureWidth, kTextureHeight, + config, buffer.get(), 0, rowBytes); REPORTER_ASSERT(reporter, result); memset(dstBuffer.get(), 0xCDCD, size); - result = context->getGpu()->readPixels(tex.get(), origin, 0, 0, kTextureWidth, kTextureHeight, - config, dstBuffer.get(), rowBytes); + result = gpu->readPixels(tex.get(), origin, 0, 0, kTextureWidth, kTextureHeight, + config, dstBuffer.get(), rowBytes); if (result) { REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_values(srcBuffer, dstBuffer, @@ -142,13 +143,13 @@ void basic_transfer_test(skiatest::Reporter* reporter, GrContext* context, GrPix buffer->unmap(); size_t offset = sizeof(GrColor)*(kTop*kBufferWidth + kLeft); - result = context->getGpu()->transferPixels(tex.get(), kLeft, kTop, kWidth, kHeight, config, - buffer.get(), offset, rowBytes); + result = gpu->transferPixels(tex.get(), kLeft, kTop, kWidth, kHeight, config, + buffer.get(), offset, rowBytes); REPORTER_ASSERT(reporter, result); memset(dstBuffer.get(), 0xCDCD, size); - result = context->getGpu()->readPixels(tex.get(), origin, 0, 0, kTextureWidth, kTextureHeight, - config, dstBuffer.get(), rowBytes); + result = gpu->readPixels(tex.get(), origin, 0, 0, kTextureWidth, kTextureHeight, + config, dstBuffer.get(), rowBytes); if (result) { REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_values(srcBuffer, dstBuffer, diff --git a/tests/VkHeapTests.cpp b/tests/VkHeapTests.cpp index fd5f88a1bb..29e4e7906b 100644 --- a/tests/VkHeapTests.cpp +++ b/tests/VkHeapTests.cpp @@ -11,6 +11,7 @@ #if SK_SUPPORT_GPU && defined(SK_VULKAN) +#include "GrContextPriv.h" #include "GrContextFactory.h" #include "GrTest.h" #include "Test.h" @@ -19,7 +20,7 @@ using sk_gpu_test::GrContextFactory; void subheap_test(skiatest::Reporter* reporter, GrContext* context) { - GrVkGpu* gpu = static_cast(context->getGpu()); + GrVkGpu* gpu = static_cast(context->contextPriv().getGpu()); // memtype doesn't matter, we're just testing the suballocation algorithm so we'll use 0 GrVkSubHeap heap(gpu, 0, 0, 64 * 1024, 32); @@ -116,7 +117,7 @@ void subheap_test(skiatest::Reporter* reporter, GrContext* context) { } void suballoc_test(skiatest::Reporter* reporter, GrContext* context) { - GrVkGpu* gpu = static_cast(context->getGpu()); + GrVkGpu* gpu = static_cast(context->contextPriv().getGpu()); // memtype/heap index don't matter, we're just testing the allocation algorithm so we'll use 0 GrVkHeap heap(gpu, GrVkHeap::kSubAlloc_Strategy, 64 * 1024); @@ -176,7 +177,7 @@ void suballoc_test(skiatest::Reporter* reporter, GrContext* context) { } void singlealloc_test(skiatest::Reporter* reporter, GrContext* context) { - GrVkGpu* gpu = static_cast(context->getGpu()); + GrVkGpu* gpu = static_cast(context->contextPriv().getGpu()); // memtype/heap index don't matter, we're just testing the allocation algorithm so we'll use 0 GrVkHeap heap(gpu, GrVkHeap::kSingleAlloc_Strategy, 64 * 1024); diff --git a/tests/VkWrapTests.cpp b/tests/VkWrapTests.cpp index cf28586196..6cfbba65b6 100644 --- a/tests/VkWrapTests.cpp +++ b/tests/VkWrapTests.cpp @@ -11,6 +11,7 @@ #if SK_SUPPORT_GPU && defined(SK_VULKAN) +#include "GrContextPriv.h" #include "GrContextFactory.h" #include "GrRenderTarget.h" #include "GrTest.h" @@ -30,7 +31,7 @@ const GrPixelConfig kPixelConfig = kRGBA_8888_GrPixelConfig; void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { - GrVkGpu* gpu = static_cast(context->getGpu()); + GrVkGpu* gpu = static_cast(context->contextPriv().getGpu()); GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig, false, @@ -75,7 +76,7 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { } void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) { - GrVkGpu* gpu = static_cast(context->getGpu()); + GrVkGpu* gpu = static_cast(context->contextPriv().getGpu()); GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig, true, @@ -112,7 +113,7 @@ void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) { } void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { - GrVkGpu* gpu = static_cast(context->getGpu()); + GrVkGpu* gpu = static_cast(context->contextPriv().getGpu()); GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig, true, diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp index a41e8f4071..a16752f229 100644 --- a/tests/WritePixelsTest.cpp +++ b/tests/WritePixelsTest.cpp @@ -427,10 +427,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WritePixels_Gpu, reporter, ctxInfo) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WritePixelsNonTexture_Gpu, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); + GrGpu* gpu = context->contextPriv().getGpu(); for (auto& origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) { for (int sampleCnt : {0, 4}) { - GrBackendTexture backendTex = context->getGpu()->createTestingOnlyBackendTexture( + GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( nullptr, DEV_W, DEV_H, kSkia8888_GrPixelConfig, true, GrMipMapped::kNo); SkColorType colorType; if (kRGBA_8888_GrPixelConfig == kSkia8888_GrPixelConfig) { @@ -441,14 +442,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WritePixelsNonTexture_Gpu, reporter, ctxInfo) sk_sp surface(SkSurface::MakeFromBackendTextureAsRenderTarget( context, backendTex, origin, sampleCnt, colorType, nullptr, nullptr)); if (!surface) { - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); continue; } test_write_pixels(reporter, surface.get()); surface.reset(); - context->getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + gpu->deleteTestingOnlyBackendTexture(&backendTex); } } } diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp index f511574726..25c5a602f9 100644 --- a/tools/gpu/GrTest.cpp +++ b/tools/gpu/GrTest.cpp @@ -148,7 +148,7 @@ void GrContext::printGpuStats() const { } sk_sp GrContext::getFontAtlasImage_ForTesting(GrMaskFormat format) { - GrAtlasGlyphCache* cache = this->getAtlasGlyphCache(); + GrAtlasGlyphCache* cache = this->contextPriv().getAtlasGlyphCache(); const sk_sp* proxies = cache->getProxies(format); if (!proxies[0]) { -- cgit v1.2.3