aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2018-06-13 09:41:19 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-13 18:06:56 +0000
commitda86e2822ab31770e989009716dd4c89966ade45 (patch)
tree66a8fe4ff7e07bd7003f317d0b29a39ebf411790
parente141548696bd049b0e520391ff64e64e4e02c55f (diff)
Remove unused code that was used for late mip allocations.
This also includes removing code to support changing GrGpuResource's size since we now have to way to ever change the size. Bug: skia: Change-Id: Id27a8bc3cc94f5b954beda528b209727ede10ef6 Reviewed-on: https://skia-review.googlesource.com/134503 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
-rw-r--r--include/gpu/GrGpuResource.h6
-rw-r--r--src/gpu/GrGpuResource.cpp11
-rw-r--r--src/gpu/GrResourceCache.cpp23
-rw-r--r--src/gpu/GrResourceCache.h8
-rw-r--r--src/gpu/GrTexturePriv.h4
-rw-r--r--src/gpu/gl/GrGLGpu.cpp25
-rw-r--r--src/gpu/vk/GrVkGpu.cpp53
-rw-r--r--src/gpu/vk/GrVkTexture.cpp67
-rw-r--r--src/gpu/vk/GrVkTexture.h2
-rw-r--r--tests/ResourceCacheTest.cpp168
10 files changed, 41 insertions, 326 deletions
diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h
index 2da8085908..38545dd821 100644
--- a/include/gpu/GrGpuResource.h
+++ b/include/gpu/GrGpuResource.h
@@ -283,12 +283,6 @@ protected:
virtual void onAbandon() { }
/**
- * This entry point should be called whenever gpuMemorySize() should report a different size.
- * The cache will call gpuMemorySize() to update the current size of the resource.
- */
- void didChangeGpuMemorySize() const;
-
- /**
* Allows subclasses to add additional backing information to the SkTraceMemoryDump.
**/
virtual void setMemoryBacking(SkTraceMemoryDump*, const SkString&) const {}
diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp
index ec7113562b..27e0e4ab74 100644
--- a/src/gpu/GrGpuResource.cpp
+++ b/src/gpu/GrGpuResource.cpp
@@ -118,17 +118,6 @@ GrContext* GrGpuResource::getContext() {
}
}
-void GrGpuResource::didChangeGpuMemorySize() const {
- if (this->wasDestroyed()) {
- return;
- }
-
- size_t oldSize = fGpuMemorySize;
- SkASSERT(kInvalidGpuMemorySize != oldSize);
- fGpuMemorySize = kInvalidGpuMemorySize;
- get_resource_cache(fGpu)->resourceAccess().didChangeGpuMemorySize(this, oldSize);
-}
-
void GrGpuResource::removeUniqueKey() {
if (this->wasDestroyed()) {
return;
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index 8e41ba69a7..2e072533a2 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -413,29 +413,6 @@ void GrResourceCache::notifyCntReachedZero(GrGpuResource* resource, uint32_t fla
this->validate();
}
-void GrResourceCache::didChangeGpuMemorySize(const GrGpuResource* resource, size_t oldSize) {
- SkASSERT(resource);
- SkASSERT(this->isInCache(resource));
-
- ptrdiff_t delta = resource->gpuMemorySize() - oldSize;
-
- fBytes += delta;
-#if GR_CACHE_STATS
- fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes);
-#endif
- if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) {
- fBudgetedBytes += delta;
- TRACE_COUNTER2("skia.gpu.cache", "skia budget", "used",
- fBudgetedBytes, "free", fMaxBytes - fBudgetedBytes);
-#if GR_CACHE_STATS
- fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes);
-#endif
- }
-
- this->purgeAsNeeded();
- this->validate();
-}
-
void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) {
SkASSERT(resource);
SkASSERT(this->isInCache(resource));
diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h
index b91e664d18..771b13fb26 100644
--- a/src/gpu/GrResourceCache.h
+++ b/src/gpu/GrResourceCache.h
@@ -265,7 +265,6 @@ private:
void insertResource(GrGpuResource*);
void removeResource(GrGpuResource*);
void notifyCntReachedZero(GrGpuResource*, uint32_t flags);
- void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize);
void changeUniqueKey(GrGpuResource*, const GrUniqueKey&);
void removeUniqueKey(GrGpuResource*);
void willRemoveScratchKey(const GrGpuResource*);
@@ -413,13 +412,6 @@ private:
}
/**
- * Called by GrGpuResources when their sizes change.
- */
- void didChangeGpuMemorySize(const GrGpuResource* resource, size_t oldSize) {
- fCache->didChangeGpuMemorySize(resource, oldSize);
- }
-
- /**
* Called by GrGpuResources to change their unique keys.
*/
void changeUniqueKey(GrGpuResource* resource, const GrUniqueKey& newKey) {
diff --git a/src/gpu/GrTexturePriv.h b/src/gpu/GrTexturePriv.h
index 2979e8bd94..1cdd2dc9f5 100644
--- a/src/gpu/GrTexturePriv.h
+++ b/src/gpu/GrTexturePriv.h
@@ -36,10 +36,6 @@ public:
return GrMipMapped::kNo;
}
- void setMaxMipMapLevel(int maxMipMapLevel) const {
- fTexture->fMaxMipMapLevel = maxMipMapLevel;
- }
-
int maxMipMapLevel() const {
return fTexture->fMaxMipMapLevel;
}
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 3e2c1b48b8..2c7d977659 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -2905,8 +2905,6 @@ void GrGLGpu::generateMipmaps(const GrSamplerState& params, GrGLTexture* texture
}
texture->texturePriv().markMipMapsClean();
- texture->texturePriv().setMaxMipMapLevel(SkMipMap::ComputeLevelCount(
- texture->width(), texture->height()));
// We have potentially set lots of state on the texture. Easiest to dirty it all:
texture->textureParamsModified();
@@ -3849,28 +3847,7 @@ bool GrGLGpu::generateMipmap(GrGLTexture* texture, GrSurfaceOrigin textureOrigin
int width = texture->width();
int height = texture->height();
int levelCount = SkMipMap::ComputeLevelCount(width, height) + 1;
-
- // Define all mips, if we haven't previously done so:
- if (0 == texture->texturePriv().maxMipMapLevel()) {
- GrGLenum internalFormat;
- GrGLenum externalFormat;
- GrGLenum externalType;
- if (!this->glCaps().getTexImageFormats(texture->config(), texture->config(),
- &internalFormat, &externalFormat, &externalType)) {
- return false;
- }
-
- this->unbindCpuToGpuXferBuffer();
-
- for (GrGLint level = 1; level < levelCount; ++level) {
- // Define the next mip:
- width = SkTMax(1, width / 2);
- height = SkTMax(1, height / 2);
- GL_ALLOC_CALL(this->glInterface(), TexImage2D(GR_GL_TEXTURE_2D, level, internalFormat,
- width, height, 0,
- externalFormat, externalType, nullptr));
- }
- }
+ SkASSERT(levelCount == texture->texturePriv().maxMipMapLevel() + 1);
// Create (if necessary), then bind temporary FBO:
if (0 == fTempDstFBOID) {
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index a99931188d..346d95b0c2 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -359,12 +359,7 @@ bool GrVkGpu::onWritePixels(GrSurface* surface, int left, int top, int width, in
success = this->uploadTexDataLinear(vkTex, left, top, width, height, srcColorType,
texels[0].fPixels, texels[0].fRowBytes);
} else {
- int currentMipLevels = vkTex->texturePriv().maxMipMapLevel() + 1;
- if (mipLevelCount > currentMipLevels) {
- if (!vkTex->reallocForMipmap(this, mipLevelCount)) {
- return false;
- }
- }
+ SkASSERT(mipLevelCount <= vkTex->texturePriv().maxMipMapLevel() + 1);
success = this->uploadTexDataOptimal(vkTex, left, top, width, height, srcColorType, texels,
mipLevelCount);
}
@@ -932,49 +927,11 @@ void GrVkGpu::generateMipmap(GrVkTexture* tex, GrSurfaceOrigin texOrigin) {
// SkMipMap doesn't include the base level in the level count so we have to add 1
uint32_t levelCount = SkMipMap::ComputeLevelCount(tex->width(), tex->height()) + 1;
- if (levelCount != tex->mipLevels()) {
- const GrVkResource* oldResource = tex->resource();
- oldResource->ref();
- // grab handle to the original image resource
- VkImage oldImage = tex->image();
-
- // change the original image's layout so we can copy from it
- tex->setImageLayout(this, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
- VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, false);
-
- if (!tex->reallocForMipmap(this, levelCount)) {
- oldResource->unref(this);
- return;
- }
- // change the new image's layout so we can blit to it
- tex->setImageLayout(this, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
- VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, false);
+ SkASSERT(levelCount == tex->mipLevels());
- // Blit original image to top level of new image
- blitRegion.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 };
- blitRegion.srcOffsets[0] = { 0, 0, 0 };
- blitRegion.srcOffsets[1] = { width, height, 1 };
- blitRegion.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 };
- blitRegion.dstOffsets[0] = { 0, 0, 0 };
- blitRegion.dstOffsets[1] = { width, height, 1 };
-
- fCurrentCmdBuffer->blitImage(this,
- oldResource,
- oldImage,
- VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
- tex->resource(),
- tex->image(),
- VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
- 1,
- &blitRegion,
- VK_FILTER_LINEAR);
-
- oldResource->unref(this);
- } else {
- // change layout of the layers so we can write to them.
- tex->setImageLayout(this, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
- VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, false);
- }
+ // change layout of the layers so we can write to them.
+ tex->setImageLayout(this, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
+ VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, false);
// setup memory barrier
SkASSERT(GrVkFormatIsSupported(tex->imageFormat()));
diff --git a/src/gpu/vk/GrVkTexture.cpp b/src/gpu/vk/GrVkTexture.cpp
index c4c7a8f1e1..1f1d1bbc1a 100644
--- a/src/gpu/vk/GrVkTexture.cpp
+++ b/src/gpu/vk/GrVkTexture.cpp
@@ -160,70 +160,3 @@ const GrVkImageView* GrVkTexture::textureView() {
return fTextureView;
}
-bool GrVkTexture::reallocForMipmap(GrVkGpu* gpu, uint32_t mipLevels) {
- if (mipLevels == 1) {
- // don't need to do anything for a 1x1 texture
- return false;
- }
-
- const GrVkResource* oldResource = this->resource();
-
- // We shouldn't realloc something that doesn't belong to us
- if (fIsBorrowed) {
- return false;
- }
-
- bool renderTarget = SkToBool(this->asRenderTarget());
-
- VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT;
- if (renderTarget) {
- usageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
- }
- usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
-
- GrVkImage::ImageDesc imageDesc;
- imageDesc.fImageType = VK_IMAGE_TYPE_2D;
- imageDesc.fFormat = fInfo.fFormat;
- imageDesc.fWidth = this->width();
- imageDesc.fHeight = this->height();
- imageDesc.fLevels = mipLevels;
- imageDesc.fSamples = 1;
- imageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL;
- imageDesc.fUsageFlags = usageFlags;
- imageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
-
- GrVkImageInfo info;
- if (!GrVkImage::InitImageInfo(gpu, imageDesc, &info)) {
- return false;
- }
-
- // have to create a new image view for new resource
- const GrVkImageView* oldView = fTextureView;
- VkImage image = info.fImage;
- const GrVkImageView* textureView = GrVkImageView::Create(gpu, image, info.fFormat,
- GrVkImageView::kColor_Type, mipLevels);
- if (!textureView) {
- GrVkImage::DestroyImageInfo(gpu, &info);
- return false;
- }
-
- if (renderTarget) {
- GrVkTextureRenderTarget* texRT = static_cast<GrVkTextureRenderTarget*>(this);
- if (!texRT->updateForMipmap(gpu, info)) {
- GrVkImage::DestroyImageInfo(gpu, &info);
- return false;
- }
- }
-
- oldResource->unref(gpu);
- oldView->unref(gpu);
-
- this->setNewResource(info.fImage, info.fAlloc, info.fImageTiling);
- fTextureView = textureView;
- fInfo = info;
- this->updateImageLayout(info.fImageLayout);
- // SetMaxMipMapLevel stores the max level not the number of levels
- this->texturePriv().setMaxMipMapLevel(mipLevels-1);
-
- return true;
-}
diff --git a/src/gpu/vk/GrVkTexture.h b/src/gpu/vk/GrVkTexture.h
index 91ed671c12..c6f7c277bb 100644
--- a/src/gpu/vk/GrVkTexture.h
+++ b/src/gpu/vk/GrVkTexture.h
@@ -35,8 +35,6 @@ public:
const GrVkImageView* textureView();
- bool reallocForMipmap(GrVkGpu* gpu, uint32_t mipLevels);
-
// In Vulkan we call the release proc after we are finished with the underlying
// GrVkImage::Resource object (which occurs after the GPU has finsihed all work on it).
void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index aee64842a9..b6ccd515c2 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -274,8 +274,8 @@ public:
}
static TestResource* CreateScratch(GrGpu* gpu, SkBudgeted budgeted,
- SimulatedProperty property) {
- return new TestResource(gpu, budgeted, property, kScratchConstructor);
+ SimulatedProperty property, size_t size = kDefaultSize) {
+ return new TestResource(gpu, budgeted, property, kScratchConstructor, size);
}
static TestResource* CreateWrapped(GrGpu* gpu, size_t size = kDefaultSize) {
return new TestResource(gpu, size);
@@ -286,11 +286,6 @@ public:
SkSafeUnref(fToDelete);
}
- void setSize(size_t size) {
- fSize = size;
- this->didChangeGpuMemorySize();
- }
-
static int NumAlive() { return fNumAlive; }
void setUnrefWhenDestroyed(TestResource* resource) {
@@ -311,10 +306,11 @@ public:
private:
static const int kScratchKeyFieldCnt = 6;
- TestResource(GrGpu* gpu, SkBudgeted budgeted, SimulatedProperty property, ScratchConstructor)
+ TestResource(GrGpu* gpu, SkBudgeted budgeted, SimulatedProperty property, ScratchConstructor,
+ size_t size = kDefaultSize)
: INHERITED(gpu)
, fToDelete(nullptr)
- , fSize(kDefaultSize)
+ , fSize(size)
, fProperty(property)
, fIsScratch(true) {
++fNumAlive;
@@ -376,14 +372,10 @@ static void test_no_key(skiatest::Reporter* reporter) {
GrGpu* gpu = context->contextPriv().getGpu();
// Create a bunch of resources with no keys
- TestResource* a = new TestResource(gpu);
- TestResource* b = new TestResource(gpu);
- TestResource* c = new TestResource(gpu);
- TestResource* d = new TestResource(gpu);
- a->setSize(11);
- b->setSize(12);
- c->setSize(13);
- d->setSize(14);
+ TestResource* a = new TestResource(gpu, SkBudgeted::kYes, 11);
+ TestResource* b = new TestResource(gpu, SkBudgeted::kYes, 12);
+ TestResource* c = new TestResource(gpu, SkBudgeted::kYes, 13 );
+ TestResource* d = new TestResource(gpu, SkBudgeted::kYes, 14 );
REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive());
REPORTER_ASSERT(reporter, 4 == cache->getResourceCount());
@@ -435,27 +427,23 @@ static void test_purge_unlocked(skiatest::Reporter* reporter) {
// Create two resource w/ a unique key and two w/o but all of which have scratch keys.
TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
- TestResource::kA_SimulatedProperty);
- a->setSize(11);
+ TestResource::kA_SimulatedProperty, 11);
GrUniqueKey uniqueKey;
make_unique_key<0>(&uniqueKey, 0);
TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
- TestResource::kA_SimulatedProperty);
- b->setSize(12);
+ TestResource::kA_SimulatedProperty, 12);
b->resourcePriv().setUniqueKey(uniqueKey);
TestResource* c = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
- TestResource::kA_SimulatedProperty);
- c->setSize(13);
+ TestResource::kA_SimulatedProperty, 13);
GrUniqueKey uniqueKey2;
make_unique_key<0>(&uniqueKey2, 1);
TestResource* d = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
- TestResource::kA_SimulatedProperty);
- d->setSize(14);
+ TestResource::kA_SimulatedProperty, 14);
d->resourcePriv().setUniqueKey(uniqueKey2);
@@ -506,15 +494,12 @@ static void test_budgeting(skiatest::Reporter* reporter) {
// Create a scratch, a unique, and a wrapped resource
TestResource* scratch =
- TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty);
- scratch->setSize(10);
- TestResource* unique = new TestResource(gpu);
- unique->setSize(11);
+ TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty,
+ 10);
+ TestResource* unique = new TestResource(gpu, SkBudgeted::kYes, 11);
unique->resourcePriv().setUniqueKey(uniqueKey);
- TestResource* wrapped = TestResource::CreateWrapped(gpu);
- wrapped->setSize(12);
- TestResource* unbudgeted = new TestResource(gpu, SkBudgeted::kNo);
- unbudgeted->setSize(13);
+ TestResource* wrapped = TestResource::CreateWrapped(gpu, 12);
+ TestResource* unbudgeted = new TestResource(gpu, SkBudgeted::kNo, 13);
// Make sure we can add a unique key to the wrapped resource
GrUniqueKey uniqueKey2;
@@ -556,7 +541,6 @@ static void test_budgeting(skiatest::Reporter* reporter) {
// Now try freeing the budgeted resources first
wrapped = TestResource::CreateWrapped(gpu);
- scratch->setSize(12);
unique->unref();
REPORTER_ASSERT(reporter, 11 == cache->getPurgeableBytes());
cache->purgeAllUnlocked();
@@ -568,7 +552,7 @@ static void test_budgeting(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
scratch->unref();
- REPORTER_ASSERT(reporter, 12 == cache->getPurgeableBytes());
+ REPORTER_ASSERT(reporter, 10 == cache->getPurgeableBytes());
cache->purgeAllUnlocked();
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() + wrapped->gpuMemorySize() ==
@@ -608,9 +592,8 @@ static void test_unbudgeted(skiatest::Reporter* reporter) {
// A large uncached or wrapped resource shouldn't evict anything.
scratch = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
- TestResource::kB_SimulatedProperty);
+ TestResource::kB_SimulatedProperty, 10);
- scratch->setSize(10);
scratch->unref();
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
REPORTER_ASSERT(reporter, 10 == cache->getResourceBytes());
@@ -618,8 +601,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, 10 == cache->getBudgetedResourceBytes());
REPORTER_ASSERT(reporter, 10 == cache->getPurgeableBytes());
- unique = new TestResource(gpu);
- unique->setSize(11);
+ unique = new TestResource(gpu, SkBudgeted::kYes, 11);
unique->resourcePriv().setUniqueKey(uniqueKey);
unique->unref();
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
@@ -740,12 +722,10 @@ static void test_duplicate_scratch_key(skiatest::Reporter* reporter) {
// Create two resources that have the same scratch key.
TestResource* a = TestResource::CreateScratch(gpu,
SkBudgeted::kYes,
- TestResource::kB_SimulatedProperty);
+ TestResource::kB_SimulatedProperty, 11);
TestResource* b = TestResource::CreateScratch(gpu,
SkBudgeted::kYes,
- TestResource::kB_SimulatedProperty);
- a->setSize(11);
- b->setSize(12);
+ TestResource::kB_SimulatedProperty, 12);
GrScratchKey scratchKey1;
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey1);
// Check for negative case consistency. (leaks upon test failure.)
@@ -909,8 +889,7 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) {
make_unique_key<0>(&key, 0);
// Create two resources that we will attempt to register with the same unique key.
- TestResource* a = new TestResource(gpu);
- a->setSize(11);
+ TestResource* a = new TestResource(gpu, SkBudgeted::kYes, 11);
// Set key on resource a.
a->resourcePriv().setUniqueKey(key);
@@ -926,8 +905,7 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
// Create resource b and set the same key. It should replace a's unique key cache entry.
- TestResource* b = new TestResource(gpu);
- b->setSize(12);
+ TestResource* b = new TestResource(gpu, SkBudgeted::kYes, 12);
b->resourcePriv().setUniqueKey(key);
REPORTER_ASSERT(reporter, b == cache->findAndRefUniqueResource(key));
b->unref();
@@ -946,10 +924,9 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) {
// Now replace b with c, but make sure c can start with one unique key and change it to b's key.
// Also make b be unreffed when replacement occurs.
b->unref();
- TestResource* c = new TestResource(gpu);
+ TestResource* c = new TestResource(gpu, SkBudgeted::kYes, 13);
GrUniqueKey differentKey;
make_unique_key<0>(&differentKey, 1);
- c->setSize(13);
c->resourcePriv().setUniqueKey(differentKey);
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
REPORTER_ASSERT(reporter, b->gpuMemorySize() + c->gpuMemorySize() == cache->getResourceBytes());
@@ -1101,73 +1078,6 @@ static void test_cache_chained_purge(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
}
-static void test_resource_size_changed(skiatest::Reporter* reporter) {
- GrUniqueKey key1, key2;
- make_unique_key<0>(&key1, 1);
- make_unique_key<0>(&key2, 2);
-
- // Test changing resources sizes (both increase & decrease).
- {
- Mock mock(3, 30000);
- GrContext* context = mock.context();
- GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
-
- TestResource* a = new TestResource(gpu);
- a->resourcePriv().setUniqueKey(key1);
- a->unref();
-
- TestResource* b = new TestResource(gpu);
- b->resourcePriv().setUniqueKey(key2);
- b->unref();
-
- REPORTER_ASSERT(reporter, 200 == cache->getResourceBytes());
- REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
- {
- sk_sp<TestResource> find2(
- static_cast<TestResource*>(cache->findAndRefUniqueResource(key2)));
- find2->setSize(200);
- sk_sp<TestResource> find1(
- static_cast<TestResource*>(cache->findAndRefUniqueResource(key1)));
- find1->setSize(50);
- }
-
- REPORTER_ASSERT(reporter, 250 == cache->getResourceBytes());
- REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
- }
-
- // Test increasing a resources size beyond the cache budget.
- {
- Mock mock(2, 300);
- GrContext* context = mock.context();
- GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
-
- TestResource* a = new TestResource(gpu);
- a->setSize(100);
- a->resourcePriv().setUniqueKey(key1);
- a->unref();
-
- TestResource* b = new TestResource(gpu);
- b->setSize(100);
- b->resourcePriv().setUniqueKey(key2);
- b->unref();
-
- REPORTER_ASSERT(reporter, 200 == cache->getResourceBytes());
- REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
-
- {
- sk_sp<TestResource> find2(static_cast<TestResource*>(
- cache->findAndRefUniqueResource(key2)));
- find2->setSize(201);
- }
- REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1));
-
- REPORTER_ASSERT(reporter, 201 == cache->getResourceBytes());
- REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
- }
-}
-
static void test_timestamp_wrap(skiatest::Reporter* reporter) {
static const int kCount = 50;
static const int kBudgetCnt = kCount / 2;
@@ -1459,26 +1369,21 @@ static void test_partial_purge(skiatest::Reporter* reporter) {
make_unique_key<0>(&key3, 3);
// Add three unique resources to the cache.
- TestResource *unique1 = new TestResource(gpu);
- TestResource *unique2 = new TestResource(gpu);
- TestResource *unique3 = new TestResource(gpu);
+ TestResource *unique1 = new TestResource(gpu, SkBudgeted::kYes, 10);
+ TestResource *unique2 = new TestResource(gpu, SkBudgeted::kYes, 11);
+ TestResource *unique3 = new TestResource(gpu, SkBudgeted::kYes, 12);
unique1->resourcePriv().setUniqueKey(key1);
unique2->resourcePriv().setUniqueKey(key2);
unique3->resourcePriv().setUniqueKey(key3);
- unique1->setSize(10);
- unique2->setSize(11);
- unique3->setSize(12);
-
// Add two scratch resources to the cache.
TestResource *scratch1 = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
- TestResource::kA_SimulatedProperty);
+ TestResource::kA_SimulatedProperty,
+ 13);
TestResource *scratch2 = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
- TestResource::kB_SimulatedProperty);
- scratch1->setSize(13);
- scratch2->setSize(14);
-
+ TestResource::kB_SimulatedProperty,
+ 14);
REPORTER_ASSERT(reporter, 5 == cache->getBudgetedResourceCount());
REPORTER_ASSERT(reporter, 60 == cache->getBudgetedResourceBytes());
@@ -1562,14 +1467,12 @@ static void test_large_resource_count(skiatest::Reporter* reporter) {
TestResource* resource;
- resource = new TestResource(gpu);
+ resource = new TestResource(gpu, SkBudgeted::kYes, 1);
resource->resourcePriv().setUniqueKey(key1);
- resource->setSize(1);
resource->unref();
- resource = new TestResource(gpu);
+ resource = new TestResource(gpu, SkBudgeted::kYes, 1);
resource->resourcePriv().setUniqueKey(key2);
- resource->setSize(1);
resource->unref();
}
@@ -1705,7 +1608,6 @@ DEF_GPUTEST(ResourceCacheMisc, reporter, /* options */) {
test_scratch_key_consistency(reporter);
test_purge_invalidated(reporter);
test_cache_chained_purge(reporter);
- test_resource_size_changed(reporter);
test_timestamp_wrap(reporter);
test_flush(reporter);
test_time_purge(reporter);