Remove SkVarAlloc
Change-Id: Id41d3e03390185f72b682225aeb140df45c84a34 Reviewed-on: https://skia-review.googlesource.com/13763 Commit-Queue: Mike Klein <mtklein@chromium.org> Reviewed-by: Mike Klein <mtklein@chromium.org>
This commit is contained in:
parent
edbb7d8860
commit
3f4531d312
@ -358,7 +358,6 @@ skia_core_sources = [
|
||||
"$_src/core/SkValidatingReadBuffer.cpp",
|
||||
"$_src/core/SkValidatingReadBuffer.h",
|
||||
"$_src/core/SkValidationUtils.h",
|
||||
"$_src/core/SkVarAlloc.cpp",
|
||||
"$_src/core/SkVertices.cpp",
|
||||
"$_src/core/SkVertState.cpp",
|
||||
"$_src/core/SkWriteBuffer.cpp",
|
||||
|
@ -248,7 +248,6 @@ tests_sources = [
|
||||
"$_tests/TypefaceTest.cpp",
|
||||
"$_tests/UnicodeTest.cpp",
|
||||
"$_tests/UtilsTest.cpp",
|
||||
"$_tests/VarAllocTest.cpp",
|
||||
"$_tests/VerticesTest.cpp",
|
||||
"$_tests/VkClearTests.cpp",
|
||||
"$_tests/VkHeapTests.cpp",
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkVarAlloc.h"
|
||||
|
||||
#include "SkMalloc.h"
|
||||
|
||||
struct SkVarAlloc::Block {
|
||||
Block* prev;
|
||||
char* data() { return (char*)(this + 1); }
|
||||
|
||||
static Block* Alloc(Block* prev, size_t size) {
|
||||
SkASSERT(size >= sizeof(Block));
|
||||
Block* b = (Block*)sk_malloc_throw(size);
|
||||
b->prev = prev;
|
||||
return b;
|
||||
}
|
||||
};
|
||||
|
||||
SkVarAlloc::SkVarAlloc(size_t minLgSize)
|
||||
: fBytesAllocated(0)
|
||||
, fByte(nullptr)
|
||||
, fRemaining(0)
|
||||
, fLgSize(minLgSize)
|
||||
, fBlock(nullptr) {}
|
||||
|
||||
SkVarAlloc::SkVarAlloc(size_t minLgSize, char* storage, size_t len)
|
||||
: fBytesAllocated(0)
|
||||
, fByte(storage)
|
||||
, fRemaining(len)
|
||||
, fLgSize(minLgSize)
|
||||
, fBlock(nullptr) {}
|
||||
|
||||
SkVarAlloc::~SkVarAlloc() {
|
||||
Block* b = fBlock;
|
||||
while (b) {
|
||||
Block* prev = b->prev;
|
||||
sk_free(b);
|
||||
b = prev;
|
||||
}
|
||||
}
|
||||
|
||||
void SkVarAlloc::makeSpace(size_t bytes) {
|
||||
SkASSERT(SkIsAlignPtr(bytes));
|
||||
|
||||
size_t alloc = static_cast<size_t>(1)<<fLgSize++;
|
||||
while (alloc < bytes + sizeof(Block)) {
|
||||
alloc *= 2;
|
||||
}
|
||||
fBytesAllocated += alloc;
|
||||
fBlock = Block::Alloc(fBlock, alloc);
|
||||
fByte = fBlock->data();
|
||||
fRemaining = alloc - sizeof(Block);
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkVarAlloc_DEFINED
|
||||
#define SkVarAlloc_DEFINED
|
||||
|
||||
#include "SkTypes.h"
|
||||
|
||||
class SkVarAlloc : SkNoncopyable {
|
||||
public:
|
||||
// Smallest block we'll allocate is 2**N bytes.
|
||||
explicit SkVarAlloc(size_t minLgSize);
|
||||
// Same as above, but first uses up to len bytes from storage.
|
||||
SkVarAlloc(size_t minLgSize, char* storage, size_t len);
|
||||
|
||||
~SkVarAlloc();
|
||||
|
||||
// Returns contiguous bytes aligned at least for pointers.
|
||||
char* alloc(size_t bytes) {
|
||||
bytes = SkAlignPtr(bytes);
|
||||
|
||||
if (bytes > fRemaining) {
|
||||
this->makeSpace(bytes);
|
||||
}
|
||||
SkASSERT(bytes <= fRemaining);
|
||||
|
||||
char* ptr = fByte;
|
||||
fByte += bytes;
|
||||
fRemaining = SkToU32(fRemaining - bytes);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// Returns our best estimate of the number of bytes we've allocated.
|
||||
// (We may not track this precisely to save space.)
|
||||
size_t approxBytesAllocated() const { return fBytesAllocated; }
|
||||
|
||||
private:
|
||||
void makeSpace(size_t bytes);
|
||||
|
||||
size_t fBytesAllocated;
|
||||
|
||||
char* fByte;
|
||||
unsigned fRemaining;
|
||||
unsigned fLgSize;
|
||||
|
||||
struct Block;
|
||||
Block* fBlock;
|
||||
};
|
||||
static_assert(sizeof(SkVarAlloc) <= 32, "SkVarAllocSize");
|
||||
|
||||
#endif//SkVarAlloc_DEFINED
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "Test.h"
|
||||
#include "SkVarAlloc.h"
|
||||
|
||||
DEF_TEST(VarAlloc, r) {
|
||||
SkVarAlloc va(4/*start allocating at 16B*/);
|
||||
char* p = va.alloc(128);
|
||||
sk_bzero(p, 128); // Just checking this is safe.
|
||||
|
||||
#if !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__)
|
||||
// This method will always return 0 on Android and UCLIBC platforms.
|
||||
REPORTER_ASSERT(r, va.approxBytesAllocated() >= 128);
|
||||
#endif
|
||||
}
|
Loading…
Reference in New Issue
Block a user