move SkMallocPixelRef into its own .cpp file, rather than embedding it

inside SkBitmap.cpp.

core_files.mk updated, but if your build does not reference that, you will
need to add SkMallocPixelRef.cpp to your list



git-svn-id: http://skia.googlecode.com/svn/trunk@597 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@android.com 2010-09-09 16:07:53 +00:00
parent ce4e53a234
commit 49099b2536
4 changed files with 61 additions and 50 deletions

View File

@ -377,56 +377,6 @@ SkGpuTexture* SkBitmap::getTexture() const {
///////////////////////////////////////////////////////////////////////////////
SkMallocPixelRef::SkMallocPixelRef(void* storage, size_t size,
SkColorTable* ctable) {
SkASSERT(storage);
fStorage = storage;
fSize = size;
fCTable = ctable;
ctable->safeRef();
}
SkMallocPixelRef::~SkMallocPixelRef() {
SkSafeUnref(fCTable);
sk_free(fStorage);
}
void* SkMallocPixelRef::onLockPixels(SkColorTable** ct) {
*ct = fCTable;
return fStorage;
}
void SkMallocPixelRef::onUnlockPixels() {
// nothing to do
}
void SkMallocPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
buffer.write32(fSize);
buffer.writePad(fStorage, fSize);
if (fCTable) {
buffer.writeBool(true);
fCTable->flatten(buffer);
} else {
buffer.writeBool(false);
}
}
SkMallocPixelRef::SkMallocPixelRef(SkFlattenableReadBuffer& buffer) : INHERITED(buffer, NULL) {
fSize = buffer.readU32();
fStorage = sk_malloc_throw(fSize);
buffer.read(fStorage, fSize);
if (buffer.readBool()) {
fCTable = SkNEW_ARGS(SkColorTable, (buffer));
} else {
fCTable = NULL;
}
}
static SkPixelRef::Registrar reg("SkMallocPixelRef",
SkMallocPixelRef::Create);
/** We explicitly use the same allocator for our pixels that SkMask does,
so that we can freely assign memory allocated by one class to the other.
*/

View File

@ -0,0 +1,56 @@
#include "SkMallocPixelRef.h"
#include "SkBitmap.h"
#include "SkFlattenable.h"
SkMallocPixelRef::SkMallocPixelRef(void* storage, size_t size,
SkColorTable* ctable) {
if (NULL == storage) {
storage = sk_malloc_throw(size);
}
fStorage = storage;
fSize = size;
fCTable = ctable;
ctable->safeRef();
}
SkMallocPixelRef::~SkMallocPixelRef() {
SkSafeUnref(fCTable);
sk_free(fStorage);
}
void* SkMallocPixelRef::onLockPixels(SkColorTable** ct) {
*ct = fCTable;
return fStorage;
}
void SkMallocPixelRef::onUnlockPixels() {
// nothing to do
}
void SkMallocPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
buffer.write32(fSize);
buffer.writePad(fStorage, fSize);
if (fCTable) {
buffer.writeBool(true);
fCTable->flatten(buffer);
} else {
buffer.writeBool(false);
}
}
SkMallocPixelRef::SkMallocPixelRef(SkFlattenableReadBuffer& buffer) : INHERITED(buffer, NULL) {
fSize = buffer.readU32();
fStorage = sk_malloc_throw(fSize);
buffer.read(fStorage, fSize);
if (buffer.readBool()) {
fCTable = SkNEW_ARGS(SkColorTable, (buffer));
} else {
fCTable = NULL;
}
}
static SkPixelRef::Registrar reg("SkMallocPixelRef",
SkMallocPixelRef::Create);

View File

@ -47,6 +47,7 @@ SOURCE := \
SkGraphics.cpp \
SkLineClipper.cpp \
SkMMapStream.cpp \
SkMallocPixelRef.cpp \
SkMask.cpp \
SkMaskFilter.cpp \
SkMath.cpp \

View File

@ -131,6 +131,7 @@
00F043FC10B445F50049C54C /* SkEdgeBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00F043F910B445F50049C54C /* SkEdgeBuilder.cpp */; };
00F043FD10B445F50049C54C /* SkEdgeClipper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00F043FA10B445F50049C54C /* SkEdgeClipper.cpp */; };
00F043FE10B445F50049C54C /* SkLineClipper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00F043FB10B445F50049C54C /* SkLineClipper.cpp */; };
27CE2BE912393D1D00CF4BB7 /* SkMallocPixelRef.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27CE2BE812393D1D00CF4BB7 /* SkMallocPixelRef.cpp */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -258,6 +259,7 @@
00F043F910B445F50049C54C /* SkEdgeBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkEdgeBuilder.cpp; path = ../../src/core/SkEdgeBuilder.cpp; sourceTree = SOURCE_ROOT; };
00F043FA10B445F50049C54C /* SkEdgeClipper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkEdgeClipper.cpp; path = ../../src/core/SkEdgeClipper.cpp; sourceTree = SOURCE_ROOT; };
00F043FB10B445F50049C54C /* SkLineClipper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkLineClipper.cpp; path = ../../src/core/SkLineClipper.cpp; sourceTree = SOURCE_ROOT; };
27CE2BE812393D1D00CF4BB7 /* SkMallocPixelRef.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkMallocPixelRef.cpp; path = ../../src/core/SkMallocPixelRef.cpp; sourceTree = SOURCE_ROOT; };
D2AAC046055464E500DB518D /* libcore.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libcore.a; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
@ -302,6 +304,7 @@
08FB7795FE84155DC02AAC07 /* src */ = {
isa = PBXGroup;
children = (
27CE2BE812393D1D00CF4BB7 /* SkMallocPixelRef.cpp */,
00F043F910B445F50049C54C /* SkEdgeBuilder.cpp */,
00F043FA10B445F50049C54C /* SkEdgeClipper.cpp */,
00F043FB10B445F50049C54C /* SkLineClipper.cpp */,
@ -620,6 +623,7 @@
00F043FC10B445F50049C54C /* SkEdgeBuilder.cpp in Sources */,
00F043FD10B445F50049C54C /* SkEdgeClipper.cpp in Sources */,
00F043FE10B445F50049C54C /* SkLineClipper.cpp in Sources */,
27CE2BE912393D1D00CF4BB7 /* SkMallocPixelRef.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};