Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Unified Diff: tests/BitmapHeapTest.cpp

Issue 1930103003: remove SkWriteBuffer::reserve() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More dead code. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkPictureFlat.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/BitmapHeapTest.cpp
diff --git a/tests/BitmapHeapTest.cpp b/tests/BitmapHeapTest.cpp
deleted file mode 100644
index f9d4ee19bb5da1e37da88c68133231fced96c3e7..0000000000000000000000000000000000000000
--- a/tests/BitmapHeapTest.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2012 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkBitmap.h"
-#include "SkBitmapHeap.h"
-#include "SkColor.h"
-#include "SkFlattenable.h"
-#include "SkWriteBuffer.h"
-#include "SkPictureFlat.h"
-#include "SkRefCnt.h"
-#include "SkShader.h"
-#include "Test.h"
-
-struct SimpleFlatController : public SkFlatController {
- SimpleFlatController() : SkFlatController() {}
- ~SimpleFlatController() { fAllocations.freeAll(); }
- void* allocThrow(size_t bytes) override {
- fAllocations.push(sk_malloc_throw(bytes));
- return fAllocations.top();
- }
- void unalloc(void*) override { }
- void setBitmapStorage(SkBitmapHeap* h) { this->setBitmapHeap(h); }
-private:
- SkTDArray<void*> fAllocations;
-};
-
-struct SkShaderTraits {
- static void Flatten(SkWriteBuffer& buffer, const SkShader& shader) {
- buffer.writeFlattenable(&shader);
- }
-};
-typedef SkFlatDictionary<SkShader, SkShaderTraits> FlatDictionary;
-
-class SkBitmapHeapTester {
-public:
- static int32_t GetRefCount(const SkBitmapHeapEntry* entry) {
- return entry->fRefCount;
- }
-};
-
-DEF_TEST(BitmapHeap, reporter) {
- // Create a bitmap shader.
- SkBitmap bm;
- bm.allocN32Pixels(2, 2);
- bm.eraseColor(SK_ColorRED);
- uint32_t* pixel = bm.getAddr32(1,0);
- *pixel = SK_ColorBLUE;
-
- auto bitmapShader = SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode);
-
- // Flatten, storing it in the bitmap heap.
- SkBitmapHeap heap(1, 1);
- SimpleFlatController controller;
- controller.setBitmapStorage(&heap);
- FlatDictionary dictionary(&controller);
-
- // Dictionary and heap start off empty.
- REPORTER_ASSERT(reporter, heap.count() == 0);
- REPORTER_ASSERT(reporter, dictionary.count() == 0);
-
- heap.deferAddingOwners();
- int index = dictionary.find(*bitmapShader);
- heap.endAddingOwnersDeferral(true);
-
- // The dictionary and heap should now each have one entry.
- REPORTER_ASSERT(reporter, 1 == index);
- REPORTER_ASSERT(reporter, heap.count() == 1);
- REPORTER_ASSERT(reporter, dictionary.count() == 1);
-
- // The bitmap entry's refcount should be 1, then 0 after release.
- SkBitmapHeapEntry* entry = heap.getEntry(0);
- REPORTER_ASSERT(reporter, SkBitmapHeapTester::GetRefCount(entry) == 1);
-
- entry->releaseRef();
- REPORTER_ASSERT(reporter, SkBitmapHeapTester::GetRefCount(entry) == 0);
-
- // Now clear out the heap, after which it should be empty.
- heap.freeMemoryIfPossible(~0U);
- REPORTER_ASSERT(reporter, heap.count() == 0);
-
- // Now attempt to flatten the shader again.
- heap.deferAddingOwners();
- index = dictionary.find(*bitmapShader);
- heap.endAddingOwnersDeferral(false);
-
- // The bitmap heap should contain the bitmap, but with no references.
- REPORTER_ASSERT(reporter, heap.count() == 1);
- REPORTER_ASSERT(reporter, SkBitmapHeapTester::GetRefCount(heap.getEntry(0)) == 0);
-}
« no previous file with comments | « src/core/SkPictureFlat.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698