From 49099b25367d1b9ef45ccaa7fe370facea6b89bf Mon Sep 17 00:00:00 2001 From: "reed@android.com" Date: Thu, 9 Sep 2010 16:07:53 +0000 Subject: [PATCH] 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 --- src/core/SkBitmap.cpp | 50 -------------------- src/core/SkMallocPixelRef.cpp | 56 +++++++++++++++++++++++ src/core/core_files.mk | 1 + xcode/core/core.xcodeproj/project.pbxproj | 4 ++ 4 files changed, 61 insertions(+), 50 deletions(-) create mode 100644 src/core/SkMallocPixelRef.cpp diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 970ac01920..624e0cf214 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -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. */ diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp new file mode 100644 index 0000000000..726baca4d1 --- /dev/null +++ b/src/core/SkMallocPixelRef.cpp @@ -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); + diff --git a/src/core/core_files.mk b/src/core/core_files.mk index c36f11a2cd..d5cdf39a1c 100644 --- a/src/core/core_files.mk +++ b/src/core/core_files.mk @@ -47,6 +47,7 @@ SOURCE := \ SkGraphics.cpp \ SkLineClipper.cpp \ SkMMapStream.cpp \ + SkMallocPixelRef.cpp \ SkMask.cpp \ SkMaskFilter.cpp \ SkMath.cpp \ diff --git a/xcode/core/core.xcodeproj/project.pbxproj b/xcode/core/core.xcodeproj/project.pbxproj index 0f5cfcd1b3..0b510c73a0 100644 --- a/xcode/core/core.xcodeproj/project.pbxproj +++ b/xcode/core/core.xcodeproj/project.pbxproj @@ -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; };