Archive more dead code.
These classes were used by QuadTree, which has been archived (with prejudice). BUG=skia: Review URL: https://codereview.chromium.org/616963006
This commit is contained in:
parent
15c7ceb6aa
commit
ed48ebe39e
@ -141,7 +141,6 @@
|
||||
'../tests/MipMapTest.cpp',
|
||||
'../tests/NameAllocatorTest.cpp',
|
||||
'../tests/OSPathTest.cpp',
|
||||
'../tests/ObjectPoolTest.cpp',
|
||||
'../tests/OnceTest.cpp',
|
||||
'../tests/PDFJpegEmbedTest.cpp',
|
||||
'../tests/PDFPrimitivesTest.cpp',
|
||||
@ -179,7 +178,6 @@
|
||||
'../tests/RoundRectTest.cpp',
|
||||
'../tests/RuntimeConfigTest.cpp',
|
||||
'../tests/SHA1Test.cpp',
|
||||
'../tests/SListTest.cpp',
|
||||
'../tests/ScalarTest.cpp',
|
||||
'../tests/SerializationTest.cpp',
|
||||
'../tests/ShaderImageFilterTest.cpp',
|
||||
|
@ -1,132 +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.
|
||||
*/
|
||||
|
||||
#ifndef SkTInternalSList_DEFINED
|
||||
#define SkTInternalSList_DEFINED
|
||||
|
||||
#include "SkTInternalLList.h" // for SkPtrWrapper
|
||||
|
||||
/**
|
||||
* This macro creates the methods required by the SkTInternalSList class.
|
||||
* It should be instantiated in the private block of the class you want to put
|
||||
* into an SkTInternalSList.
|
||||
* For most use cases you should use SK_DECLARE_INTERNAL_SLIST_INTERFACE and not
|
||||
* this macro. If you care about the field name, or want to re-use an existing
|
||||
* field, then you can use this macro to declare the methods pointing to a
|
||||
* specific field.
|
||||
* Unlike SK_DECLARE_INTERNAL_SLIST_INTERFACE this does not declare the field
|
||||
* itself.
|
||||
* It also makes SkTInternalSList<ClassName> a friend to give it access to the
|
||||
* methods.
|
||||
*/
|
||||
#define SK_DECLARE_INTERNAL_SLIST_ADAPTER(ClassName, field) \
|
||||
ClassName* getSListNext() { \
|
||||
return this->field; \
|
||||
} \
|
||||
void setSListNext(ClassName* next) { \
|
||||
this->field = next; \
|
||||
} \
|
||||
friend class SkTInternalSList<ClassName>
|
||||
|
||||
/**
|
||||
* This macro declares an fSListNext that auto initializes to NULL and then
|
||||
* uses SK_DECLARE_INTERNAL_SLIST_ADAPTER to add the methods needed by
|
||||
* SkTInternalSList.
|
||||
* It should be instantiated in the private block of the class you want to put
|
||||
* into an SkTInternalSList.
|
||||
*/
|
||||
#define SK_DECLARE_INTERNAL_SLIST_INTERFACE(ClassName) \
|
||||
SK_DECLARE_INTERNAL_SLIST_ADAPTER(ClassName, fSListNext); \
|
||||
SkPtrWrapper<ClassName> fSListNext
|
||||
|
||||
/**
|
||||
* An implementation of an intrusive singly linked list.
|
||||
* The type T must have a methods getSListNext and setSListNext that are visible
|
||||
* to the list. The easiest way to do this is with
|
||||
* SK_DECLARE_INTERNAL_SLIST_INTERFACE.
|
||||
* The list does not maintain ownership of any of its elements, or ever delete
|
||||
* them.
|
||||
*/
|
||||
template<typename T> class SkTInternalSList {
|
||||
public:
|
||||
SkTInternalSList() : fHead(NULL), fCount(0) {}
|
||||
|
||||
/**
|
||||
* Push an item onto the head of the list.
|
||||
* This method is *not* thread safe.
|
||||
*/
|
||||
void push(T* entry) {
|
||||
SkASSERT(entry->getSListNext() == NULL);
|
||||
entry->setSListNext(fHead);
|
||||
fHead = entry;
|
||||
++fCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes all the items from another list and pushes them into this list.
|
||||
* No ordering guarantees are made, the other list will be emptied.
|
||||
* This method is *not* thread safe.
|
||||
*/
|
||||
void pushAll(SkTInternalSList<T>* other) {
|
||||
if (this->isEmpty()) {
|
||||
this->swap(other);
|
||||
return;
|
||||
}
|
||||
while (!other->isEmpty()) {
|
||||
this->push(other->pop());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop an item from the head of the list.
|
||||
* Returns NULL if the list is empty.
|
||||
* This method is *not* thread safe.
|
||||
*/
|
||||
T* pop() {
|
||||
if (NULL == fHead) {
|
||||
return NULL;
|
||||
}
|
||||
T* result = fHead;
|
||||
fHead = result->getSListNext();
|
||||
result->setSListNext(NULL);
|
||||
--fCount;
|
||||
return result;
|
||||
}
|
||||
|
||||
T* head() const {
|
||||
return fHead;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the list has no elements.
|
||||
*/
|
||||
bool isEmpty() const {
|
||||
return NULL == fHead;
|
||||
}
|
||||
|
||||
/**
|
||||
* Swaps the contents of this list with another one.
|
||||
* This method is *not* thread safe.
|
||||
*/
|
||||
void swap(SkTInternalSList<T>* other) {
|
||||
SkTSwap(fHead, other->fHead);
|
||||
SkTSwap(fCount, other->fCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the count of elements in the list.
|
||||
*/
|
||||
int getCount() const {
|
||||
return fCount;
|
||||
}
|
||||
private:
|
||||
T* fHead;
|
||||
int fCount;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,109 +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.
|
||||
*/
|
||||
|
||||
#ifndef SkFreeList_DEFINED
|
||||
#define SkFreeList_DEFINED
|
||||
|
||||
#include "SkTInternalSList.h"
|
||||
|
||||
/**
|
||||
* An implementation of a self growing pool of objects.
|
||||
* It maintains a pool of fully initialized objects. If an attempt is made to
|
||||
* acquire one, and there are none left, it makes some more.
|
||||
* It does not automatically reclaim them, they have to be given back to it.
|
||||
* Constructors will be called on objects allocated by the pool at allocation
|
||||
* time.
|
||||
* All allocated objects will be destroyed and memory will be reclaimed when
|
||||
* the pool is destroyed, so the pool must survive longer than you are using
|
||||
* any item taken from it.
|
||||
*/
|
||||
template<typename T, int numItemsPerBlock = 4096/sizeof(T)> class SkTObjectPool {
|
||||
public:
|
||||
SkTObjectPool() {}
|
||||
~SkTObjectPool() {
|
||||
while (!fBlocks.isEmpty()) {
|
||||
SkDELETE(fBlocks.pop());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item from the pool.
|
||||
* If the pool has no free items, it will allocate and construct some more.
|
||||
* The returned item is only valid as long as the pool has not been
|
||||
* destroyed, at that point all memory allocated by grow will have been
|
||||
* reclaimed.
|
||||
* This method is *not* thread safe.
|
||||
*/
|
||||
T* acquire() {
|
||||
if (fAvailable.isEmpty()) {
|
||||
grow();
|
||||
}
|
||||
return fAvailable.pop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Release an item into the pool.
|
||||
* The item does not have to have come from the pool, but if it did not
|
||||
* it must have a lifetime greater than the pool does.
|
||||
* This method is *not* thread safe.
|
||||
*/
|
||||
void release(T* entry) {
|
||||
fAvailable.push(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes all the items from an SkTInternalSList and adds them back to this
|
||||
* pool. The other list will be left empty.
|
||||
*/
|
||||
void releaseAll(SkTInternalSList<T>* other) {
|
||||
fAvailable.pushAll(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of items immediately available without having to
|
||||
* construct any new ones.
|
||||
*/
|
||||
int available() const { return fAvailable.getCount(); }
|
||||
|
||||
/**
|
||||
* Returns the number of blocks of items the pool has allocated so far.
|
||||
*/
|
||||
int blocks() const { return fBlocks.getCount(); }
|
||||
|
||||
/**
|
||||
* Returns the number of items allocated by the pool in total.
|
||||
*/
|
||||
int allocated() const { return fBlocks.getCount() * numItemsPerBlock; }
|
||||
|
||||
private:
|
||||
/**
|
||||
* The type for a new block of entries for the list.
|
||||
*/
|
||||
struct Block {
|
||||
T entries[numItemsPerBlock];
|
||||
SK_DECLARE_INTERNAL_SLIST_INTERFACE(Block);
|
||||
};
|
||||
SkTInternalSList<Block> fBlocks;
|
||||
SkTInternalSList<T> fAvailable;
|
||||
|
||||
/**
|
||||
* When the free list runs out of items, this method is called to allocate
|
||||
* a new block of them.
|
||||
* It calls the constructors and then pushes the nodes into the available
|
||||
* list.
|
||||
*/
|
||||
void grow() {
|
||||
Block* block = SkNEW(Block);
|
||||
fBlocks.push(block);
|
||||
for(int index = 0; index < numItemsPerBlock; ++index) {
|
||||
fAvailable.push(&block->entries[index]);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -1,68 +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 "SkTObjectPool.h"
|
||||
#include "SkTObjectPool.h"
|
||||
#include "Test.h"
|
||||
|
||||
class PoolEntry {
|
||||
public:
|
||||
private:
|
||||
SK_DECLARE_INTERNAL_SLIST_INTERFACE(PoolEntry);
|
||||
};
|
||||
|
||||
static const int kNumItemsPerBlock = 3;
|
||||
typedef SkTObjectPool<PoolEntry, kNumItemsPerBlock> ObjectPoolType;
|
||||
|
||||
static bool verifyPool(skiatest::Reporter* reporter,
|
||||
const ObjectPoolType& pool,
|
||||
const char* stage,
|
||||
int available, int blocks) {
|
||||
if (available != pool.available()) {
|
||||
ERRORF(reporter, "%s - Pool available is %d not %d",
|
||||
stage, pool.available(), available);
|
||||
return false;
|
||||
}
|
||||
if (blocks != pool.blocks()) {
|
||||
ERRORF(reporter, "%s - Pool blocks is %d not %d",
|
||||
stage, pool.blocks(), blocks);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static const int kNumToAcquire = kNumItemsPerBlock * 5;
|
||||
static void testObjectPool(skiatest::Reporter* reporter) {
|
||||
ObjectPoolType pool;
|
||||
SkTInternalSList<PoolEntry> used;
|
||||
verifyPool(reporter, pool, "empty", 0, 0);
|
||||
for (int index = 0; index < kNumToAcquire; ++index) {
|
||||
used.push(pool.acquire());
|
||||
int blocks = (index / kNumItemsPerBlock) + 1;
|
||||
int available = (blocks * kNumItemsPerBlock) - (index + 1);
|
||||
if (!verifyPool(reporter, pool, "acquire", available, blocks)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
int available = pool.available();
|
||||
int blocks = pool.blocks();
|
||||
for (int index = 0; index < kNumToAcquire / 2; ++index) {
|
||||
pool.release(used.pop());
|
||||
++available;
|
||||
if (!verifyPool(reporter, pool, "release", available, blocks)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
available += used.getCount();
|
||||
pool.releaseAll(&used);
|
||||
REPORTER_ASSERT(reporter, used.isEmpty());
|
||||
verifyPool(reporter, pool, "releaseAll", available, blocks);
|
||||
}
|
||||
|
||||
DEF_TEST(ObjectPool, reporter) {
|
||||
testObjectPool(reporter);
|
||||
}
|
@ -1,111 +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 "SkTInternalSList.h"
|
||||
#include "Test.h"
|
||||
|
||||
class SListEntry {
|
||||
public:
|
||||
SListEntry* next() { return getSListNext(); }
|
||||
private:
|
||||
SK_DECLARE_INTERNAL_SLIST_INTERFACE(SListEntry);
|
||||
};
|
||||
|
||||
static bool verifyEmptyList(skiatest::Reporter* reporter,
|
||||
const SkTInternalSList<SListEntry>& list,
|
||||
const char* stage) {
|
||||
|
||||
if (!list.isEmpty()) {
|
||||
ERRORF(reporter, "%s - List not empty", stage);
|
||||
return false;
|
||||
}
|
||||
if (0 != list.getCount()) {
|
||||
ERRORF(reporter, "%s - List count is not zero, %d instead", stage, list.getCount());
|
||||
return false;
|
||||
}
|
||||
if (list.head()) {
|
||||
ERRORF(reporter, "%s - List has elements when empty", stage);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool verifyList(skiatest::Reporter* reporter,
|
||||
const SkTInternalSList<SListEntry>& list,
|
||||
const char* stage,
|
||||
SListEntry* start, int count, int step = 1) {
|
||||
SListEntry* next = list.head();
|
||||
if (list.getCount() != count) {
|
||||
ERRORF(reporter, "%s - List was too short, %d instead of %d", stage, list.getCount(), count);
|
||||
return false;
|
||||
}
|
||||
int index = 0;
|
||||
for(SListEntry* value = start; index < count; value += step, ++index) {
|
||||
if (NULL == next) {
|
||||
ERRORF(reporter, "%s - List too short, should be %d", stage, count);
|
||||
return false;
|
||||
}
|
||||
if (next!= value) {
|
||||
ERRORF(reporter, "%s - List entries at index %d of %d don't match", stage, index, count);
|
||||
return false;
|
||||
}
|
||||
next = next->next();
|
||||
}
|
||||
if (next) {
|
||||
ERRORF(reporter, "%s - List too long, should be %d", stage, count);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void testTInternalSList(skiatest::Reporter* reporter) {
|
||||
// Build a test array of data
|
||||
static const int testArraySize = 10;
|
||||
SListEntry testArray[testArraySize];
|
||||
// Basic add remove tests
|
||||
SkTInternalSList<SListEntry> list;
|
||||
verifyEmptyList(reporter, list, "start");
|
||||
// Push values in, testing on the way
|
||||
for (int index = 0; index < testArraySize; ++index) {
|
||||
list.push(&testArray[index]);
|
||||
if (!verifyList(reporter, list, "push", &testArray[index], index+1, -1)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Now remove them again
|
||||
for (int index = testArraySize - 1; index >= 0; --index) {
|
||||
REPORTER_ASSERT(reporter, &testArray[index] == list.pop());
|
||||
if ((index != 0) &&
|
||||
!verifyList(reporter, list, "pop", &testArray[index-1], index, -1)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
verifyEmptyList(reporter, list, "end");
|
||||
// Move between list tests
|
||||
for (int index = 0; index < testArraySize; ++index) {
|
||||
list.push(&testArray[index]);
|
||||
}
|
||||
verifyList(reporter, list, "swap", &testArray[testArraySize-1], testArraySize, -1);
|
||||
SkTInternalSList<SListEntry> other;
|
||||
// Check swap moves the list over unchanged
|
||||
other.swap(&list);
|
||||
verifyEmptyList(reporter, list, "swap");
|
||||
verifyList(reporter, other, "swap", &testArray[testArraySize-1], testArraySize, -1);
|
||||
// Check pushAll optimizes to a swap when one of the is empty
|
||||
list.pushAll(&other);
|
||||
verifyList(reporter, list, "pushAll-empty", &testArray[testArraySize-1], testArraySize, -1);
|
||||
verifyEmptyList(reporter, other, "pushAll-empty");
|
||||
// Check pushAll when non empty works
|
||||
other.push(list.pop());
|
||||
other.pushAll(&list);
|
||||
verifyEmptyList(reporter, list, "pushAll");
|
||||
verifyList(reporter, other, "pushAll", &testArray[0], testArraySize, 1);
|
||||
}
|
||||
|
||||
DEF_TEST(SList, reporter) {
|
||||
testTInternalSList(reporter);
|
||||
}
|
Loading…
Reference in New Issue
Block a user