diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-01-03 13:27:46 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-01-04 12:43:32 +0000 |
commit | d66a2fdf0d75ebbcbfe2bc5d9dca9e541bf5e899 (patch) | |
tree | 3640db4acb04ae1411d31f38edc69d4aad0ad3d7 | |
parent | 44d355f3b2de616db2a0dec6d01b0bfb0d6ba947 (diff) | |
download | qtwebengine-chromium-d66a2fdf0d75ebbcbfe2bc5d9dca9e541bf5e899.tar.gz |
[Backport] trim down colortable impl
Bug: skia:
Change-Id: I2606cb6d4d41db1b568c5182483abdd05d12afda
Reviewed-on: https://skia-review.googlesource.com/26304
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
-rw-r--r-- | chromium/third_party/skia/include/core/SkColorTable.h | 31 | ||||
-rw-r--r-- | chromium/third_party/skia/src/core/SkBitmap.cpp | 22 | ||||
-rw-r--r-- | chromium/third_party/skia/src/core/SkColorTable.cpp | 91 |
3 files changed, 13 insertions, 131 deletions
diff --git a/chromium/third_party/skia/include/core/SkColorTable.h b/chromium/third_party/skia/include/core/SkColorTable.h index ca5efd1fe15..ef8712d1d87 100644 --- a/chromium/third_party/skia/include/core/SkColorTable.h +++ b/chromium/third_party/skia/include/core/SkColorTable.h @@ -22,10 +22,8 @@ SkColorTable is thread-safe. */ -class SK_API SkColorTable : public SkRefCnt { +class SkColorTable : public SkRefCnt { public: - static sk_sp<SkColorTable> Make(const SkPMColor colors[], int count); - /** Copy up to 256 colors into a new SkColorTable. */ SkColorTable(const SkPMColor colors[], int count); @@ -43,34 +41,15 @@ public: return fColors[index]; } - /** Return the array of colors for reading. - */ + /** Return the array of colors for reading. */ const SkPMColor* readColors() const { return fColors; } - /** read16BitCache() returns the array of RGB16 colors that mirror the 32bit colors. - */ - const uint16_t* read16BitCache() const; - - void writeToBuffer(SkWriteBuffer&) const; - // may return null - static sk_sp<SkColorTable> Create(SkReadBuffer&); + static void Skip(SkReadBuffer&); private: - enum AllocatedWithMalloc { - kAllocatedWithMalloc - }; - // assumes ownership of colors (assumes it was allocated w/ malloc) - SkColorTable(SkPMColor* colors, int count, AllocatedWithMalloc); - - SkPMColor* fColors; - mutable uint16_t* f16BitCache = nullptr; - mutable SkOnce f16BitCacheOnce; - int fCount; - - void init(const SkPMColor* colors, int count); - - friend class SkImageGenerator; + SkPMColor* fColors; + int fCount; typedef SkRefCnt INHERITED; }; diff --git a/chromium/third_party/skia/src/core/SkBitmap.cpp b/chromium/third_party/skia/src/core/SkBitmap.cpp index e96e968fbf8..005e2157fe5 100644 --- a/chromium/third_party/skia/src/core/SkBitmap.cpp +++ b/chromium/third_party/skia/src/core/SkBitmap.cpp @@ -700,28 +700,10 @@ bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) { } if (buffer->readBool()) { - sk_sp<SkColorTable> ctable = SkColorTable::Create(*buffer); - if (!ctable) { + SkColorTable::Skip(*buffer); + if (!buffer->isValid()) { return false; } - - if (info.isEmpty()) { - // require an empty ctable - if (ctable->count() != 0) { - buffer->validate(false); - return false; - } - } else { - // require a non-empty ctable - if (ctable->count() == 0) { - buffer->validate(false); - return false; - } - unsigned char maxIndex = ctable->count() - 1; - for (uint64_t i = 0; i < ramSize; ++i) { - dst[i] = SkTMin(dst[i], maxIndex); - } - } } sk_sp<SkPixelRef> pr = SkMallocPixelRef::MakeWithData(info, info.minRowBytes(), diff --git a/chromium/third_party/skia/src/core/SkColorTable.cpp b/chromium/third_party/skia/src/core/SkColorTable.cpp index 2816de926af..fab3c3dc1cd 100644 --- a/chromium/third_party/skia/src/core/SkColorTable.cpp +++ b/chromium/third_party/skia/src/core/SkColorTable.cpp @@ -5,15 +5,13 @@ * found in the LICENSE file. */ - #include "SkColorTable.h" #include "SkReadBuffer.h" #include "SkWriteBuffer.h" -#include "SkStream.h" -#include "SkTemplates.h" -void SkColorTable::init(const SkPMColor colors[], int count) { - SkASSERT((unsigned)count <= 256); +SkColorTable::SkColorTable(const SkPMColor colors[], int count) { + SkASSERT(0 == count || colors); + SkASSERT(count >= 0 && count <= 256); fCount = count; fColors = reinterpret_cast<SkPMColor*>(sk_malloc_throw(count * sizeof(SkPMColor))); @@ -21,92 +19,15 @@ void SkColorTable::init(const SkPMColor colors[], int count) { memcpy(fColors, colors, count * sizeof(SkPMColor)); } -SkColorTable::SkColorTable(const SkPMColor colors[], int count) { - SkASSERT(0 == count || colors); - SkASSERT(count >= 0 && count <= 256); - this->init(colors, count); -} - -SkColorTable::SkColorTable(SkPMColor* colors, int count, AllocatedWithMalloc) - : fColors(colors) - , fCount(count) -{ - SkASSERT(count > 0 && count <= 256); - SkASSERT(colors); -} - SkColorTable::~SkColorTable() { sk_free(fColors); - sk_free(f16BitCache); -} - -#include "SkColorPriv.h" - -const uint16_t* SkColorTable::read16BitCache() const { - f16BitCacheOnce([this] { - f16BitCache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t)); - for (int i = 0; i < fCount; i++) { - f16BitCache[i] = SkPixel32ToPixel16_ToU16(fColors[i]); - } - }); - return f16BitCache; -} - -sk_sp<SkColorTable> SkColorTable::Make(const SkPMColor colors[], int count) { - if (count < 0 || count > 256) { - return nullptr; - } - if (count && !colors) { - return nullptr; - } - return sk_make_sp<SkColorTable>(colors, count); -} - -/////////////////////////////////////////////////////////////////////////////// - -#if 0 -SkColorTable::SkColorTable(SkReadBuffer& buffer) { - if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) { - /*fAlphaType = */buffer.readUInt(); - } - - fCount = buffer.getArrayCount(); - size_t allocSize = fCount * sizeof(SkPMColor); - SkDEBUGCODE(bool success = false;) - if (buffer.validateAvailable(allocSize)) { - fColors = (SkPMColor*)sk_malloc_throw(allocSize); - SkDEBUGCODE(success =) buffer.readColorArray(fColors, fCount); - } else { - fCount = 0; - fColors = nullptr; - } -#ifdef SK_DEBUG - SkASSERT((unsigned)fCount <= 256); - SkASSERT(success); -#endif } -#endif -void SkColorTable::writeToBuffer(SkWriteBuffer& buffer) const { - buffer.writeColorArray(fColors, fCount); -} - -sk_sp<SkColorTable> SkColorTable::Create(SkReadBuffer& buffer) { +void SkColorTable::Skip(SkReadBuffer& buffer) { const int count = buffer.getArrayCount(); - if (0 == count) { - return sk_sp<SkColorTable>(new SkColorTable(nullptr, 0)); - } - if (count < 0 || count > 256) { buffer.validate(false); - return nullptr; - } - - const size_t allocSize = count * sizeof(SkPMColor); - std::unique_ptr<SkPMColor> colors((SkPMColor*)sk_malloc_throw(allocSize)); - if (!buffer.readColorArray(colors.get(), count)) { - return nullptr; + } else { + buffer.skip(count * sizeof(SkPMColor)); } - - return sk_sp<SkColorTable>(new SkColorTable(colors.release(), count, kAllocatedWithMalloc)); } |