* not change when the content of the GrGpuResource object changes. This will never return
* 0.
*/
- uint32_t getUniqueID() const { return fUniqueID; }
+ uint32_t uniqueID() const { return fUniqueID; }
/** Returns the current unique key for the resource. It will be invalid if the resource has no
associated unique key. */
**/
virtual void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
+ static uint32_t CreateUniqueID();
+
protected:
// This must be called by every non-wrapped GrGpuObject. It should be called once the object is
// fully initialized (i.e. only from the constructors of the final class).
#ifdef SK_DEBUG
friend class GrGpu; // for assert in GrGpu to access getGpu
#endif
-
- static uint32_t CreateUniqueID();
-
// An index into a heap when this resource is purgeable or an array when not. This is maintained
// by the cache.
int fCacheArrayIndex;
virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; }
protected:
+ // Deferred version
GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted)
: fDesc(desc)
, fFit(fit)
, fBudgeted(budgeted)
- , fUniqueID(CreateUniqueID()) {
+ , fUniqueID(GrGpuResource::CreateUniqueID()) {
+ }
+
+ // Wrapped version
+ GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit,
+ SkBudgeted budgeted, uint32_t uniqueID)
+ : fDesc(desc)
+ , fFit(fit)
+ , fBudgeted(budgeted)
+ , fUniqueID(uniqueID) {
}
virtual ~GrSurfaceProxy() {}
const GrSurfaceDesc fDesc;
const SkBackingFit fFit; // always exact for wrapped resources
const SkBudgeted fBudgeted; // set from the backing resource for wrapped resources
- const uint32_t fUniqueID;
+ const uint32_t fUniqueID; // set from the backing resource for wrapped resources
private:
- static uint32_t CreateUniqueID();
// See comment in GrGpuResource.h.
void notifyAllCntsAreZero(CntType) const { delete this; }
GrTexture* instantiate(GrTextureProvider* texProvider);
private:
- GrTextureProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted,
- const void* /*srcData*/, size_t /*rowBytes*/)
- : INHERITED(desc, fit, budgeted) {
- // TODO: Handle 'srcData' here
- }
-
+ // Deferred version
+ GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit, SkBudgeted,
+ const void* srcData, size_t srcRowBytes);
// Wrapped version
GrTextureProxy(sk_sp<GrTexture> tex);
#ifdef SK_DEBUG
void GrDrawTarget::dump() const {
SkDebugf("--------------------------------------------------------------\n");
- SkDebugf("node: %d -> RT: %d\n", fDebugID, fRenderTarget ? fRenderTarget->getUniqueID() : -1);
+ SkDebugf("node: %d -> RT: %d\n", fDebugID, fRenderTarget ? fRenderTarget->uniqueID() : -1);
SkDebugf("relies On (%d): ", fDependencies.count());
for (int i = 0; i < fDependencies.count(); ++i) {
SkDebugf("%d, ", fDependencies[i]->fDebugID);
// remove all the previously recorded batches and change the load op to clear with supplied
// color.
if (fLastFullClearBatch &&
- fLastFullClearBatch->renderTargetUniqueID() == renderTarget->getUniqueID()) {
+ fLastFullClearBatch->renderTargetUniqueID() == renderTarget->uniqueID()) {
// As currently implemented, fLastFullClearBatch should be the last batch because we would
// have cleared it when another batch was recorded.
SkASSERT(fRecordedBatches.back().fBatch.get() == fLastFullClearBatch);
void GrGpuResource::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
// Dump resource as "skia/gpu_resources/resource_#".
SkString dumpName("skia/gpu_resources/resource_");
- dumpName.appendS32(this->getUniqueID());
+ dumpName.appendS32(this->uniqueID());
traceMemoryDump->dumpNumericValue(dumpName.c_str(), "size", "bytes", this->gpuMemorySize());
// Wrapped version
GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, sk_sp<GrRenderTarget> rt)
- : INHERITED(rt->desc(), SkBackingFit::kExact, rt->resourcePriv().isBudgeted())
+ : INHERITED(rt->desc(), SkBackingFit::kExact,
+ rt->resourcePriv().isBudgeted(), rt->uniqueID())
, fTarget(std::move(rt))
, fFlags(fTarget->renderTargetPriv().flags())
, fLastDrawTarget(nullptr) {
#include "GrSurfaceProxy.h"
-#include "SkAtomics.h"
-
-uint32_t GrSurfaceProxy::CreateUniqueID() {
- static int32_t gUniqueID = SK_InvalidUniqueID;
- uint32_t id;
- do {
- id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
- } while (id == SK_InvalidUniqueID);
- return id;
-}
#include "GrTextureProvider.h"
#include "GrGpuResourcePriv.h"
+GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit fit, SkBudgeted budgeted,
+ const void* /*srcData*/, size_t /*rowBytes*/)
+ : INHERITED(srcDesc, fit, budgeted) {
+ // TODO: Handle 'srcData' here
+}
+
GrTextureProxy::GrTextureProxy(sk_sp<GrTexture> tex)
- : INHERITED(tex->desc(), SkBackingFit::kExact, tex->resourcePriv().isBudgeted())
+ : INHERITED(tex->desc(), SkBackingFit::kExact,
+ tex->resourcePriv().isBudgeted(), tex->uniqueID())
, fTexture(std::move(tex)) {
}
const char* name() const override { return "Clear"; }
- uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->getUniqueID(); }
+ uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->uniqueID(); }
GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); }
SkString dumpInfo() const override {
const SkIRect& r = fClip.scissorRect();
string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom);
}
- string.appendf("], Color: 0x%08x, RT: %d", fColor, fRenderTarget.get()->getUniqueID());
+ string.appendf("], Color: 0x%08x, RT: %d", fColor, fRenderTarget.get()->uniqueID());
string.append(INHERITED::dumpInfo());
return string;
}
const char* name() const override { return "ClearStencilClip"; }
- uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->getUniqueID(); }
+ uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->uniqueID(); }
GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); }
SkString dumpInfo() const override {
const SkIRect& r = fClip.scissorRect();
string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom);
}
- string.appendf("], IC: %d, RT: %d", fInsideStencilMask, fRenderTarget.get()->getUniqueID());
+ string.appendf("], IC: %d, RT: %d", fInsideStencilMask, fRenderTarget.get()->uniqueID());
string.append(INHERITED::dumpInfo());
return string;
}
uint32_t renderTargetUniqueID() const override {
GrRenderTarget* rt = fDst.get()->asRenderTarget();
- return rt ? rt->getUniqueID() : 0;
+ return rt ? rt->uniqueID() : 0;
}
GrRenderTarget* renderTarget() const override { return nullptr; }
const char* name() const override { return "Discard"; }
- uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->getUniqueID(); }
+ uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->uniqueID(); }
GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); }
SkString dumpInfo() const override {
SkString string;
- string.printf("RT: %d", fRenderTarget.get()->getUniqueID());
+ string.printf("RT: %d", fRenderTarget.get()->uniqueID());
string.append(INHERITED::dumpInfo());
return string;
}
uint32_t renderTargetUniqueID() const final {
SkASSERT(fPipelineInstalled);
- return this->pipeline()->getRenderTarget()->getUniqueID();
+ return this->pipeline()->getRenderTarget()->uniqueID();
}
GrRenderTarget* renderTarget() const final {
const char* name() const override { return "StencilPath"; }
- uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->getUniqueID(); }
+ uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->uniqueID(); }
GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); }
SkString dumpInfo() const override {
SkString dumpInfo() const override {
SkString str;
- str.appendf("Texture: %d", fTextureAccess.getTexture()->getUniqueID());
+ str.appendf("Texture: %d", fTextureAccess.getTexture()->uniqueID());
return str;
}
SkASSERT(type >= 0 && type <= kLast_GrBufferType);
auto& bufferState = fHWBufferState[type];
- if (buffer->getUniqueID() != bufferState.fBoundBufferUniqueID) {
+ if (buffer->uniqueID() != bufferState.fBoundBufferUniqueID) {
if (buffer->isCPUBacked()) {
if (!bufferState.fBufferZeroKnownBound) {
GL_CALL(BindBuffer(bufferState.fGLTarget, 0));
GL_CALL(BindBuffer(bufferState.fGLTarget, glBuffer->bufferID()));
}
bufferState.fBufferZeroKnownBound = buffer->isCPUBacked();
- bufferState.fBoundBufferUniqueID = buffer->getUniqueID();
+ bufferState.fBoundBufferUniqueID = buffer->uniqueID();
}
return bufferState.fGLTarget;
void GrGLGpu::notifyBufferReleased(const GrGLBuffer* buffer) {
if (buffer->hasAttachedToTexture()) {
// Detach this buffer from any textures to ensure the underlying memory is freed.
- uint32_t uniqueID = buffer->getUniqueID();
+ uint32_t uniqueID = buffer->uniqueID();
for (int i = fHWMaxUsedBufferTextureUnit; i >= 0; --i) {
auto& buffTex = fHWBufferTextures[i];
if (uniqueID != buffTex.fAttachedBufferUniqueID) {
void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bounds, bool disableSRGB) {
SkASSERT(target);
- uint32_t rtID = target->getUniqueID();
+ uint32_t rtID = target->uniqueID();
if (fHWBoundRenderTargetUniqueID != rtID) {
fStats.incRenderTargetBinds();
GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, target->renderFBOID()));
this->onResolveRenderTarget(texRT);
}
- uint32_t textureID = texture->getUniqueID();
+ uint32_t textureID = texture->uniqueID();
GrGLenum target = texture->target();
if (fHWBoundTextureUniqueIDs[unitIdx] != textureID) {
this->setTextureUnit(unitIdx);
buffTex.fKnownBound = true;
}
- if (buffer->getUniqueID() != buffTex.fAttachedBufferUniqueID ||
+ if (buffer->uniqueID() != buffTex.fAttachedBufferUniqueID ||
buffTex.fTexelConfig != texelConfig) {
this->setTextureUnit(unitIdx);
buffer->bufferID()));
buffTex.fTexelConfig = texelConfig;
- buffTex.fAttachedBufferUniqueID = buffer->getUniqueID();
+ buffTex.fAttachedBufferUniqueID = buffer->uniqueID();
if (this->glCaps().textureSwizzleSupport() &&
this->glCaps().configSwizzle(texelConfig) != buffTex.fSwizzle) {
// Due to this resource having both a texture and a renderbuffer component, dump as
// skia/gpu_resources/resource_#/renderbuffer
SkString dumpName("skia/gpu_resources/resource_");
- dumpName.appendS32(this->getUniqueID());
+ dumpName.appendS32(this->uniqueID());
dumpName.append("/renderbuffer");
traceMemoryDump->dumpNumericValue(dumpName.c_str(), "size", "bytes", size);
// texture and a
// renderbuffer component, dump as skia/gpu_resources/resource_#/texture
SkString dumpName("skia/gpu_resources/resource_");
- dumpName.appendS32(this->getUniqueID());
+ dumpName.appendS32(this->uniqueID());
dumpName.append("/texture");
// Use the texture's gpuMemorySize, not our own, which includes the
array->fEnableIsValid = true;
array->fEnabled = true;
}
- if (array->fVertexBufferUniqueID != vertexBuffer->getUniqueID() ||
+ if (array->fVertexBufferUniqueID != vertexBuffer->uniqueID() ||
array->fType != type ||
array->fStride != stride ||
array->fOffset != offset) {
stride,
offset));
}
- array->fVertexBufferUniqueID = vertexBuffer->getUniqueID();
+ array->fVertexBufferUniqueID = vertexBuffer->uniqueID();
array->fType = type;
array->fStride = stride;
array->fOffset = offset;
GrGLAttribArrayState* GrGLVertexArray::bindWithIndexBuffer(GrGLGpu* gpu, const GrBuffer* ibuff) {
GrGLAttribArrayState* state = this->bind(gpu);
- if (state && fIndexBufferUniqueID != ibuff->getUniqueID()) {
+ if (state && fIndexBufferUniqueID != ibuff->uniqueID()) {
if (ibuff->isCPUBacked()) {
GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, 0));
} else {
GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER,
glBuffer->bufferID()));
}
- fIndexBufferUniqueID = ibuff->getUniqueID();
+ fIndexBufferUniqueID = ibuff->uniqueID();
}
return state;
}
this->glGpu()->bindVertexArray(fVertexArrayID);
SkASSERT(fInstanceBuffer);
- if (fInstanceAttribsBufferUniqueId != fInstanceBuffer->getUniqueID() ||
+ if (fInstanceAttribsBufferUniqueId != fInstanceBuffer->uniqueID() ||
fInstanceAttribsBaseInstance != baseInstance) {
Instance* offsetInBuffer = (Instance*) nullptr + baseInstance;
sizeof(Instance), &offsetInBuffer->fLocalRect));
GL_CALL(VertexAttribDivisor((int)Attrib::kLocalRect, 1));
- fInstanceAttribsBufferUniqueId = fInstanceBuffer->getUniqueID();
+ fInstanceAttribsBufferUniqueId = fInstanceBuffer->uniqueID();
fInstanceAttribsBaseInstance = baseInstance;
}
}
);
SkAutoTUnref<GrPathRange> glyphs(this->createGlyphs(ctx));
- if (fLastDrawnGlyphsID != glyphs->getUniqueID()) {
+ if (fLastDrawnGlyphsID != glyphs->uniqueID()) {
// Either this is the first draw or the glyphs object was purged since last draw.
glyphs->loadPathsIfNeeded(fInstanceData->indices(), fInstanceData->count());
- fLastDrawnGlyphsID = glyphs->getUniqueID();
+ fLastDrawnGlyphsID = glyphs->uniqueID();
}
// Don't compute a bounding box. For dst copy texture, we'll opt instead for it to just copy
static bool reset_dc(sk_sp<GrDrawContext>* dc, GrContext* context, int w, int h) {
SkDEBUGCODE(uint32_t oldID = 0;)
if (*dc) {
- SkDEBUGCODE(oldID = (*dc)->accessRenderTarget()->getUniqueID();)
+ SkDEBUGCODE(oldID = (*dc)->accessRenderTarget()->uniqueID();)
dc->reset(nullptr);
}
context->freeGpuResources();
*dc = context->makeDrawContext(SkBackingFit::kExact, w, h, kRGBA_8888_GrPixelConfig, nullptr);
- SkASSERT((*dc)->accessRenderTarget()->getUniqueID() != oldID);
+ SkASSERT((*dc)->accessRenderTarget()->uniqueID() != oldID);
return *dc != nullptr;
}
#include "GrTextureProxy.h"
#include "GrRenderTargetProxy.h"
+// Check that the surface proxy's member vars are set as expected
static void check_surface(skiatest::Reporter* reporter,
GrSurfaceProxy* proxy,
GrSurfaceOrigin origin,
int width, int height,
- GrPixelConfig config) {
+ GrPixelConfig config,
+ uint32_t uniqueID) {
REPORTER_ASSERT(reporter, proxy->origin() == origin);
REPORTER_ASSERT(reporter, proxy->width() == width);
REPORTER_ASSERT(reporter, proxy->height() == height);
REPORTER_ASSERT(reporter, proxy->config() == config);
+ if (SK_InvalidUniqueID != uniqueID) {
+ REPORTER_ASSERT(reporter, proxy->uniqueID() == uniqueID);
+ }
}
static void check_rendertarget(skiatest::Reporter* reporter,
}
-DEF_GPUTEST_FOR_RENDERING_CONTEXTS(AllocedProxyTest, reporter, ctxInfo) {
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
fit,
budgeted));
check_surface(reporter, rtProxy.get(), origin,
- widthHeight, widthHeight, config);
+ widthHeight, widthHeight, config, SK_InvalidUniqueID);
check_rendertarget(reporter, provider, rtProxy.get(), fit);
}
fit,
budgeted));
check_surface(reporter, texProxy.get(), origin,
- widthHeight, widthHeight, config);
+ widthHeight, widthHeight, config, SK_InvalidUniqueID);
check_texture(reporter, provider, texProxy.get(), fit);
}
}
sk_sp<GrRenderTargetProxy> rtProxy(
GrRenderTargetProxy::Make(caps, defaultFBO));
check_surface(reporter, rtProxy.get(), origin,
- kWidthHeight, kWidthHeight, config);
+ kWidthHeight, kWidthHeight, config, defaultFBO->uniqueID());
check_rendertarget(reporter, provider, rtProxy.get(), SkBackingFit::kExact);
}
sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(caps, rt));
check_surface(reporter, rtProxy.get(), origin,
- kWidthHeight, kWidthHeight, config);
+ kWidthHeight, kWidthHeight, config, rt->uniqueID());
check_rendertarget(reporter, provider, rtProxy.get(), SkBackingFit::kExact);
}
sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(tex));
check_surface(reporter, texProxy.get(), origin,
- kWidthHeight, kWidthHeight, config);
+ kWidthHeight, kWidthHeight, config, tex->uniqueID());
check_texture(reporter, provider, texProxy.get(), SkBackingFit::kExact);
}
}
// Call all the public methods on resource in the abandoned state. They shouldn't crash.
- resource->getUniqueID();
+ resource->uniqueID();
resource->getUniqueKey();
resource->wasDestroyed();
resource->gpuMemorySize();
ERRORF(reporter, "Not texture backed.");
return static_cast<intptr_t>(0);
}
- return static_cast<intptr_t>(texture->getUniqueID());
+ return static_cast<intptr_t>(texture->uniqueID());
};
auto surfaceBackingStore = [reporter](SkSurface* surface) {
ERRORF(reporter, "Not render target backed.");
return static_cast<intptr_t>(0);
}
- return static_cast<intptr_t>(rt->getUniqueID());
+ return static_cast<intptr_t>(rt->uniqueID());
};
test_unique_image_snap(reporter, surface.get(), false, imageBackingStore,
// get the render target of the top device so we can ignore batches drawn offscreen
SkBaseDevice* bd = canvas->getDevice_just_for_deprecated_compatibility_testing();
SkGpuDevice* gbd = reinterpret_cast<SkGpuDevice*>(bd);
- uint32_t rtID = gbd->accessDrawContext()->accessRenderTarget()->getUniqueID();
+ uint32_t rtID = gbd->accessDrawContext()->accessRenderTarget()->uniqueID();
// get the bounding boxes to draw
SkTArray<GrAuditTrail::BatchInfo> childrenBounds;