2013-08-21 19:27:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
|
|
|
#include "include/gpu/GrContextOptions.h"
|
|
|
|
#include "include/private/GrRecordingContext.h"
|
|
|
|
#include "include/private/SkTo.h"
|
|
|
|
#include "src/core/SkMathPriv.h"
|
|
|
|
#include "src/gpu/GrClip.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/GrDrawOpAtlas.h"
|
|
|
|
#include "src/gpu/GrDrawingManager.h"
|
|
|
|
#include "src/gpu/GrGpu.h"
|
|
|
|
#include "src/gpu/GrGpuResourceCacheAccess.h"
|
|
|
|
#include "src/gpu/GrMemoryPool.h"
|
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
|
|
|
#include "src/gpu/GrRenderTargetContext.h"
|
|
|
|
#include "src/gpu/GrRenderTargetContextPriv.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrRenderTargetProxy.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrResourceCache.h"
|
|
|
|
#include "src/gpu/GrSemaphore.h"
|
|
|
|
#include "src/gpu/GrSurfaceContextPriv.h"
|
2020-03-05 19:14:18 +00:00
|
|
|
#include "src/gpu/GrTexture.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/SkGr.h"
|
|
|
|
#include "src/gpu/ccpr/GrCCPathCache.h"
|
|
|
|
#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
|
|
|
|
#include "src/gpu/ops/GrMeshDrawOp.h"
|
|
|
|
#include "src/gpu/text/GrStrikeCache.h"
|
|
|
|
#include "src/gpu/text/GrTextBlobCache.h"
|
|
|
|
#include "src/image/SkImage_Gpu.h"
|
2018-09-19 15:31:27 +00:00
|
|
|
|
2018-06-13 13:59:02 +00:00
|
|
|
#include <algorithm>
|
2015-12-11 14:11:21 +00:00
|
|
|
|
2015-02-19 19:38:44 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
|
2015-02-03 02:26:03 +00:00
|
|
|
|
2017-01-06 17:04:19 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
int GrResourceCache::countUniqueKeysWithTag(const char* tag) const {
|
|
|
|
int count = 0;
|
2020-03-14 21:22:45 +00:00
|
|
|
fUniqueHash.foreach([&](const GrGpuResource& resource){
|
|
|
|
if (0 == strcmp(tag, resource.getUniqueKey().tag())) {
|
2017-01-06 17:04:19 +00:00
|
|
|
++count;
|
|
|
|
}
|
2020-03-14 21:22:45 +00:00
|
|
|
});
|
2017-01-06 17:04:19 +00:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-13 15:47:38 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#define ASSERT_SINGLE_OWNER \
|
2017-04-10 12:19:26 +00:00
|
|
|
SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());)
|
2016-01-13 15:47:38 +00:00
|
|
|
|
2017-11-30 05:01:06 +00:00
|
|
|
|
2019-08-22 20:19:24 +00:00
|
|
|
uint32_t GrRenderTargetContextPriv::testingOnly_getOpsTaskID() {
|
|
|
|
return fRenderTargetContext->getOpsTask()->uniqueID();
|
2017-12-05 17:05:21 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 14:42:18 +00:00
|
|
|
void GrRenderTargetContextPriv::testingOnly_addDrawOp(std::unique_ptr<GrDrawOp> op) {
|
2020-05-29 12:55:06 +00:00
|
|
|
this->testingOnly_addDrawOp(GrNoClip(), std::move(op));
|
2017-11-30 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 14:42:18 +00:00
|
|
|
void GrRenderTargetContextPriv::testingOnly_addDrawOp(
|
2020-05-29 12:55:06 +00:00
|
|
|
const GrClip& clip,
|
2018-10-31 14:42:18 +00:00
|
|
|
std::unique_ptr<GrDrawOp> op,
|
|
|
|
const std::function<GrRenderTargetContext::WillAddOpFn>& willAddFn) {
|
2017-05-08 14:43:33 +00:00
|
|
|
ASSERT_SINGLE_OWNER
|
2019-02-15 20:19:15 +00:00
|
|
|
if (fRenderTargetContext->fContext->priv().abandoned()) {
|
2019-02-04 18:26:26 +00:00
|
|
|
fRenderTargetContext->fContext->priv().opMemoryPool()->release(std::move(op));
|
2018-10-31 14:42:18 +00:00
|
|
|
return;
|
2017-05-08 14:43:33 +00:00
|
|
|
}
|
|
|
|
SkDEBUGCODE(fRenderTargetContext->validate());
|
2019-03-04 16:08:13 +00:00
|
|
|
GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->auditTrail(),
|
2017-05-08 14:43:33 +00:00
|
|
|
"GrRenderTargetContext::testingOnly_addDrawOp");
|
2018-10-31 14:42:18 +00:00
|
|
|
fRenderTargetContext->addDrawOp(clip, std::move(op), willAddFn);
|
2017-05-08 14:43:33 +00:00
|
|
|
}
|
|
|
|
|
2016-01-13 15:47:38 +00:00
|
|
|
#undef ASSERT_SINGLE_OWNER
|
|
|
|
|
2017-05-12 18:09:46 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-06-24 19:08:57 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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;
|
2018-06-18 15:51:36 +00:00
|
|
|
}
|
|
|
|
|
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; }
|
|
|
|
|
2018-06-18 15:51:36 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-05-12 18:09:46 +00:00
|
|
|
#define DRAW_OP_TEST_EXTERN(Op) \
|
2019-02-12 20:24:12 +00:00
|
|
|
extern std::unique_ptr<GrDrawOp> Op##__Test(GrPaint&&, SkRandom*, \
|
2019-06-24 00:07:38 +00:00
|
|
|
GrRecordingContext*, int numSamples)
|
2017-05-12 18:09:46 +00:00
|
|
|
#define DRAW_OP_TEST_ENTRY(Op) Op##__Test
|
|
|
|
|
2017-06-15 20:21:49 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(AAConvexPathOp);
|
2017-07-13 20:42:55 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp);
|
2017-07-07 17:29:28 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(AAHairlineOp);
|
2017-06-15 13:59:23 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(AAStrokeRectOp);
|
2017-07-11 12:52:13 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(CircleOp);
|
2017-07-12 19:27:54 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(DashOp);
|
2017-07-13 20:40:46 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(DefaultPathOp);
|
2017-05-15 20:45:49 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(DIEllipseOp);
|
|
|
|
DRAW_OP_TEST_EXTERN(EllipseOp);
|
2018-11-28 20:34:34 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(FillRectOp);
|
2017-07-18 23:59:24 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(GrAtlasTextOp);
|
2019-03-24 00:53:23 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(DrawAtlasOp);
|
2019-02-11 19:29:34 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(DrawVerticesOp);
|
2017-07-11 12:52:13 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(NonAALatticeOp);
|
2017-06-15 13:59:23 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
|
2017-07-13 15:20:51 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(ShadowRRectOp);
|
2017-07-11 19:52:02 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(SmallPathOp);
|
2017-07-11 19:53:05 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(RegionOp);
|
2017-05-15 20:45:49 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(RRectOp);
|
2020-03-25 22:18:16 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(TriangulatingPathOp);
|
2017-08-28 19:32:01 +00:00
|
|
|
DRAW_OP_TEST_EXTERN(TextureOp);
|
2017-05-12 18:09:46 +00:00
|
|
|
|
|
|
|
void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) {
|
2019-02-22 16:16:30 +00:00
|
|
|
auto context = renderTargetContext->surfPriv().getContext();
|
2019-02-12 20:24:12 +00:00
|
|
|
using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*,
|
2019-06-24 00:07:38 +00:00
|
|
|
GrRecordingContext*, int numSamples);
|
2017-05-12 18:09:46 +00:00
|
|
|
static constexpr MakeDrawOpFn* gFactories[] = {
|
2017-08-28 19:32:01 +00:00
|
|
|
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),
|
2018-11-28 20:34:34 +00:00
|
|
|
DRAW_OP_TEST_ENTRY(FillRectOp),
|
2017-08-28 19:32:01 +00:00
|
|
|
DRAW_OP_TEST_ENTRY(GrAtlasTextOp),
|
2019-03-24 00:53:23 +00:00
|
|
|
DRAW_OP_TEST_ENTRY(DrawAtlasOp),
|
2019-02-11 19:29:34 +00:00
|
|
|
DRAW_OP_TEST_ENTRY(DrawVerticesOp),
|
2017-08-28 19:32:01 +00:00
|
|
|
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),
|
2020-03-25 22:18:16 +00:00
|
|
|
DRAW_OP_TEST_ENTRY(TriangulatingPathOp),
|
2017-08-28 19:32:01 +00:00
|
|
|
DRAW_OP_TEST_ENTRY(TextureOp),
|
2017-05-12 18:09:46 +00:00
|
|
|
};
|
|
|
|
|
2017-07-14 19:27:56 +00:00
|
|
|
static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories);
|
2017-05-12 18:09:46 +00:00
|
|
|
uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
|
2017-07-14 19:27:56 +00:00
|
|
|
auto op = gFactories[index](
|
2019-06-24 00:07:38 +00:00
|
|
|
std::move(paint), random, context, renderTargetContext->numSamples());
|
2017-07-14 19:27:56 +00:00
|
|
|
SkASSERT(op);
|
|
|
|
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
|
2017-05-12 18:09:46 +00:00
|
|
|
}
|