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"
|
|
|
|
#include "include/gpu/GrTexture.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/GrClip.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/GrDefaultGeoProcFactory.h"
|
|
|
|
#include "src/gpu/GrOnFlushResourceProvider.h"
|
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
|
|
|
#include "src/gpu/GrRenderTargetContextPriv.h"
|
|
|
|
#include "src/gpu/GrResourceProvider.h"
|
|
|
|
#include "src/gpu/effects/generated/GrSimpleTextureEffect.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"
|
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
|
2019-02-12 20:24:12 +00:00
|
|
|
static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context,
|
2018-06-12 14:11:12 +00:00
|
|
|
GrPaint&& paint,
|
|
|
|
const SkRect& r) {
|
|
|
|
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
|
2019-02-12 20:24:12 +00:00
|
|
|
static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context,
|
2018-06-12 14:11:12 +00:00
|
|
|
GrPaint&& paint,
|
|
|
|
const SkRect& r,
|
|
|
|
const SkRect& local) {
|
|
|
|
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
|
|
|
|
2018-10-31 18:04:39 +00:00
|
|
|
NonAARectOp(const Helper::MakeArgs& helperArgs, 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)
|
|
|
|
, fHelper(helperArgs, GrAAType::kNone) {
|
|
|
|
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.
|
|
|
|
this->setBounds(r, HasAABloat::kYes, IsZeroArea::kYes);
|
|
|
|
}
|
|
|
|
|
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 {
|
2017-09-13 17:10:52 +00:00
|
|
|
fHelper.visitProxies(func);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
static GrAppliedClip kNoClip;
|
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:
|
2017-08-09 20:02:19 +00:00
|
|
|
void onPrepareDraws(Target* target) override {
|
2017-03-21 11:56:47 +00:00
|
|
|
using namespace GrDefaultGeoProcFactory;
|
|
|
|
|
|
|
|
// The vertex attrib order is always pos, color, local coords.
|
|
|
|
static const int kColorOffset = sizeof(SkPoint);
|
|
|
|
static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor);
|
|
|
|
|
|
|
|
sk_sp<GrGeometryProcessor> gp =
|
2018-07-17 14:19:38 +00:00
|
|
|
GrDefaultGeoProcFactory::Make(target->caps().shaderCaps(),
|
|
|
|
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) {
|
|
|
|
SkDebugf("Couldn't create GrGeometryProcessor for GrAtlasedOp\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Change how GPs configure attributes
Adds setVertexAttributes and setInstanceAttributes. These take a pointer
to the first attribute, and a count. The count is the total number of
possible attributes, though some may not be initialized. The base class
computes the number of initialized attributes, pre-computes the strides,
and only allows subsequent access to the initialized attributes.
The attributes need to be allocated contiguously. Some GPs place them in
an array, though most just place them as consecutive members, and pass
a pointer to the first one.
Indexed access would be possible, but now it makes more sense to iterate
over all attributes, so enable that, and use range-based for everywhere.
Completely remove the per-attribute offset helper (again - possible, but
not real helpful), and make the stride always available. In many ops,
just use the GP's computed stride, rather than re-computing it.
Bug: skia:
Change-Id: Ie4cccb7969a98ee5a10b373e714fbd702e875b3e
Reviewed-on: https://skia-review.googlesource.com/c/169241
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2018-11-12 20:34:00 +00:00
|
|
|
size_t vertexStride = gp->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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 14:02:38 +00:00
|
|
|
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
|
|
|
|
mesh->setIndexed(indexBuffer, 6, firstIndex, 0, 3, GrPrimitiveRestart::kNo);
|
|
|
|
mesh->setVertexData(vertexBuffer, firstVertex);
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2019-02-26 18:13:22 +00:00
|
|
|
target->recordDraw(std::move(gp), mesh);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {
|
|
|
|
fHelper.executeDrawsAndUploads(this, flushState, chainBounds);
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 21:04:43 +00:00
|
|
|
Helper fHelper;
|
|
|
|
|
|
|
|
typedef GrMeshDrawOp INHERITED;
|
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; }
|
|
|
|
|
2018-06-12 14:11:12 +00:00
|
|
|
static std::unique_ptr<AtlasedRectOp> Make(GrContext* context,
|
|
|
|
GrPaint&& paint,
|
|
|
|
const SkRect& r,
|
|
|
|
int id) {
|
|
|
|
GrDrawOp* op = Helper::FactoryHelper<AtlasedRectOp>(context, std::move(paint),
|
|
|
|
r, id).release();
|
2017-07-13 21:04:43 +00:00
|
|
|
return std::unique_ptr<AtlasedRectOp>(static_cast<AtlasedRectOp*>(op));
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2018-10-31 18:04:39 +00:00
|
|
|
AtlasedRectOp(const Helper::MakeArgs& helperArgs, const SkPMColor4f& color, const SkRect& r,
|
2018-10-30 19:30:35 +00:00
|
|
|
int id)
|
2018-10-31 18:04:39 +00:00
|
|
|
: INHERITED(helperArgs, SkPMColor4f::FromBytes_RGBA(kColors[id]), r, &kEmptyRect,
|
|
|
|
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;
|
|
|
|
// The Atlased ops have an internal singly-linked list of ops that land in the same opList
|
|
|
|
AtlasedRectOp* fNext;
|
|
|
|
|
|
|
|
typedef NonAARectOp INHERITED;
|
|
|
|
};
|
|
|
|
|
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:
|
|
|
|
AtlasObject() : fDone(false) { }
|
|
|
|
|
|
|
|
~AtlasObject() override {
|
|
|
|
SkASSERT(fDone);
|
|
|
|
}
|
|
|
|
|
|
|
|
void markAsDone() {
|
|
|
|
fDone = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert the new op in an internal singly-linked list for 'opListID'
|
|
|
|
void addOp(uint32_t opListID, AtlasedRectOp* op) {
|
|
|
|
LinkedListHeader* header = nullptr;
|
|
|
|
for (int i = 0; i < fOps.count(); ++i) {
|
|
|
|
if (opListID == fOps[i].fID) {
|
|
|
|
header = &(fOps[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!header) {
|
2018-08-08 15:23:41 +00:00
|
|
|
fOps.push_back({opListID, 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.
|
2018-11-16 20:43:41 +00:00
|
|
|
sk_sp<GrTextureProxy> getAtlasProxy(GrProxyProvider* proxyProvider, const GrCaps* caps) {
|
2018-02-14 16:09:57 +00:00
|
|
|
if (fAtlasProxy) {
|
|
|
|
return fAtlasProxy;
|
|
|
|
}
|
|
|
|
|
2019-07-08 20:48:14 +00:00
|
|
|
const GrBackendFormat format = caps->getBackendFormatFromColorType(GrColorType::kRGBA_8888);
|
2018-11-16 20:43:41 +00:00
|
|
|
|
2018-06-16 23:22:59 +00:00
|
|
|
fAtlasProxy = GrProxyProvider::MakeFullyLazyProxy(
|
2019-04-01 16:29:34 +00:00
|
|
|
[](GrResourceProvider* resourceProvider)
|
|
|
|
-> GrSurfaceProxy::LazyInstantiationResult {
|
2018-02-14 16:09:57 +00:00
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
// TODO: until partial flushes in MDB lands we're stuck having
|
|
|
|
// all 9 atlas draws occur
|
|
|
|
desc.fWidth = 9 /*this->numOps()*/ * kAtlasTileSize;
|
|
|
|
desc.fHeight = kAtlasTileSize;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
2019-04-01 16:29:34 +00:00
|
|
|
auto texture = resourceProvider->createTexture(
|
|
|
|
desc, SkBudgeted::kYes, GrResourceProvider::Flags::kNoPendingIO);
|
|
|
|
return std::move(texture);
|
2018-02-14 16:09:57 +00:00
|
|
|
},
|
2018-11-16 20:43:41 +00:00
|
|
|
format,
|
2018-02-14 16:09:57 +00:00
|
|
|
GrProxyProvider::Renderable::kYes,
|
|
|
|
kBottomLeft_GrSurfaceOrigin,
|
2018-06-16 23:22:59 +00:00
|
|
|
kRGBA_8888_GrPixelConfig,
|
|
|
|
*proxyProvider->caps());
|
2019-04-22 16:41:39 +00:00
|
|
|
|
|
|
|
fAtlasProxy->priv().setIgnoredByResourceAllocator();
|
2018-02-14 16:09:57 +00:00
|
|
|
return fAtlasProxy;
|
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,
|
2017-03-21 11:56:47 +00:00
|
|
|
const uint32_t* opListIDs, int numOpListIDs,
|
|
|
|
SkTArray<sk_sp<GrRenderTargetContext>>* results) override {
|
|
|
|
SkASSERT(!results->count());
|
|
|
|
|
|
|
|
// Until MDB is landed we will most-likely only have one opList.
|
|
|
|
SkTDArray<LinkedListHeader*> lists;
|
|
|
|
for (int i = 0; i < numOpListIDs; ++i) {
|
|
|
|
if (LinkedListHeader* list = this->getList(opListIDs[i])) {
|
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
|
|
|
|
}
|
|
|
|
|
2018-02-14 16:09:57 +00:00
|
|
|
if (!resourceProvider->instatiateProxy(fAtlasProxy.get())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-11 12:08:08 +00:00
|
|
|
// At this point 'fAtlasProxy' should be instantiated and have:
|
|
|
|
// 1 ref from the 'fAtlasProxy' sk_sp
|
|
|
|
// 9 refs from the 9 AtlasedRectOps
|
2019-06-18 21:15:04 +00:00
|
|
|
SkASSERT(10 == fAtlasProxy->priv().getProxyRefCnt());
|
|
|
|
// The backing GrSurface should have only 1 though bc there is only one proxy
|
2019-06-19 18:12:13 +00:00
|
|
|
SkASSERT(1 == fAtlasProxy->testingOnly_getBackingRefCnt());
|
2017-03-21 11:56:47 +00:00
|
|
|
sk_sp<GrRenderTargetContext> rtc = resourceProvider->makeRenderTargetContext(
|
2019-06-24 19:50:07 +00:00
|
|
|
fAtlasProxy, GrColorType::kRGBA_8888, nullptr, nullptr);
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2017-12-11 22:42:09 +00:00
|
|
|
// clear the atlas
|
2018-11-05 20:06:26 +00:00
|
|
|
rtc->clear(nullptr, SK_PMColor4fTRANSPARENT,
|
|
|
|
GrRenderTargetContext::CanClearFullscreen::kYes);
|
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
|
2018-11-05 20:06:26 +00:00
|
|
|
rtc->clear(&r, op->color(), GrRenderTargetContext::CanClearFullscreen::kNo);
|
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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
results->push_back(std::move(rtc));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef struct {
|
|
|
|
uint32_t fID;
|
|
|
|
AtlasedRectOp* fHead;
|
|
|
|
} LinkedListHeader;
|
|
|
|
|
|
|
|
LinkedListHeader* getList(uint32_t opListID) {
|
|
|
|
for (int i = 0; i < fOps.count(); ++i) {
|
|
|
|
if (opListID == fOps[i].fID) {
|
|
|
|
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;
|
|
|
|
header->fID = 0; // invalid opList ID
|
|
|
|
}
|
|
|
|
|
|
|
|
// Each opList containing AtlasedRectOps gets its own internal singly-linked list
|
|
|
|
SkTDArray<LinkedListHeader> fOps;
|
|
|
|
|
2018-02-14 16:09:57 +00:00
|
|
|
// The fully lazy proxy for the atlas
|
|
|
|
sk_sp<GrTextureProxy> fAtlasProxy;
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
// Set to true when the testing harness expects this object to be no longer used
|
|
|
|
bool fDone;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This creates an off-screen rendertarget whose ops which eventually pull from the atlas.
|
|
|
|
static sk_sp<GrTextureProxy> make_upstream_image(GrContext* context, AtlasObject* object, int start,
|
2018-02-14 16:09:57 +00:00
|
|
|
sk_sp<GrTextureProxy> atlasProxy) {
|
2019-06-24 19:50:07 +00:00
|
|
|
sk_sp<GrRenderTargetContext> rtc(
|
2019-07-03 15:27:44 +00:00
|
|
|
context->priv().makeDeferredRenderTargetContext(SkBackingFit::kApprox,
|
2019-06-24 19:50:07 +00:00
|
|
|
3*kDrawnTileSize,
|
|
|
|
kDrawnTileSize,
|
|
|
|
GrColorType::kRGBA_8888,
|
|
|
|
nullptr));
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2018-11-05 20:06:26 +00:00
|
|
|
rtc->clear(nullptr, { 1, 0, 0, 1 }, GrRenderTargetContext::CanClearFullscreen::kYes);
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
SkRect r = SkRect::MakeXYWH(i*kDrawnTileSize, 0, kDrawnTileSize, kDrawnTileSize);
|
|
|
|
|
2018-02-14 16:09:57 +00:00
|
|
|
auto fp = GrSimpleTextureEffect::Make(atlasProxy, SkMatrix::I());
|
2017-03-21 11:56:47 +00:00
|
|
|
GrPaint paint;
|
|
|
|
paint.addColorFragmentProcessor(std::move(fp));
|
|
|
|
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
|
2018-06-12 14:11:12 +00:00
|
|
|
std::unique_ptr<AtlasedRectOp> op(AtlasedRectOp::Make(context,
|
|
|
|
std::move(paint), r, start + i));
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
AtlasedRectOp* sparePtr = op.get();
|
|
|
|
|
2018-10-31 14:42:18 +00:00
|
|
|
uint32_t opListID;
|
|
|
|
rtc->priv().testingOnly_addDrawOp(GrNoClip(), std::move(op),
|
|
|
|
[&opListID](GrOp* op, uint32_t id) { opListID = id; });
|
2018-05-22 22:17:48 +00:00
|
|
|
SkASSERT(SK_InvalidUniqueID != opListID);
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
object->addOp(opListID, sparePtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rtc->asTextureProxyRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
sk_sp<GrTextureProxy> pre_create_atlas(GrContext* context) {
|
|
|
|
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
|
|
|
|
|
Dest color space no longer impacts mipmaps or texture sampling
PS5: Removes SkDestinationSurfaceColorMode, tracking of mipmap
mode on GrTexture, sRGB decode state per-texture. Because we
were often choosing sRGB configs for RGB color types, legacy
rendering would then be incorrect (too dark). So...
PS7: Stops ever using sRGB pixel configs when translating
image info or color type. Also removes a bunch of GrCaps bits
and a GrContextOption that are no longer relevant.
PS9: Adjusts surface creation unit test expectations, and
changes the raster rules accordingly.
At this point, sRGB configs are (obviously) going to be broken.
Locally, I ran 8888, gl, and the gbr- versions of both. Across
all GMs x configs, there are 13 diffs. 12 are GMs that create
surfaces with a color-space attached (and thus, the offscreen
is no longer getting sRGB pixel config). The only remainder
constructs an SkPictureImageGenerator, (with an attached color
space) and renders it to the gbr-gl canvas, which triggers a
a tagged surface inside the generator.
Bug: skia:
Change-Id: Ie5edfa157dd799f3121e8173fc4f97f6c8ed6789
Reviewed-on: https://skia-review.googlesource.com/131282
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
2018-06-01 16:25:08 +00:00
|
|
|
GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bm.info());
|
2017-03-21 11:56:47 +00:00
|
|
|
desc.fFlags |= kRenderTarget_GrSurfaceFlag;
|
|
|
|
|
|
|
|
sk_sp<GrSurfaceProxy> tmp = GrSurfaceProxy::MakeDeferred(*context->caps(),
|
|
|
|
context->textureProvider(),
|
|
|
|
desc, SkBudgeted::kYes,
|
|
|
|
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) {
|
2017-03-21 11:56:47 +00:00
|
|
|
static const int kNumProxies = 3;
|
|
|
|
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
auto proxyProvider = context->priv().proxyProvider();
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2017-05-05 15:26:15 +00:00
|
|
|
AtlasObject object;
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2019-02-04 18:26:26 +00:00
|
|
|
context->priv().addOnFlushCallbackObject(&object);
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
sk_sp<GrTextureProxy> proxies[kNumProxies];
|
|
|
|
for (int i = 0; i < kNumProxies; ++i) {
|
2018-02-14 16:09:57 +00:00
|
|
|
proxies[i] = make_upstream_image(context, &object, i*3,
|
2018-11-16 20:43:41 +00:00
|
|
|
object.getAtlasProxy(proxyProvider,
|
2019-02-04 18:26:26 +00:00
|
|
|
context->priv().caps()));
|
2017-03-21 11:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const int kFinalWidth = 6*kDrawnTileSize;
|
|
|
|
static const int kFinalHeight = kDrawnTileSize;
|
|
|
|
|
2019-06-24 19:50:07 +00:00
|
|
|
sk_sp<GrRenderTargetContext> rtc(
|
2019-07-03 15:27:44 +00:00
|
|
|
context->priv().makeDeferredRenderTargetContext(SkBackingFit::kApprox,
|
2019-06-24 19:50:07 +00:00
|
|
|
kFinalWidth,
|
|
|
|
kFinalHeight,
|
|
|
|
GrColorType::kRGBA_8888,
|
|
|
|
nullptr));
|
2017-03-21 11:56:47 +00:00
|
|
|
|
2018-11-05 20:06:26 +00:00
|
|
|
rtc->clear(nullptr, SK_PMColor4fWHITE, GrRenderTargetContext::CanClearFullscreen::kYes);
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
// Note that this doesn't include the third texture proxy
|
|
|
|
for (int i = 0; i < kNumProxies-1; ++i) {
|
|
|
|
SkRect r = SkRect::MakeXYWH(i*3*kDrawnTileSize, 0, 3*kDrawnTileSize, kDrawnTileSize);
|
|
|
|
|
|
|
|
SkMatrix t = SkMatrix::MakeTrans(-i*3*kDrawnTileSize, 0);
|
|
|
|
|
|
|
|
GrPaint paint;
|
2017-10-18 17:15:13 +00:00
|
|
|
auto fp = GrSimpleTextureEffect::Make(std::move(proxies[i]), t);
|
2017-03-21 11:56:47 +00:00
|
|
|
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
|
|
|
|
paint.addColorFragmentProcessor(std::move(fp));
|
|
|
|
|
|
|
|
rtc->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), r);
|
|
|
|
}
|
|
|
|
|
2019-04-17 19:26:11 +00:00
|
|
|
rtc->flush(SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo());
|
2017-03-21 11:56:47 +00:00
|
|
|
|
|
|
|
SkBitmap readBack;
|
|
|
|
readBack.allocN32Pixels(kFinalWidth, kFinalHeight);
|
|
|
|
|
|
|
|
SkDEBUGCODE(bool result =) rtc->readPixels(readBack.info(), readBack.getPixels(),
|
2019-07-01 17:05:28 +00:00
|
|
|
readBack.rowBytes(), {0, 0});
|
2017-03-21 11:56:47 +00:00
|
|
|
SkASSERT(result);
|
|
|
|
|
2019-02-04 18:26:26 +00:00
|
|
|
context->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);
|
|
|
|
}
|