2017-03-21 11:56:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 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 "tests/Test.h"
|
|
|
|
|
2019-05-29 13:51:09 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrBackendSemaphore.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-05-29 13:51:09 +00:00
|
|
|
#include "src/core/SkPointPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrDefaultGeoProcFactory.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-09-30 16:15:30 +00:00
|
|
|
#include "src/gpu/GrImageInfo.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrOnFlushResourceProvider.h"
|
2020-03-04 21:12:08 +00:00
|
|
|
#include "src/gpu/GrProgramInfo.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
|
|
|
#include "src/gpu/GrRenderTargetContextPriv.h"
|
|
|
|
#include "src/gpu/GrResourceProvider.h"
|
2020-03-05 19:14:18 +00:00
|
|
|
#include "src/gpu/GrTexture.h"
|
2020-01-07 16:15:44 +00:00
|
|
|
#include "src/gpu/effects/GrTextureEffect.h"
|
2019-05-29 13:51:09 +00:00
|
|
|
#include "src/gpu/geometry/GrQuad.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
|
2019-10-24 14:37:08 +00:00
|
|
|
#include "tests/TestUtils.h"
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2017-07-13 21:04:43 +00:00
|
|
|
namespace {
|
2017-03-21 11:56:47 +00:00
|
|
|
// This is a simplified mesh drawing op that can be used in the atlas generation test.
|
|
|
|
// Please see AtlasedRectOp below.
|
2017-07-13 21:04:43 +00:00
|
|
|
class NonAARectOp : public GrMeshDrawOp {
|
|
|
|
protected:
|
|
|
|
using Helper = GrSimpleMeshDrawOpHelper;
|
|
|
|
|
2017-03-21 11:56:47 +00:00
|
|
|
public:
|
|
|
|
DEFINE_OP_CLASS_ID
|
|
|
|
|
|
|
|
// This creates an instance of a simple non-AA solid color rect-drawing Op
|
2020-10-07 20:46:15 +00:00
|
|
|
static GrOp::Owner Make(GrRecordingContext* context,
|
|
|
|
GrPaint&& paint,
|
|
|
|
const SkRect& r) {
|
2018-06-12 14:11:12 +00:00
|
|
|
return Helper::FactoryHelper<NonAARectOp>(context, std::move(paint), r, nullptr, ClassID());
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This creates an instance of a simple non-AA textured rect-drawing Op
|
2020-10-07 20:46:15 +00:00
|
|
|
static GrOp::Owner Make(GrRecordingContext* context,
|
|
|
|
GrPaint&& paint,
|
|
|
|
const SkRect& r,
|
|
|
|
const SkRect& local) {
|
2018-06-12 14:11:12 +00:00
|
|
|
return Helper::FactoryHelper<NonAARectOp>(context, std::move(paint), r, &local, ClassID());
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 18:04:39 +00:00
|
|
|
const SkPMColor4f& color() const { return fColor; }
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2020-10-07 20:46:15 +00:00
|
|
|
NonAARectOp(GrProcessorSet* processorSet, const SkPMColor4f& color, const SkRect& r,
|
2017-07-13 21:04:43 +00:00
|
|
|
const SkRect* localRect, int32_t classID)
|
|
|
|
: INHERITED(classID)
|
|
|
|
, fColor(color)
|
|
|
|
, fHasLocalRect(SkToBool(localRect))
|
|
|
|
, fRect(r)
|
2020-10-07 20:46:15 +00:00
|
|
|
, fHelper(processorSet, GrAAType::kNone) {
|
2017-07-13 21:04:43 +00:00
|
|
|
if (fHasLocalRect) {
|
2018-05-17 14:42:14 +00:00
|
|
|
fLocalQuad = GrQuad(*localRect);
|
2017-07-13 21:04:43 +00:00
|
|
|
}
|
2017-03-21 11:56:47 +00:00
|
|
|
// Choose some conservative values for aa bloat and zero area.
|
2019-10-01 19:14:44 +00:00
|
|
|
this->setBounds(r, HasAABloat::kYes, IsHairline::kYes);
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 17:10:52 +00:00
|
|
|
const char* name() const override { return "NonAARectOp"; }
|
|
|
|
|
2019-05-22 01:35:29 +00:00
|
|
|
void visitProxies(const VisitProxyFunc& func) const override {
|
2020-03-04 21:12:08 +00:00
|
|
|
if (fProgramInfo) {
|
2020-03-17 00:05:03 +00:00
|
|
|
fProgramInfo->visitFPProxies(func);
|
2020-03-04 21:12:08 +00:00
|
|
|
} else {
|
|
|
|
fHelper.visitProxies(func);
|
|
|
|
}
|
2017-09-13 17:10:52 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 21:04:43 +00:00
|
|
|
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
|
|
|
|
|
2019-06-24 00:07:38 +00:00
|
|
|
GrProcessorSet::Analysis finalize(
|
|
|
|
const GrCaps& caps, const GrAppliedClip*, bool hasMixedSampledCoverage,
|
|
|
|
GrClampType clampType) override {
|
2017-07-13 21:04:43 +00:00
|
|
|
// Set the color to unknown because the subclass may change the color later.
|
|
|
|
GrProcessorAnalysisColor gpColor;
|
|
|
|
gpColor.setToUnknown();
|
|
|
|
// We ignore the clip so pass this rather than the GrAppliedClip param.
|
Reland "Improve scissor state tracking in GrRTC"
This reverts commit 4926b07217f07e8f5ff1dba15d23bab960ffded3.
Reason for revert: fix wip
Original change's description:
> Revert "Improve scissor state tracking in GrRTC"
>
> This reverts commit 3b923a880bc0855772daffd95b5728795f515d5f.
>
> Reason for revert: GrAppliedHardClip isn't tracking scissor state properly
>
> Original change's description:
> > Improve scissor state tracking in GrRTC
> >
> > At a low level, this changes GrScissorState from a rect+bool to a rect+size.
> > The scissor test is considered enablebd if the rect does not fill the
> > device bounds rect specified by the size. This has a number of benefits:
> >
> > 1. We can always access the scissor rect and know that it will be
> > restricted to the render target dimensions.
> > 2. It helps consolidate code that previously had to test the scissor rect
> > and render target bounds separately.
> > 3. The clear operations can now match the proper backing store dimensions
> > of the render target.
> > 4. It makes it easier to reason about scissors applying to the logical
> > dimensions of the render target vs. its backing store dimensions.
> >
> > Originally, I was going to have the extra scissor guards for the logical
> > dimensions be added in a separate CL (with the cleanup for
> > attemptQuadOptimization). However, it became difficult to ensure correct
> > behavior respecting the vulkan render pass bounds without applying this
> > new logic at the same time.
> >
> > So now, with this CL, GrAppliedClips are sized to the backing store
> > dimensions of the render target. GrOpsTasks also clip bounds to the
> > backing store dimensions instead of the logical dimensions (which seems
> > more correct since that's where the auto-clipping happens). Then when
> > we convert a GrClip to a GrAppliedClip, the GrRTC automatically enforces
> > the logical dimensions scissor if we have stencil settings (to ensure
> > the padded pixels don't get corrupted). It also may remove the scissor
> > if the draw was just a color buffer update.
> >
> > Change-Id: I75671c9cc921f4696b1dd5231e02486090aa4282
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290654
> > Commit-Queue: Michael Ludwig <michaelludwig@google.com>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
>
> TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com
>
> Change-Id: Ie98d084158e3a537604ab0fecee69bde3e744d1b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294340
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com
# Not skipping CQ checks because this is a reland.
Change-Id: I2116e52146890ee4b7ea007f3c3d5c3e532e4bdd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294257
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-06-04 19:52:44 +00:00
|
|
|
static GrAppliedClip kNoClip = GrAppliedClip::Disabled();
|
2019-06-24 00:07:38 +00:00
|
|
|
return fHelper.finalizeProcessors(caps, &kNoClip, hasMixedSampledCoverage, clampType,
|
|
|
|
GrProcessorAnalysisCoverage::kNone, &gpColor);
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 21:04:43 +00:00
|
|
|
protected:
|
2018-10-31 18:04:39 +00:00
|
|
|
SkPMColor4f fColor;
|
|
|
|
bool fHasLocalRect;
|
|
|
|
GrQuad fLocalQuad;
|
|
|
|
SkRect fRect;
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
private:
|
2020-03-12 16:07:19 +00:00
|
|
|
GrProgramInfo* programInfo() override { return fProgramInfo; }
|
|
|
|
|
2020-03-11 19:55:55 +00:00
|
|
|
void onCreateProgramInfo(const GrCaps* caps,
|
|
|
|
SkArenaAlloc* arena,
|
2020-11-19 18:41:26 +00:00
|
|
|
const GrSurfaceProxyView& writeView,
|
2020-03-11 19:55:55 +00:00
|
|
|
GrAppliedClip&& appliedClip,
|
2020-09-11 13:33:54 +00:00
|
|
|
const GrXferProcessor::DstProxyView& dstProxyView,
|
2020-11-20 15:22:43 +00:00
|
|
|
GrXferBarrierFlags renderPassXferBarriers,
|
|
|
|
GrLoadOp colorLoadOp) override {
|
2017-03-21 11:56:47 +00:00
|
|
|
using namespace GrDefaultGeoProcFactory;
|
|
|
|
|
2019-11-20 21:08:10 +00:00
|
|
|
GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Make(
|
2020-03-04 21:12:08 +00:00
|
|
|
arena,
|
2018-07-17 14:19:38 +00:00
|
|
|
Color::kPremulGrColorAttribute_Type,
|
2017-03-21 11:56:47 +00:00
|
|
|
Coverage::kSolid_Type,
|
|
|
|
fHasLocalRect ? LocalCoords::kHasExplicit_Type
|
|
|
|
: LocalCoords::kUnused_Type,
|
|
|
|
SkMatrix::I());
|
|
|
|
if (!gp) {
|
2020-03-04 21:12:08 +00:00
|
|
|
SkDebugf("Couldn't create GrGeometryProcessor\n");
|
2020-03-11 19:55:55 +00:00
|
|
|
return;
|
2020-03-04 21:12:08 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 20:22:00 +00:00
|
|
|
fProgramInfo = fHelper.createProgramInfo(caps, arena, writeView, std::move(appliedClip),
|
2020-09-11 13:33:54 +00:00
|
|
|
dstProxyView, gp, GrPrimitiveType::kTriangles,
|
2020-11-20 15:22:43 +00:00
|
|
|
renderPassXferBarriers, colorLoadOp);
|
2020-03-04 21:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onPrepareDraws(Target* target) override {
|
|
|
|
|
|
|
|
// The vertex attrib order is always pos, color, local coords.
|
|
|
|
static const int kColorOffset = sizeof(SkPoint);
|
|
|
|
static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor);
|
|
|
|
|
|
|
|
if (!fProgramInfo) {
|
2020-03-11 19:55:55 +00:00
|
|
|
this->createProgramInfo(target);
|
2020-03-04 21:12:08 +00:00
|
|
|
if (!fProgramInfo) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 21:12:08 +00:00
|
|
|
size_t vertexStride = fProgramInfo->primProc().vertexStride();
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2019-01-29 19:38:50 +00:00
|
|
|
sk_sp<const GrBuffer> indexBuffer;
|
2017-03-21 11:56:47 +00:00
|
|
|
int firstIndex;
|
|
|
|
uint16_t* indices = target->makeIndexSpace(6, &indexBuffer, &firstIndex);
|
|
|
|
if (!indices) {
|
|
|
|
SkDebugf("Indices could not be allocated for GrAtlasedOp.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-29 19:38:50 +00:00
|
|
|
sk_sp<const GrBuffer> vertexBuffer;
|
2017-03-21 11:56:47 +00:00
|
|
|
int firstVertex;
|
|
|
|
void* vertices = target->makeVertexSpace(vertexStride, 4, &vertexBuffer, &firstVertex);
|
|
|
|
if (!vertices) {
|
|
|
|
SkDebugf("Vertices could not be allocated for GrAtlasedOp.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup indices
|
|
|
|
indices[0] = 0;
|
|
|
|
indices[1] = 1;
|
|
|
|
indices[2] = 2;
|
2017-10-18 12:21:05 +00:00
|
|
|
indices[3] = 2;
|
|
|
|
indices[4] = 1;
|
2017-03-21 11:56:47 +00:00
|
|
|
indices[5] = 3;
|
|
|
|
|
|
|
|
// Setup positions
|
|
|
|
SkPoint* position = (SkPoint*) vertices;
|
2018-05-18 16:52:22 +00:00
|
|
|
SkPointPriv::SetRectTriStrip(position, fRect, vertexStride);
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
// Setup vertex colors
|
|
|
|
GrColor* color = (GrColor*)((intptr_t)vertices + kColorOffset);
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
2018-10-31 18:04:39 +00:00
|
|
|
*color = fColor.toBytes_RGBA();
|
2017-03-21 11:56:47 +00:00
|
|
|
color = (GrColor*)((intptr_t)color + vertexStride);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup local coords
|
|
|
|
if (fHasLocalRect) {
|
|
|
|
SkPoint* coords = (SkPoint*)((intptr_t) vertices + kLocalOffset);
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
*coords = fLocalQuad.point(i);
|
|
|
|
coords = (SkPoint*)((intptr_t) coords + vertexStride);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-04 21:12:08 +00:00
|
|
|
fMesh = target->allocMesh();
|
2020-03-13 15:21:12 +00:00
|
|
|
fMesh->setIndexed(indexBuffer, 6, firstIndex, 0, 3, GrPrimitiveRestart::kNo, vertexBuffer,
|
|
|
|
firstVertex);
|
2019-02-26 18:13:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {
|
2020-03-04 21:12:08 +00:00
|
|
|
if (!fProgramInfo || !fMesh) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-05 21:40:31 +00:00
|
|
|
|
2020-03-16 23:34:44 +00:00
|
|
|
flushState->bindPipelineAndScissorClip(*fProgramInfo, chainBounds);
|
|
|
|
flushState->bindTextures(fProgramInfo->primProc(), nullptr, fProgramInfo->pipeline());
|
|
|
|
flushState->drawMesh(*fMesh);
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 21:12:08 +00:00
|
|
|
Helper fHelper;
|
2020-03-16 15:25:50 +00:00
|
|
|
GrSimpleMesh* fMesh = nullptr;
|
2020-03-04 21:12:08 +00:00
|
|
|
GrProgramInfo* fProgramInfo = nullptr;
|
2017-07-13 21:04:43 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GrMeshDrawOp;
|
2017-03-21 11:56:47 +00:00
|
|
|
};
|
|
|
|
|
2017-07-13 21:04:43 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
static constexpr SkRect kEmptyRect = SkRect::MakeEmpty();
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-03-21 11:56:47 +00:00
|
|
|
/*
|
|
|
|
* Atlased ops just draw themselves as textured rects with the texture pixels being
|
|
|
|
* pulled out of the atlas. Their color is based on their ID.
|
|
|
|
*/
|
|
|
|
class AtlasedRectOp final : public NonAARectOp {
|
|
|
|
public:
|
|
|
|
DEFINE_OP_CLASS_ID
|
|
|
|
|
|
|
|
~AtlasedRectOp() override {
|
|
|
|
fID = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* name() const override { return "AtlasedRectOp"; }
|
|
|
|
|
|
|
|
int id() const { return fID; }
|
|
|
|
|
2020-10-07 20:46:15 +00:00
|
|
|
static GrOp::Owner Make(GrRecordingContext* rContext,
|
|
|
|
GrPaint&& paint,
|
|
|
|
const SkRect& r,
|
|
|
|
int id) {
|
|
|
|
return Helper::FactoryHelper<AtlasedRectOp>(rContext, std::move(paint), r, id);
|
2017-07-13 21:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We set the initial color of the NonAARectOp based on the ID.
|
|
|
|
// Note that we force creation of a NonAARectOp that has local coords in anticipation of
|
|
|
|
// pulling from the atlas.
|
2020-10-07 20:46:15 +00:00
|
|
|
AtlasedRectOp(GrProcessorSet* processorSet, const SkPMColor4f& color, const SkRect& r,
|
2018-10-30 19:30:35 +00:00
|
|
|
int id)
|
2020-10-07 20:46:15 +00:00
|
|
|
: INHERITED(processorSet, SkPMColor4f::FromBytes_RGBA(kColors[id]), r, &kEmptyRect,
|
2018-10-31 18:04:39 +00:00
|
|
|
ClassID())
|
2017-07-13 21:04:43 +00:00
|
|
|
, fID(id)
|
|
|
|
, fNext(nullptr) {
|
|
|
|
SkASSERT(fID < kMaxIDs);
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 18:04:39 +00:00
|
|
|
void setColor(const SkPMColor4f& color) { fColor = color; }
|
2017-03-21 11:56:47 +00:00
|
|
|
void setLocalRect(const SkRect& localRect) {
|
|
|
|
SkASSERT(fHasLocalRect); // This should've been created to anticipate this
|
2018-05-17 14:42:14 +00:00
|
|
|
fLocalQuad = GrQuad(localRect);
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AtlasedRectOp* next() const { return fNext; }
|
|
|
|
void setNext(AtlasedRectOp* next) {
|
|
|
|
fNext = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
static const int kMaxIDs = 9;
|
2018-10-29 20:07:15 +00:00
|
|
|
static const GrColor kColors[kMaxIDs];
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
int fID;
|
2019-08-22 20:19:24 +00:00
|
|
|
// The Atlased ops have an internal singly-linked list of ops that land in the same opsTask
|
2017-03-21 11:56:47 +00:00
|
|
|
AtlasedRectOp* fNext;
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = NonAARectOp;
|
2017-03-21 11:56:47 +00:00
|
|
|
};
|
|
|
|
|
2017-07-13 21:04:43 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2017-03-21 11:56:47 +00:00
|
|
|
const GrColor AtlasedRectOp::kColors[kMaxIDs] = {
|
|
|
|
GrColorPackRGBA(255, 0, 0, 255),
|
|
|
|
GrColorPackRGBA(0, 255, 0, 255),
|
|
|
|
GrColorPackRGBA(0, 0, 255, 255),
|
|
|
|
GrColorPackRGBA(0, 255, 255, 255),
|
|
|
|
GrColorPackRGBA(255, 0, 255, 255),
|
|
|
|
GrColorPackRGBA(255, 255, 0, 255),
|
|
|
|
GrColorPackRGBA(0, 0, 0, 255),
|
|
|
|
GrColorPackRGBA(128, 128, 128, 255),
|
|
|
|
GrColorPackRGBA(255, 255, 255, 255)
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int kDrawnTileSize = 16;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rather than performing any rect packing, this atlaser just lays out constant-sized
|
|
|
|
* tiles in an Nx1 row
|
|
|
|
*/
|
|
|
|
static const int kAtlasTileSize = 2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This class aggregates the op information required for atlasing
|
|
|
|
*/
|
2017-05-05 15:26:15 +00:00
|
|
|
class AtlasObject final : public GrOnFlushCallbackObject {
|
2017-03-21 11:56:47 +00:00
|
|
|
public:
|
2019-10-24 14:37:08 +00:00
|
|
|
AtlasObject(skiatest::Reporter* reporter) : fDone(false), fReporter(reporter) {}
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
~AtlasObject() override {
|
|
|
|
SkASSERT(fDone);
|
|
|
|
}
|
|
|
|
|
|
|
|
void markAsDone() {
|
|
|
|
fDone = true;
|
|
|
|
}
|
|
|
|
|
2019-08-22 20:19:24 +00:00
|
|
|
// Insert the new op in an internal singly-linked list for 'opsTaskID'
|
|
|
|
void addOp(uint32_t opsTaskID, AtlasedRectOp* op) {
|
2017-03-21 11:56:47 +00:00
|
|
|
LinkedListHeader* header = nullptr;
|
|
|
|
for (int i = 0; i < fOps.count(); ++i) {
|
2019-08-22 20:19:24 +00:00
|
|
|
if (opsTaskID == fOps[i].fID) {
|
2017-03-21 11:56:47 +00:00
|
|
|
header = &(fOps[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!header) {
|
2019-08-22 20:19:24 +00:00
|
|
|
fOps.push_back({opsTaskID, nullptr});
|
2017-03-21 11:56:47 +00:00
|
|
|
header = &(fOps[fOps.count()-1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
op->setNext(header->fHead);
|
|
|
|
header->fHead = op;
|
|
|
|
}
|
|
|
|
|
2018-02-14 16:09:57 +00:00
|
|
|
int numOps() const { return fOps.count(); }
|
|
|
|
|
|
|
|
// Get the fully lazy proxy that is backing the atlas. Its actual width isn't
|
|
|
|
// known until flush time.
|
2020-02-10 21:36:07 +00:00
|
|
|
GrSurfaceProxyView getAtlasView(GrProxyProvider* proxyProvider, const GrCaps* caps) {
|
|
|
|
if (fAtlasView) {
|
|
|
|
return fAtlasView;
|
2018-02-14 16:09:57 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
|
|
|
|
GrRenderable::kYes);
|
2020-02-10 21:36:07 +00:00
|
|
|
auto proxy = GrProxyProvider::MakeFullyLazyProxy(
|
2020-03-23 22:32:50 +00:00
|
|
|
[](GrResourceProvider* resourceProvider,
|
|
|
|
const GrSurfaceProxy::LazySurfaceDesc& desc)
|
2019-08-30 20:19:42 +00:00
|
|
|
-> GrSurfaceProxy::LazyCallbackResult {
|
2020-03-23 22:32:50 +00:00
|
|
|
SkASSERT(desc.fDimensions.width() < 0 && desc.fDimensions.height() < 0);
|
2020-02-07 19:17:25 +00:00
|
|
|
SkISize dims;
|
2018-02-14 16:09:57 +00:00
|
|
|
// TODO: until partial flushes in MDB lands we're stuck having
|
|
|
|
// all 9 atlas draws occur
|
2020-02-07 19:17:25 +00:00
|
|
|
dims.fWidth = 9 /*this->numOps()*/ * kAtlasTileSize;
|
|
|
|
dims.fHeight = kAtlasTileSize;
|
2018-02-14 16:09:57 +00:00
|
|
|
|
2020-03-23 22:32:50 +00:00
|
|
|
return resourceProvider->createTexture(dims, desc.fFormat, desc.fRenderable,
|
2020-07-21 14:32:07 +00:00
|
|
|
desc.fSampleCnt, desc.fMipmapped,
|
2020-03-23 22:32:50 +00:00
|
|
|
desc.fBudgeted, desc.fProtected);
|
2018-02-14 16:09:57 +00:00
|
|
|
},
|
2018-11-16 20:43:41 +00:00
|
|
|
format,
|
2019-07-22 18:23:45 +00:00
|
|
|
GrRenderable::kYes,
|
|
|
|
1,
|
2019-07-19 18:24:36 +00:00
|
|
|
GrProtected::kNo,
|
2019-08-30 20:19:42 +00:00
|
|
|
*proxyProvider->caps(),
|
|
|
|
GrSurfaceProxy::UseAllocator::kNo);
|
2019-04-22 16:41:39 +00:00
|
|
|
|
2020-03-27 00:37:01 +00:00
|
|
|
GrSwizzle readSwizzle = caps->getReadSwizzle(format, GrColorType::kRGBA_8888);
|
2020-02-10 21:36:07 +00:00
|
|
|
fAtlasView = {std::move(proxy), kBottomLeft_GrSurfaceOrigin, readSwizzle};
|
|
|
|
return fAtlasView;
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-02-14 16:09:57 +00:00
|
|
|
* This callback creates the atlas and updates the AtlasedRectOps to read from it
|
2017-03-21 11:56:47 +00:00
|
|
|
*/
|
2017-05-05 15:26:15 +00:00
|
|
|
void preFlush(GrOnFlushResourceProvider* resourceProvider,
|
2020-11-11 13:51:25 +00:00
|
|
|
SkSpan<const uint32_t> renderTaskIDs) override {
|
2019-08-22 20:19:24 +00:00
|
|
|
// Until MDB is landed we will most-likely only have one opsTask.
|
2017-03-21 11:56:47 +00:00
|
|
|
SkTDArray<LinkedListHeader*> lists;
|
2020-11-11 13:51:25 +00:00
|
|
|
for (uint32_t taskID : renderTaskIDs) {
|
|
|
|
if (LinkedListHeader* list = this->getList(taskID)) {
|
2018-08-08 15:23:41 +00:00
|
|
|
lists.push_back(list);
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lists.count()) {
|
|
|
|
return; // nothing to atlas
|
|
|
|
}
|
|
|
|
|
2020-02-10 21:36:07 +00:00
|
|
|
if (!resourceProvider->instatiateProxy(fAtlasView.proxy())) {
|
2018-02-14 16:09:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-10 21:36:07 +00:00
|
|
|
// At this point 'fAtlasView' proxy should be instantiated and have:
|
|
|
|
// 1 ref from the 'fAtlasView' proxy sk_sp
|
2019-06-11 12:08:08 +00:00
|
|
|
// 9 refs from the 9 AtlasedRectOps
|
2019-06-18 21:15:04 +00:00
|
|
|
// The backing GrSurface should have only 1 though bc there is only one proxy
|
2020-02-10 21:36:07 +00:00
|
|
|
CheckSingleThreadedProxyRefs(fReporter, fAtlasView.proxy(), 10, 1);
|
|
|
|
auto rtc = resourceProvider->makeRenderTargetContext(
|
|
|
|
fAtlasView.refProxy(), fAtlasView.origin(), GrColorType::kRGBA_8888, nullptr,
|
|
|
|
nullptr);
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2017-12-11 22:42:09 +00:00
|
|
|
// clear the atlas
|
2020-05-26 20:57:38 +00:00
|
|
|
rtc->clear(SK_PMColor4fTRANSPARENT);
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
int blocksInAtlas = 0;
|
|
|
|
for (int i = 0; i < lists.count(); ++i) {
|
|
|
|
for (AtlasedRectOp* op = lists[i]->fHead; op; op = op->next()) {
|
|
|
|
SkIRect r = SkIRect::MakeXYWH(blocksInAtlas*kAtlasTileSize, 0,
|
|
|
|
kAtlasTileSize, kAtlasTileSize);
|
|
|
|
|
|
|
|
// For now, we avoid the resource buffer issues and just use clears
|
|
|
|
#if 1
|
2020-05-26 20:57:38 +00:00
|
|
|
rtc->clear(r, op->color());
|
2017-03-21 11:56:47 +00:00
|
|
|
#else
|
|
|
|
GrPaint paint;
|
2018-11-05 20:06:26 +00:00
|
|
|
paint.setColor4f(op->color());
|
2017-07-13 21:04:43 +00:00
|
|
|
std::unique_ptr<GrDrawOp> drawOp(NonAARectOp::Make(std::move(paint),
|
|
|
|
SkRect::Make(r)));
|
|
|
|
rtc->priv().testingOnly_addDrawOp(std::move(drawOp));
|
2017-03-21 11:56:47 +00:00
|
|
|
#endif
|
|
|
|
blocksInAtlas++;
|
|
|
|
|
|
|
|
// Set the atlased Op's color to white (so we know we're not using it for
|
|
|
|
// the final draw).
|
2018-10-31 18:04:39 +00:00
|
|
|
op->setColor(SK_PMColor4fWHITE);
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
// Set the atlased Op's localRect to point to where it landed in the atlas
|
|
|
|
op->setLocalRect(SkRect::Make(r));
|
|
|
|
}
|
|
|
|
|
|
|
|
// We've updated all these ops and we certainly don't want to process them again
|
|
|
|
this->clearOpsFor(lists[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef struct {
|
|
|
|
uint32_t fID;
|
|
|
|
AtlasedRectOp* fHead;
|
|
|
|
} LinkedListHeader;
|
|
|
|
|
2019-08-22 20:19:24 +00:00
|
|
|
LinkedListHeader* getList(uint32_t opsTaskID) {
|
2017-03-21 11:56:47 +00:00
|
|
|
for (int i = 0; i < fOps.count(); ++i) {
|
2019-08-22 20:19:24 +00:00
|
|
|
if (opsTaskID == fOps[i].fID) {
|
2017-03-21 11:56:47 +00:00
|
|
|
return &(fOps[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clearOpsFor(LinkedListHeader* header) {
|
|
|
|
// The AtlasedRectOps have yet to execute (and this class doesn't own them) so just
|
|
|
|
// forget about them in the laziest way possible.
|
|
|
|
header->fHead = nullptr;
|
2019-08-22 20:19:24 +00:00
|
|
|
header->fID = 0; // invalid opsTask ID
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
2019-08-22 20:19:24 +00:00
|
|
|
// Each opsTask containing AtlasedRectOps gets its own internal singly-linked list
|
2020-02-10 21:36:07 +00:00
|
|
|
SkTDArray<LinkedListHeader> fOps;
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2018-02-14 16:09:57 +00:00
|
|
|
// The fully lazy proxy for the atlas
|
2020-02-10 21:36:07 +00:00
|
|
|
GrSurfaceProxyView fAtlasView;
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
// Set to true when the testing harness expects this object to be no longer used
|
2020-02-10 21:36:07 +00:00
|
|
|
bool fDone;
|
2019-10-24 14:37:08 +00:00
|
|
|
|
2020-02-10 21:36:07 +00:00
|
|
|
skiatest::Reporter* fReporter;
|
2017-03-21 11:56:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// This creates an off-screen rendertarget whose ops which eventually pull from the atlas.
|
2020-07-23 13:41:57 +00:00
|
|
|
static GrSurfaceProxyView make_upstream_image(GrRecordingContext* rContext,
|
|
|
|
AtlasObject* object,
|
|
|
|
int start,
|
2020-02-10 21:36:07 +00:00
|
|
|
GrSurfaceProxyView atlasView,
|
|
|
|
SkAlphaType atlasAlphaType) {
|
2020-01-08 16:52:34 +00:00
|
|
|
auto rtc = GrRenderTargetContext::Make(
|
2020-07-23 13:41:57 +00:00
|
|
|
rContext, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kApprox,
|
2020-01-08 16:52:34 +00:00
|
|
|
{3 * kDrawnTileSize, kDrawnTileSize});
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2020-05-26 20:57:38 +00:00
|
|
|
rtc->clear({ 1, 0, 0, 1 });
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
SkRect r = SkRect::MakeXYWH(i*kDrawnTileSize, 0, kDrawnTileSize, kDrawnTileSize);
|
|
|
|
|
2020-02-05 15:45:39 +00:00
|
|
|
auto fp = GrTextureEffect::Make(atlasView, atlasAlphaType);
|
2017-03-21 11:56:47 +00:00
|
|
|
GrPaint paint;
|
2020-07-21 16:28:35 +00:00
|
|
|
paint.setColorFragmentProcessor(std::move(fp));
|
2017-03-21 11:56:47 +00:00
|
|
|
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
|
2020-10-07 20:46:15 +00:00
|
|
|
GrOp::Owner op = AtlasedRectOp::Make(rContext, std::move(paint), r, start + i);
|
|
|
|
AtlasedRectOp* sparePtr = (AtlasedRectOp*)op.get();
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2019-08-22 20:19:24 +00:00
|
|
|
uint32_t opsTaskID;
|
2020-05-29 13:54:07 +00:00
|
|
|
rtc->priv().testingOnly_addDrawOp(nullptr, std::move(op),
|
2019-08-22 20:19:24 +00:00
|
|
|
[&opsTaskID](GrOp* op, uint32_t id) { opsTaskID = id; });
|
|
|
|
SkASSERT(SK_InvalidUniqueID != opsTaskID);
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2019-08-22 20:19:24 +00:00
|
|
|
object->addOp(opsTaskID, sparePtr);
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 21:36:07 +00:00
|
|
|
return rtc->readSurfaceView();
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enable this if you want to debug the final draws w/o having the atlasCallback create the
|
|
|
|
// atlas
|
|
|
|
#if 0
|
|
|
|
#include "SkGrPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImageEncoder.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
2017-10-06 01:45:25 +00:00
|
|
|
|
|
|
|
static void save_bm(const SkBitmap& bm, const char name[]) {
|
2019-03-20 16:12:10 +00:00
|
|
|
bool result = ToolUtils::EncodeImageToFile(name, bm, SkEncodedImageFormat::kPNG, 100);
|
2017-10-06 01:45:25 +00:00
|
|
|
SkASSERT(result);
|
|
|
|
}
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2020-07-23 13:41:57 +00:00
|
|
|
sk_sp<GrTextureProxy> pre_create_atlas(GrRecordingContext* rContext) {
|
2017-03-21 11:56:47 +00:00
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocN32Pixels(18, 2, true);
|
|
|
|
bm.erase(SK_ColorRED, SkIRect::MakeXYWH(0, 0, 2, 2));
|
|
|
|
bm.erase(SK_ColorGREEN, SkIRect::MakeXYWH(2, 0, 2, 2));
|
|
|
|
bm.erase(SK_ColorBLUE, SkIRect::MakeXYWH(4, 0, 2, 2));
|
|
|
|
bm.erase(SK_ColorCYAN, SkIRect::MakeXYWH(6, 0, 2, 2));
|
|
|
|
bm.erase(SK_ColorMAGENTA, SkIRect::MakeXYWH(8, 0, 2, 2));
|
|
|
|
bm.erase(SK_ColorYELLOW, SkIRect::MakeXYWH(10, 0, 2, 2));
|
|
|
|
bm.erase(SK_ColorBLACK, SkIRect::MakeXYWH(12, 0, 2, 2));
|
|
|
|
bm.erase(SK_ColorGRAY, SkIRect::MakeXYWH(14, 0, 2, 2));
|
|
|
|
bm.erase(SK_ColorWHITE, SkIRect::MakeXYWH(16, 0, 2, 2));
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
save_bm(bm, "atlas-fake.png");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
desc.fFlags |= kRenderTarget_GrSurfaceFlag;
|
|
|
|
|
2020-07-23 13:41:57 +00:00
|
|
|
sk_sp<GrSurfaceProxy> tmp = GrSurfaceProxy::MakeDeferred(*rContext->caps(),
|
|
|
|
rContext->textureProvider(),
|
2020-02-07 19:17:25 +00:00
|
|
|
dm.dimensions(), SkBudgeted::kYes,
|
2017-03-21 11:56:47 +00:00
|
|
|
bm.getPixels(), bm.rowBytes());
|
|
|
|
|
|
|
|
return sk_ref_sp(tmp->asTextureProxy());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-02-14 16:09:57 +00:00
|
|
|
|
2017-03-21 11:56:47 +00:00
|
|
|
static void test_color(skiatest::Reporter* reporter, const SkBitmap& bm, int x, SkColor expected) {
|
|
|
|
SkColor readback = bm.getColor(x, kDrawnTileSize/2);
|
|
|
|
REPORTER_ASSERT(reporter, expected == readback);
|
|
|
|
if (expected != readback) {
|
|
|
|
SkDebugf("Color mismatch: %x %x\n", expected, readback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For the atlasing test we make a DAG that looks like:
|
|
|
|
*
|
|
|
|
* RT1 with ops: 0,1,2 RT2 with ops: 3,4,5 RT3 with ops: 6,7,8
|
|
|
|
* \ /
|
|
|
|
* \ /
|
|
|
|
* RT4
|
|
|
|
* We then flush RT4 and expect only ops 0-5 to be atlased together.
|
|
|
|
* Each op is just a solid colored rect so both the atlas and the final image should appear as:
|
|
|
|
* R G B C M Y
|
|
|
|
* with the atlas having width = 6*kAtlasTileSize and height = kAtlasTileSize.
|
|
|
|
*
|
2018-02-14 16:09:57 +00:00
|
|
|
* Note: until partial flushes in MDB lands, the atlas will actually have width= 9*kAtlasTileSize
|
|
|
|
* and look like:
|
2017-03-21 11:56:47 +00:00
|
|
|
* R G B C M Y K Grey White
|
|
|
|
*/
|
2017-05-05 15:26:15 +00:00
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(OnFlushCallbackTest, reporter, ctxInfo) {
|
2020-02-10 21:36:07 +00:00
|
|
|
static const int kNumViews = 3;
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
auto proxyProvider = dContext->priv().proxyProvider();
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2019-10-24 14:37:08 +00:00
|
|
|
AtlasObject object(reporter);
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
dContext->priv().addOnFlushCallbackObject(&object);
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2020-02-10 21:36:07 +00:00
|
|
|
GrSurfaceProxyView views[kNumViews];
|
|
|
|
for (int i = 0; i < kNumViews; ++i) {
|
2020-08-11 16:02:22 +00:00
|
|
|
views[i] = make_upstream_image(dContext, &object, i * 3,
|
|
|
|
object.getAtlasView(proxyProvider, dContext->priv().caps()),
|
2020-02-10 21:36:07 +00:00
|
|
|
kPremul_SkAlphaType);
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const int kFinalWidth = 6*kDrawnTileSize;
|
|
|
|
static const int kFinalHeight = kDrawnTileSize;
|
|
|
|
|
2020-01-08 16:52:34 +00:00
|
|
|
auto rtc = GrRenderTargetContext::Make(
|
2020-08-11 16:02:22 +00:00
|
|
|
dContext, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kApprox,
|
2020-01-08 16:52:34 +00:00
|
|
|
{kFinalWidth, kFinalHeight});
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2020-05-26 20:57:38 +00:00
|
|
|
rtc->clear(SK_PMColor4fWHITE);
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
// Note that this doesn't include the third texture proxy
|
2020-02-10 21:36:07 +00:00
|
|
|
for (int i = 0; i < kNumViews - 1; ++i) {
|
2017-03-21 11:56:47 +00:00
|
|
|
SkRect r = SkRect::MakeXYWH(i*3*kDrawnTileSize, 0, 3*kDrawnTileSize, kDrawnTileSize);
|
|
|
|
|
2020-05-21 16:11:27 +00:00
|
|
|
SkMatrix t = SkMatrix::Translate(-i*3*kDrawnTileSize, 0);
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
GrPaint paint;
|
2020-02-10 21:36:07 +00:00
|
|
|
auto fp = GrTextureEffect::Make(std::move(views[i]), kPremul_SkAlphaType, t);
|
2017-03-21 11:56:47 +00:00
|
|
|
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
|
2020-07-21 16:28:35 +00:00
|
|
|
paint.setColorFragmentProcessor(std::move(fp));
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2020-05-29 13:54:07 +00:00
|
|
|
rtc->drawRect(nullptr, std::move(paint), GrAA::kNo, SkMatrix::I(), r);
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 14:23:36 +00:00
|
|
|
dContext->priv().flushSurface(rtc->asSurfaceProxy());
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
SkBitmap readBack;
|
|
|
|
readBack.allocN32Pixels(kFinalWidth, kFinalHeight);
|
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
SkAssertResult(rtc->readPixels(dContext, readBack.info(), readBack.getPixels(),
|
|
|
|
readBack.rowBytes(), {0, 0}));
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
dContext->priv().testingOnly_flushAndRemoveOnFlushCallbackObject(&object);
|
2017-05-05 15:26:15 +00:00
|
|
|
|
|
|
|
object.markAsDone();
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
int x = kDrawnTileSize/2;
|
|
|
|
test_color(reporter, readBack, x, SK_ColorRED);
|
|
|
|
x += kDrawnTileSize;
|
|
|
|
test_color(reporter, readBack, x, SK_ColorGREEN);
|
|
|
|
x += kDrawnTileSize;
|
|
|
|
test_color(reporter, readBack, x, SK_ColorBLUE);
|
|
|
|
x += kDrawnTileSize;
|
|
|
|
test_color(reporter, readBack, x, SK_ColorCYAN);
|
|
|
|
x += kDrawnTileSize;
|
|
|
|
test_color(reporter, readBack, x, SK_ColorMAGENTA);
|
|
|
|
x += kDrawnTileSize;
|
|
|
|
test_color(reporter, readBack, x, SK_ColorYELLOW);
|
|
|
|
}
|