skia2/tools/gpu/GrTest.cpp

225 lines
7.7 KiB
C++
Raw Normal View History

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
Revert "Revert "Plumb GrBackendTexture throughout skia."" This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6. Reason for revert: Relanding this change now that other fixes have landed. Original change's description: > Revert "Plumb GrBackendTexture throughout skia." > > This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12. > > Reason for revert: fix android roll > > Original change's description: > > Plumb GrBackendTexture throughout skia. > > > > Bug: skia: > > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875 > > Reviewed-on: https://skia-review.googlesource.com/13645 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > > Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89 > Reviewed-on: https://skia-review.googlesource.com/13773 > Reviewed-by: Stan Iliev <stani@google.com> > Commit-Queue: Stan Iliev <stani@google.com> > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2 Reviewed-on: https://skia-review.googlesource.com/13975 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
#include "GrBackendSurface.h"
#include "GrClip.h"
#include "GrContextOptions.h"
#include "GrContextPriv.h"
#include "GrDrawOpAtlas.h"
#include "GrDrawingManager.h"
#include "GrGpu.h"
#include "GrGpuResourceCacheAccess.h"
#include "GrMemoryPool.h"
#include "GrRenderTargetContext.h"
#include "GrRenderTargetContextPriv.h"
#include "GrRenderTargetProxy.h"
#include "GrResourceCache.h"
#include "GrSemaphore.h"
#include "GrSurfaceContextPriv.h"
#include "GrTexture.h"
#include "SkGr.h"
#include "SkImage_Gpu.h"
#include "SkMathPriv.h"
#include "SkString.h"
#include "SkTo.h"
#include "ccpr/GrCoverageCountingPathRenderer.h"
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
#include "ccpr/GrCCPathCache.h"
#include "ops/GrMeshDrawOp.h"
#include "text/GrStrikeCache.h"
#include "text/GrTextBlobCache.h"
#include <algorithm>
Revert "Revert "Add GrRenderTargetContext instantiate & asTextureProxy"" This reverts commit 7d7d7d19462b75f5470492dc4820a02c1eba4af2. Reason for revert: Reverting this to see if it really was crashing on SVGs or if that was cross talk. Original change's description: > Revert "Add GrRenderTargetContext instantiate & asTextureProxy" > > This reverts commit 9113edfff89e657dabc0ba095c54f7720550196c. > > Reason for revert: Looks to be causing EXCEPTION_ACCESS_VIOLATION: > > https://uberchromegw.corp.google.com/i/client.skia/builders/Test-Win-MSVC-NUC-GPU-IntelIris6100-x86_64-Debug/builds/121/steps/test_skia%20on%20Windows/logs/stdio > https://uberchromegw.corp.google.com/i/client.skia/builders/Test-Win-MSVC-GCE-CPU-AVX2-x86-Debug/builds/2384/steps/test_skia%20on%20Windows-2008ServerR2-SP1/logs/stdio > https://uberchromegw.corp.google.com/i/client.skia/builders/Test-Win-MSVC-ShuttleC-GPU-iHD530-x86_64-Debug/builds/785/steps/test_skia%20on%20Windows/logs/stdio > > Original change's description: > > Add GrRenderTargetContext instantiate & asTextureProxy > > > > This CL also centralizes the instantiation code in GrSurfaceProxy and adds a test. > > > > GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4494 > > > > Change-Id: I0081d9a216dc0af293179f23bcb88acf6a822324 > > Reviewed-on: https://skia-review.googlesource.com/4494 > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Robert Phillips <robertphillips@google.com> > > > > TBR=bsalomon@google.com,robertphillips@google.com,reviews@skia.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > > Change-Id: I225ce7867ebd445067e5ea55ebbfd587f7fe782a > Reviewed-on: https://skia-review.googlesource.com/4528 > Commit-Queue: Leon Scroggins <scroggo@google.com> > Reviewed-by: Leon Scroggins <scroggo@google.com> > TBR=bsalomon@google.com,robertphillips@google.com,scroggo@google.com,reviews@skia.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Change-Id: Ifc3b9ac343009a3808f5f47500eef50df438e3d9 Reviewed-on: https://skia-review.googlesource.com/4537 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2016-11-08 13:49:39 +00:00
bool GrSurfaceProxy::isWrapped_ForTesting() const {
return SkToBool(fTarget);
}
bool GrRenderTargetContext::isWrapped_ForTesting() const {
return fRenderTargetProxy->isWrapped_ForTesting();
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
#ifdef SK_DEBUG
int GrResourceCache::countUniqueKeysWithTag(const char* tag) const {
int count = 0;
UniqueHash::ConstIter iter(&fUniqueHash);
while (!iter.done()) {
if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) {
++count;
}
++iter;
}
return count;
}
#endif
///////////////////////////////////////////////////////////////////////////////
#define ASSERT_SINGLE_OWNER \
SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());)
uint32_t GrRenderTargetContextPriv::testingOnly_getOpListID() {
return fRenderTargetContext->getOpList()->uniqueID();
}
void GrRenderTargetContextPriv::testingOnly_addDrawOp(std::unique_ptr<GrDrawOp> op) {
this->testingOnly_addDrawOp(GrNoClip(), std::move(op));
}
void GrRenderTargetContextPriv::testingOnly_addDrawOp(
const GrClip& clip,
std::unique_ptr<GrDrawOp> op,
const std::function<GrRenderTargetContext::WillAddOpFn>& willAddFn) {
ASSERT_SINGLE_OWNER
if (fRenderTargetContext->fContext->abandoned()) {
fRenderTargetContext->fContext->priv().opMemoryPool()->release(std::move(op));
return;
}
SkDEBUGCODE(fRenderTargetContext->validate());
GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail,
"GrRenderTargetContext::testingOnly_addDrawOp");
fRenderTargetContext->addDrawOp(clip, std::move(op), willAddFn);
}
#undef ASSERT_SINGLE_OWNER
///////////////////////////////////////////////////////////////////////////////
GrInternalSurfaceFlags GrSurfaceProxy::testingOnly_getFlags() const {
return fSurfaceFlags;
}
//////////////////////////////////////////////////////////////////////////////
void GrCoverageCountingPathRenderer::testingOnly_drawPathDirectly(const DrawPathArgs& args) {
// Call onDrawPath() directly: We want to test paths that might fail onCanDrawPath() simply for
// performance reasons, and GrPathRenderer::drawPath() assert that this call returns true.
// The test is responsible to not draw any paths that CCPR is not actually capable of.
this->onDrawPath(args);
}
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
const GrCCPerFlushResources*
GrCoverageCountingPathRenderer::testingOnly_getCurrentFlushResources() {
SkASSERT(fFlushing);
if (fFlushingPaths.empty()) {
return nullptr;
}
// All pending paths should share the same resources.
const GrCCPerFlushResources* resources = fFlushingPaths.front()->fFlushResources.get();
#ifdef SK_DEBUG
for (const auto& flushingPaths : fFlushingPaths) {
SkASSERT(flushingPaths->fFlushResources.get() == resources);
}
#endif
return resources;
}
const GrCCPathCache* GrCoverageCountingPathRenderer::testingOnly_getPathCache() const {
return fPathCache.get();
}
const GrTexture* GrCCPerFlushResources::testingOnly_frontCopyAtlasTexture() const {
if (fCopyAtlasStack.empty()) {
return nullptr;
}
const GrTextureProxy* proxy = fCopyAtlasStack.front().textureProxy();
return (proxy) ? proxy->peekTexture() : nullptr;
}
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
const GrTexture* GrCCPerFlushResources::testingOnly_frontRenderedAtlasTexture() const {
if (fRenderedAtlasStack.empty()) {
return nullptr;
}
const GrTextureProxy* proxy = fRenderedAtlasStack.front().textureProxy();
return (proxy) ? proxy->peekTexture() : nullptr;
}
const SkTHashTable<GrCCPathCache::HashNode, const GrCCPathCache::Key&>&
GrCCPathCache::testingOnly_getHashTable() const {
return fHashTable;
}
const SkTInternalLList<GrCCPathCacheEntry>& GrCCPathCache::testingOnly_getLRU() const {
return fLRU;
}
int GrCCPathCacheEntry::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; }
int GrCCCachedAtlas::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; }
//////////////////////////////////////////////////////////////////////////////
#define DRAW_OP_TEST_EXTERN(Op) \
extern std::unique_ptr<GrDrawOp> Op##__Test(GrPaint&&, SkRandom*, \
GrRecordingContext*, GrFSAAType)
#define DRAW_OP_TEST_ENTRY(Op) Op##__Test
DRAW_OP_TEST_EXTERN(AAConvexPathOp);
DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp);
DRAW_OP_TEST_EXTERN(AAHairlineOp);
DRAW_OP_TEST_EXTERN(AAStrokeRectOp);
DRAW_OP_TEST_EXTERN(CircleOp);
DRAW_OP_TEST_EXTERN(DashOp);
DRAW_OP_TEST_EXTERN(DefaultPathOp);
DRAW_OP_TEST_EXTERN(DIEllipseOp);
DRAW_OP_TEST_EXTERN(EllipseOp);
DRAW_OP_TEST_EXTERN(FillRectOp);
DRAW_OP_TEST_EXTERN(GrAtlasTextOp);
DRAW_OP_TEST_EXTERN(DrawAtlasOp);
DRAW_OP_TEST_EXTERN(DrawVerticesOp);
DRAW_OP_TEST_EXTERN(NonAALatticeOp);
DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
DRAW_OP_TEST_EXTERN(ShadowRRectOp);
DRAW_OP_TEST_EXTERN(SmallPathOp);
DRAW_OP_TEST_EXTERN(RegionOp);
DRAW_OP_TEST_EXTERN(RRectOp);
DRAW_OP_TEST_EXTERN(TesselatingPathOp);
DRAW_OP_TEST_EXTERN(TextureOp);
void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) {
GrContext* context = renderTargetContext->surfPriv().getContext();
using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*,
GrRecordingContext*, GrFSAAType);
static constexpr MakeDrawOpFn* gFactories[] = {
DRAW_OP_TEST_ENTRY(AAConvexPathOp),
DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp),
DRAW_OP_TEST_ENTRY(AAHairlineOp),
DRAW_OP_TEST_ENTRY(AAStrokeRectOp),
DRAW_OP_TEST_ENTRY(CircleOp),
DRAW_OP_TEST_ENTRY(DashOp),
DRAW_OP_TEST_ENTRY(DefaultPathOp),
DRAW_OP_TEST_ENTRY(DIEllipseOp),
DRAW_OP_TEST_ENTRY(EllipseOp),
DRAW_OP_TEST_ENTRY(FillRectOp),
DRAW_OP_TEST_ENTRY(GrAtlasTextOp),
DRAW_OP_TEST_ENTRY(DrawAtlasOp),
DRAW_OP_TEST_ENTRY(DrawVerticesOp),
DRAW_OP_TEST_ENTRY(NonAALatticeOp),
DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
DRAW_OP_TEST_ENTRY(ShadowRRectOp),
DRAW_OP_TEST_ENTRY(SmallPathOp),
DRAW_OP_TEST_ENTRY(RegionOp),
DRAW_OP_TEST_ENTRY(RRectOp),
DRAW_OP_TEST_ENTRY(TesselatingPathOp),
DRAW_OP_TEST_ENTRY(TextureOp),
};
static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories);
uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
auto op = gFactories[index](
std::move(paint), random, context, renderTargetContext->fsaaType());
SkASSERT(op);
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
}