aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-07-25 07:32:33 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-25 07:32:33 -0700
commitc44be0e9e4cee5402909c06370a630eee188a8f3 (patch)
tree1646e237481d61d979143fb57cf87a51cdfcf976 /src/gpu
parent730c0447916909f01df7fa12e9c82dd7cf7989dc (diff)
Merge GrGpuObject and GrCacheable.
We want to create a new base class for "meta" gr resources as part of the GrResourceCache rewrite and this is an iterim step towards that goal.s R=robertphillips@google.com Author: bsalomon@google.com Review URL: https://codereview.chromium.org/414013005
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrAtlas.h3
-rw-r--r--src/gpu/GrCacheable.cpp18
-rwxr-xr-xsrc/gpu/GrContext.cpp12
-rw-r--r--src/gpu/GrGpu.h1
-rw-r--r--src/gpu/GrGpuObject.cpp15
-rw-r--r--src/gpu/GrResourceCache.cpp12
-rw-r--r--src/gpu/GrResourceCache.h20
-rw-r--r--src/gpu/GrStencilAndCoverTextContext.cpp23
8 files changed, 56 insertions, 48 deletions
diff --git a/src/gpu/GrAtlas.h b/src/gpu/GrAtlas.h
index 2248f67b85..9ccbc53bc6 100644
--- a/src/gpu/GrAtlas.h
+++ b/src/gpu/GrAtlas.h
@@ -10,9 +10,10 @@
#define GrAtlas_DEFINED
-#include "SkPoint.h"
#include "GrTexture.h"
#include "GrDrawTarget.h"
+#include "SkPoint.h"
+#include "SkTInternalLList.h"
class GrGpu;
class GrRectanizer;
diff --git a/src/gpu/GrCacheable.cpp b/src/gpu/GrCacheable.cpp
deleted file mode 100644
index 5dc5258117..0000000000
--- a/src/gpu/GrCacheable.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#include "GrCacheable.h"
-
-uint32_t GrCacheable::CreateUniqueID() {
- static int32_t gCacheableID = SK_InvalidUniqueID;
- uint32_t id;
- do {
- id = static_cast<uint32_t>(sk_atomic_inc(&gCacheableID) + 1);
- } while (id == SK_InvalidUniqueID);
- return id;
-}
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index a815263d13..d3edd21e5f 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -257,7 +257,7 @@ GrTexture* GrContext::findAndRefTexture(const GrTextureDesc& desc,
const GrCacheID& cacheID,
const GrTextureParams* params) {
GrResourceKey resourceKey = GrTextureImpl::ComputeKey(fGpu, params, desc, cacheID);
- GrCacheable* resource = fResourceCache->find(resourceKey);
+ GrGpuObject* resource = fResourceCache->find(resourceKey);
SkSafeRef(resource);
return static_cast<GrTexture*>(resource);
}
@@ -283,7 +283,7 @@ GrStencilBuffer* GrContext::findStencilBuffer(int width, int height,
GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(width,
height,
sampleCnt);
- GrCacheable* resource = fResourceCache->find(resourceKey);
+ GrGpuObject* resource = fResourceCache->find(resourceKey);
return static_cast<GrStencilBuffer*>(resource);
}
@@ -471,7 +471,7 @@ GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra
desc.fHeight = SkTMax(MIN_SIZE, GrNextPow2(desc.fHeight));
}
- GrCacheable* resource = NULL;
+ GrGpuObject* resource = NULL;
int origWidth = desc.fWidth;
int origHeight = desc.fHeight;
@@ -1903,13 +1903,13 @@ GrPath* GrContext::createPath(const SkPath& inPath, const SkStrokeRec& stroke) {
return path;
}
-void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrCacheable* resource) {
+void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrGpuObject* resource) {
fResourceCache->purgeAsNeeded(1, resource->gpuMemorySize());
fResourceCache->addResource(resourceKey, resource);
}
-GrCacheable* GrContext::findAndRefCachedResource(const GrResourceKey& resourceKey) {
- GrCacheable* resource = fResourceCache->find(resourceKey);
+GrGpuObject* GrContext::findAndRefCachedResource(const GrResourceKey& resourceKey) {
+ GrGpuObject* resource = fResourceCache->find(resourceKey);
SkSafeRef(resource);
return resource;
}
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index 17b7b697e2..822deb13f0 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -13,7 +13,6 @@
#include "SkPath.h"
class GrContext;
-class GrGpuObject;
class GrIndexBufferAllocPool;
class GrPath;
class GrPathRange;
diff --git a/src/gpu/GrGpuObject.cpp b/src/gpu/GrGpuObject.cpp
index fff2a2fd8f..4a72a50c49 100644
--- a/src/gpu/GrGpuObject.cpp
+++ b/src/gpu/GrGpuObject.cpp
@@ -10,7 +10,10 @@
#include "GrGpuObject.h"
#include "GrGpu.h"
-GrGpuObject::GrGpuObject(GrGpu* gpu, bool isWrapped) {
+GrGpuObject::GrGpuObject(GrGpu* gpu, bool isWrapped)
+ : fRefCnt(1)
+ , fCacheEntry(NULL)
+ , fUniqueID(CreateUniqueID()) {
fGpu = gpu;
if (isWrapped) {
fFlags = kWrapped_FlagBit;
@@ -21,6 +24,7 @@ GrGpuObject::GrGpuObject(GrGpu* gpu, bool isWrapped) {
}
GrGpuObject::~GrGpuObject() {
+ SkASSERT(0 == fRefCnt);
// subclass should have released this.
SkASSERT(this->wasDestroyed());
}
@@ -56,3 +60,12 @@ GrContext* GrGpuObject::getContext() {
return NULL;
}
}
+
+uint32_t GrGpuObject::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;
+}
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index ac10ebc641..13568e4965 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -9,13 +9,13 @@
#include "GrResourceCache.h"
-#include "GrCacheable.h"
+#include "GrGpuObject.h"
DECLARE_SKMESSAGEBUS_MESSAGE(GrResourceInvalidatedMessage);
///////////////////////////////////////////////////////////////////////////////
-void GrCacheable::didChangeGpuMemorySize() const {
+void GrGpuObject::didChangeGpuMemorySize() const {
if (this->isInCache()) {
fCacheEntry->didChangeResourceSize();
}
@@ -38,7 +38,7 @@ GrResourceKey::ResourceType GrResourceKey::GenerateResourceType() {
GrResourceCacheEntry::GrResourceCacheEntry(GrResourceCache* resourceCache,
const GrResourceKey& key,
- GrCacheable* resource)
+ GrGpuObject* resource)
: fResourceCache(resourceCache),
fKey(key),
fResource(resource),
@@ -197,7 +197,7 @@ public:
}
};
-GrCacheable* GrResourceCache::find(const GrResourceKey& key, uint32_t ownershipFlags) {
+GrGpuObject* GrResourceCache::find(const GrResourceKey& key, uint32_t ownershipFlags) {
GrAutoResourceCacheValidate atcv(this);
GrResourceCacheEntry* entry = NULL;
@@ -226,7 +226,7 @@ GrCacheable* GrResourceCache::find(const GrResourceKey& key, uint32_t ownershipF
}
void GrResourceCache::addResource(const GrResourceKey& key,
- GrCacheable* resource,
+ GrGpuObject* resource,
uint32_t ownershipFlags) {
SkASSERT(NULL == resource->getCacheEntry());
// we don't expect to create new resources during a purge. In theory
@@ -285,7 +285,7 @@ void GrResourceCache::makeNonExclusive(GrResourceCacheEntry* entry) {
fExclusiveList.remove(entry);
#endif
- if (entry->resource()->isValidOnGpu()) {
+ if (!entry->resource()->wasDestroyed()) {
// Since scratch textures still count against the cache budget even
// when they have been removed from the cache, re-adding them doesn't
// alter the budget information.
diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h
index ccfe7fa3ad..63a7a67ee5 100644
--- a/src/gpu/GrResourceCache.h
+++ b/src/gpu/GrResourceCache.h
@@ -18,7 +18,7 @@
#include "SkMessageBus.h"
#include "SkTInternalLList.h"
-class GrCacheable;
+class GrGpuObject;
class GrResourceCache;
class GrResourceCacheEntry;
@@ -29,11 +29,11 @@ public:
return gDomain;
}
- /** Uniquely identifies the GrCacheable subclass in the key to avoid collisions
+ /** Uniquely identifies the GrGpuObject subclass in the key to avoid collisions
across resource types. */
typedef uint8_t ResourceType;
- /** Flags set by the GrCacheable subclass. */
+ /** Flags set by the GrGpuObject subclass. */
typedef uint8_t ResourceFlags;
/** Generate a unique ResourceType */
@@ -118,7 +118,7 @@ struct GrResourceInvalidatedMessage {
class GrResourceCacheEntry {
public:
- GrCacheable* resource() const { return fResource; }
+ GrGpuObject* resource() const { return fResource; }
const GrResourceKey& key() const { return fKey; }
static const GrResourceKey& GetKey(const GrResourceCacheEntry& e) { return e.key(); }
@@ -131,7 +131,7 @@ public:
/**
* Update the cached size for this entry and inform the resource cache that
- * it has changed. Usually invoked from GrCacheable::didChangeGpuMemorySize,
+ * it has changed. Usually invoked from GrGpuObject::didChangeGpuMemorySize,
* not directly from here.
*/
void didChangeResourceSize();
@@ -139,12 +139,12 @@ public:
private:
GrResourceCacheEntry(GrResourceCache* resourceCache,
const GrResourceKey& key,
- GrCacheable* resource);
+ GrGpuObject* resource);
~GrResourceCacheEntry();
GrResourceCache* fResourceCache;
GrResourceKey fKey;
- GrCacheable* fResource;
+ GrGpuObject* fResource;
size_t fCachedSize;
bool fIsExclusive;
@@ -157,7 +157,7 @@ private:
///////////////////////////////////////////////////////////////////////////////
/**
- * Cache of GrCacheable objects.
+ * Cache of GrGpuObject objects.
*
* These have a corresponding GrResourceKey, built from 128bits identifying the
* resource. Multiple resources can map to same GrResourceKey.
@@ -246,7 +246,7 @@ public:
* For a resource to be completely exclusive to a caller both kNoOtherOwners
* and kHide must be specified.
*/
- GrCacheable* find(const GrResourceKey& key,
+ GrGpuObject* find(const GrResourceKey& key,
uint32_t ownershipFlags = 0);
/**
@@ -261,7 +261,7 @@ public:
* is called.
*/
void addResource(const GrResourceKey& key,
- GrCacheable* resource,
+ GrGpuObject* resource,
uint32_t ownershipFlags = 0);
/**
diff --git a/src/gpu/GrStencilAndCoverTextContext.cpp b/src/gpu/GrStencilAndCoverTextContext.cpp
index 65c26423d1..0867f2eb91 100644
--- a/src/gpu/GrStencilAndCoverTextContext.cpp
+++ b/src/gpu/GrStencilAndCoverTextContext.cpp
@@ -18,7 +18,7 @@
#include "SkPath.h"
#include "SkTextMapStateProc.h"
-class GrStencilAndCoverTextContext::GlyphPathRange : public GrCacheable {
+class GrStencilAndCoverTextContext::GlyphPathRange : public GrGpuObject {
static const int kMaxGlyphCount = 1 << 16; // Glyph IDs are uint16_t's
static const int kGlyphGroupSize = 16; // Glyphs get tracked in groups of 16
@@ -75,13 +75,13 @@ public:
this->didChangeGpuMemorySize();
}
- // GrCacheable overrides
+ // GrGpuObject overrides
virtual size_t gpuMemorySize() const SK_OVERRIDE { return fPathRange->gpuMemorySize(); }
- virtual bool isValidOnGpu() const SK_OVERRIDE { return fPathRange->isValidOnGpu(); }
private:
GlyphPathRange(GrContext* context, const SkDescriptor& desc, const SkStrokeRec& stroke)
- : fDesc(desc.copy())
+ : INHERITED(context->getGpu(), false)
+ , fDesc(desc.copy())
// We reserve a range of kMaxGlyphCount paths because of fallbacks fonts. We
// can't know exactly how many glyphs we might need without preloading every
// fallback, which we don't want to do at this point.
@@ -90,15 +90,28 @@ private:
}
~GlyphPathRange() {
+ this->release();
SkDescriptor::Free(fDesc);
}
+ virtual void onRelease() SK_OVERRIDE {
+ INHERITED::onRelease();
+ fPathRange.reset(NULL);
+ }
+
+ virtual void onAbandon() SK_OVERRIDE {
+ INHERITED::onAbandon();
+ fPathRange->abandon();
+ fPathRange.reset(NULL);
+ }
+
+
static const int kMaxGroupCount = (kMaxGlyphCount + (kGlyphGroupSize - 1)) / kGlyphGroupSize;
SkDescriptor* const fDesc;
uint8_t fLoadedGlyphs[(kMaxGroupCount + 7) >> 3]; // One bit per glyph group
SkAutoTUnref<GrPathRange> fPathRange;
- typedef GrCacheable INHERITED;
+ typedef GrGpuObject INHERITED;
};