diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-12 21:01:41 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-12 21:01:41 +0000 |
commit | 52e935d04c59135739c3a68fb6e19d313dc6d5ad (patch) | |
tree | 95f7ab178b045bef4456cbf92c6aa7e476becd99 /skia/sgl/SkBitmap.cpp | |
parent | 30fab79877b4bb067944b74d98346ac9bb6bfc7e (diff) | |
download | chromium_src-52e935d04c59135739c3a68fb6e19d313dc6d5ad.zip chromium_src-52e935d04c59135739c3a68fb6e19d313dc6d5ad.tar.gz chromium_src-52e935d04c59135739c3a68fb6e19d313dc6d5ad.tar.bz2 |
New drop of Skia. This is up to CL 121320.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6925 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/sgl/SkBitmap.cpp')
-rw-r--r-- | skia/sgl/SkBitmap.cpp | 65 |
1 files changed, 25 insertions, 40 deletions
diff --git a/skia/sgl/SkBitmap.cpp b/skia/sgl/SkBitmap.cpp index 914fc77..5ca3601 100644 --- a/skia/sgl/SkBitmap.cpp +++ b/skia/sgl/SkBitmap.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2008 Google Inc. + * Copyright (C) 2006-2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ #include "SkColorPriv.h" #include "SkDither.h" #include "SkFlattenable.h" +#include "SkMallocPixelRef.h" #include "SkMask.h" #include "SkPixelRef.h" #include "SkThread.h" @@ -33,8 +34,8 @@ struct MipLevel { }; struct SkBitmap::MipMap : SkNoncopyable { - int fRefCnt; - int fLevelCount; + int32_t fRefCnt; + int fLevelCount; // MipLevel fLevel[fLevelCount]; // Pixels[] @@ -203,6 +204,20 @@ int SkBitmap::ComputeRowBytes(Config c, int width) { return rowBytes; } +Sk64 SkBitmap::ComputeSize64(Config c, int width, int height) { + Sk64 size; + size.setMul(SkBitmap::ComputeRowBytes(c, width), height); + return size; +} + +size_t SkBitmap::ComputeSize(Config c, int width, int height) { + Sk64 size = SkBitmap::ComputeSize64(c, width, height); + if (size.isNeg() || !size.is32()) { + return 0; + } + return size.get32(); +} + void SkBitmap::setConfig(Config c, int width, int height, int rowBytes) { this->freePixels(); @@ -334,40 +349,6 @@ void SkBitmap::notifyPixelsChanged() const { /////////////////////////////////////////////////////////////////////////////// -/** 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. - */ -class SkMallocPixelRef : public SkPixelRef { -public: - /** Allocate the specified buffer for pixels. The memory is freed when the - last owner of this pixelref is gone. - */ - SkMallocPixelRef(void* addr, size_t size, SkColorTable* ctable); - virtual ~SkMallocPixelRef(); - - virtual void flatten(SkFlattenableWriteBuffer&) const; - virtual Factory getFactory() const { - return Create; - } - static SkPixelRef* Create(SkFlattenableReadBuffer& buffer) { - return SkNEW_ARGS(SkMallocPixelRef, (buffer)); - } - -protected: - // overrides from SkPixelRef - virtual void* onLockPixels(SkColorTable**); - virtual void onUnlockPixels(); - - SkMallocPixelRef(SkFlattenableReadBuffer& buffer); - -private: - void* fStorage; - size_t fSize; - SkColorTable* fCTable; - - typedef SkPixelRef INHERITED; -}; - SkMallocPixelRef::SkMallocPixelRef(void* storage, size_t size, SkColorTable* ctable) { SkASSERT(storage); @@ -416,7 +397,7 @@ SkMallocPixelRef::SkMallocPixelRef(SkFlattenableReadBuffer& buffer) : INHERITED( } static SkPixelRef::Registrar reg("SkMallocPixelRef", - SkMallocPixelRef::Create); + 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. @@ -534,7 +515,7 @@ void SkBitmap::eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const { SkAutoLockPixels alp(*this); // perform this check after the lock call - if (NULL == fPixels) { + if (!this->readyToDraw()) { return; } @@ -648,6 +629,8 @@ bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const { if (kRLE_Index8_Config == fConfig) { SkAutoLockPixels alp(*this); + // don't call readyToDraw(), since we can operate w/o a colortable + // at this stage if (this->getPixels() == NULL) { return false; } @@ -725,7 +708,7 @@ bool SkBitmap::copyTo(SkBitmap* dst, Config dstConfig, Allocator* alloc) const { SkAutoLockPixels srclock(*this); SkAutoLockPixels dstlock(tmp); - if (NULL == this->getPixels() || NULL == tmp.getPixels()) { + if (!this->readyToDraw() || !tmp.readyToDraw()) { // allocator/lock failed return false; } @@ -1257,6 +1240,7 @@ void SkBitmap::validate() const { SkASSERT(NULL == fColorTable || (unsigned)fColorTable->getRefCnt() < 10000); SkASSERT((uint8_t)ComputeBytesPerPixel((Config)fConfig) == fBytesPerPixel); +#if 0 // these asserts are not thread-correct, so disable for now if (fPixelRef) { if (fPixelLockCount > 0) { SkASSERT(fPixelRef->getLockCount() > 0); @@ -1265,6 +1249,7 @@ void SkBitmap::validate() const { SkASSERT(NULL == fColorTable); } } +#endif } #endif |