Add additional GrThreadSafeCache test case

and flush out some non-substantive changes; namely:
  whitespace changes
  tweak what is stored in TessInfo
  change createMesh to be CreateMesh

Bug: 1108408
Change-Id: Ife9a0e500b9f51db597350b0257b20efece03bdc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/329633
Reviewed-by: Adlai Holler <adlai@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2020-10-26 13:50:57 -04:00 committed by Skia Commit-Bot
parent c76d4096af
commit 3ac83b2f91
4 changed files with 73 additions and 19 deletions

View File

@ -1459,10 +1459,10 @@ template <MinMaxOrBoth MIN_MAX_OR_BOTH> bool get_scale_factor(SkMatrix::TypeMask
if (!(typeMask & SkMatrix::kAffine_Mask)) {
if (kMin_MinMaxOrBoth == MIN_MAX_OR_BOTH) {
results[0] = std::min(SkScalarAbs(m[SkMatrix::kMScaleX]),
SkScalarAbs(m[SkMatrix::kMScaleY]));
SkScalarAbs(m[SkMatrix::kMScaleY]));
} else if (kMax_MinMaxOrBoth == MIN_MAX_OR_BOTH) {
results[0] = std::max(SkScalarAbs(m[SkMatrix::kMScaleX]),
SkScalarAbs(m[SkMatrix::kMScaleY]));
SkScalarAbs(m[SkMatrix::kMScaleY]));
} else {
results[0] = SkScalarAbs(m[SkMatrix::kMScaleX]);
results[1] = SkScalarAbs(m[SkMatrix::kMScaleY]);

View File

@ -36,7 +36,8 @@ public:
class GrEagerDynamicVertexAllocator : public GrEagerVertexAllocator {
public:
GrEagerDynamicVertexAllocator(GrMeshDrawOp::Target* target,
sk_sp<const GrBuffer>* vertexBuffer, int* baseVertex)
sk_sp<const GrBuffer>* vertexBuffer,
int* baseVertex)
: fTarget(target)
, fVertexBuffer(vertexBuffer)
, fBaseVertex(baseVertex) {

View File

@ -16,11 +16,13 @@
#include "src/gpu/GrEagerVertexAllocator.h"
#include "src/gpu/GrOpFlushState.h"
#include "src/gpu/GrProgramInfo.h"
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrResourceCache.h"
#include "src/gpu/GrResourceProvider.h"
#include "src/gpu/GrSimpleMesh.h"
#include "src/gpu/GrStyle.h"
#include "src/gpu/GrThreadSafeCache.h"
#include "src/gpu/GrTriangulator.h"
#include "src/gpu/geometry/GrPathUtils.h"
#include "src/gpu/geometry/GrStyledShape.h"
@ -40,24 +42,35 @@
*/
namespace {
// The TessInfo struct contains ancillary data not specifically required for the triangle
// data (which is stored in a GrThreadSafeCache::VertexData object).
// The 'fNumVertices' field is a temporary exception. It is still needed to support the
// AA triangulated path case - which doesn't use the GrThreadSafeCache nor the VertexData object).
// When there is an associated VertexData, its numVertices should always match the TessInfo's
// value.
struct TessInfo {
int fNumVertices;
int fNumCountedCurves;
SkScalar fTolerance;
int fCount;
};
static sk_sp<SkData> create_data(int vertexCount, int numCountedCurves, SkScalar tol) {
TessInfo info;
info.fTolerance = (numCountedCurves == 0) ? 0 : tol;
info.fCount = vertexCount;
static sk_sp<SkData> create_data(int numVertices, int numCountedCurves, SkScalar tol) {
TessInfo info { numVertices, numCountedCurves, tol };
return SkData::MakeWithCopy(&info, sizeof(info));
}
bool cache_match(const SkData* data, SkScalar tol, int* actualCount) {
bool cache_match(const SkData* data, SkScalar tol,
int* actualNumVertices, int* actualNumCountedCurves) {
SkASSERT(data);
const TessInfo* info = static_cast<const TessInfo*>(data->data());
if (info->fTolerance == 0 || info->fTolerance < 3.0f * tol) {
*actualCount = info->fCount;
if (info->fNumCountedCurves == 0 || info->fTolerance < 3.0f * tol) {
if (actualNumVertices) {
*actualNumVertices = info->fNumVertices;
}
if (actualNumCountedCurves) {
*actualNumCountedCurves = info->fNumCountedCurves;
}
return true;
}
return false;
@ -128,6 +141,7 @@ private:
} // namespace
GrTriangulatingPathRenderer::GrTriangulatingPathRenderer()
: fMaxVerbCount(GR_AA_TESSELLATOR_MAX_VERB_COUNT) {
}
@ -298,11 +312,11 @@ private:
sk_sp<GrGpuBuffer> cachedVertexBuffer(rp->findByUniqueKey<GrGpuBuffer>(key));
if (cachedVertexBuffer) {
int actualCount;
int actualVertexCount;
if (cache_match(cachedVertexBuffer->getUniqueKey().getCustomData(), tol,
&actualCount)) {
this->createMesh(target, std::move(cachedVertexBuffer), 0, actualCount);
&actualVertexCount, nullptr)) {
fMesh = CreateMesh(target, std::move(cachedVertexBuffer), 0, actualVertexCount);
return;
}
}
@ -325,7 +339,7 @@ private:
sk_make_sp<UniqueKeyInvalidator>(key, target->contextUniqueID()));
rp->assignUniqueKeyToResource(key, vb.get());
this->createMesh(target, std::move(vb), 0, vertexCount);
fMesh = CreateMesh(target, std::move(vb), 0, vertexCount);
}
void createAAMesh(Target* target) {
@ -347,7 +361,7 @@ private:
if (vertexCount == 0) {
return;
}
this->createMesh(target, std::move(vertexBuffer), firstVertex, vertexCount);
fMesh = CreateMesh(target, std::move(vertexBuffer), firstVertex, vertexCount);
}
GrProgramInfo* programInfo() override { return fProgramInfo; }
@ -422,9 +436,11 @@ private:
}
}
void createMesh(Target* target, sk_sp<const GrBuffer> vb, int firstVertex, int count) {
fMesh = target->allocMesh();
fMesh->set(std::move(vb), count, firstVertex);
static GrSimpleMesh* CreateMesh(Target* target, sk_sp<const GrBuffer> vb,
int firstVertex, int count) {
auto mesh = target->allocMesh();
mesh->set(std::move(vb), count, firstVertex);
return mesh;
}
void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {

View File

@ -9,6 +9,7 @@
#include "include/core/SkDeferredDisplayListRecorder.h"
#include "include/core/SkSurfaceCharacterization.h"
#include "include/private/SkMalloc.h"
#include "include/utils/SkRandom.h"
#include "src/gpu/GrDefaultGeoProcFactory.h"
#include "src/gpu/GrDirectContextPriv.h"
#include "src/gpu/GrGpu.h"
@ -1335,3 +1336,39 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache13View, reporter, ctxInfo) {
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache13Verts, reporter, ctxInfo) {
test_13(ctxInfo.directContext(), reporter, &TestHelper::addVertAccess, &TestHelper::checkVert);
}
// Case 14: Test out mixing & matching view & vertex data w/ recycling of the cache entries to
// wring out the anonymous union code. This is mainly for the MSAN bot's consumption.
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache14, reporter, ctxInfo) {
constexpr int kBestPrimeNumber = 73; // palindromic in binary
SkRandom rand(kBestPrimeNumber);
TestHelper helper(ctxInfo.directContext());
for (int i = 0; i < 2; ++i) {
SkCanvas* ddlCanvas = (!i) ? helper.ddlCanvas1() : helper.ddlCanvas2();
for (int j = 0; j < 10; ++j) {
int numResources = 10*i + j + 1;
int wh = numResources;
if (rand.nextBool()) {
helper.addViewAccess(ddlCanvas, wh, kNoID, false, false);
REPORTER_ASSERT(reporter, helper.checkView(ddlCanvas, wh,
/*hits*/ 0, /*misses*/ numResources,
/*refs*/ 1, kNoID));
} else {
helper.addVertAccess(ddlCanvas, wh, kNoID, false, false);
REPORTER_ASSERT(reporter, helper.checkVert(ddlCanvas, wh,
/*hits*/ 0, /*misses*/ numResources,
/*refs*/ 1, kNoID));
}
}
if (!i) {
// Drop all the accumulated resources from the thread-safe cache
helper.snap1();
ctxInfo.directContext()->purgeUnlockedResources(/* scratchResourcesOnly */ false);
}
}
}