Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / core / SkMallocPixelRef.cpp
index 9adcd34..f4ba969 100644 (file)
@@ -7,7 +7,8 @@
 
 #include "SkMallocPixelRef.h"
 #include "SkBitmap.h"
-#include "SkFlattenableBuffers.h"
+#include "SkReadBuffer.h"
+#include "SkWriteBuffer.h"
 
 // assumes ptr was allocated via sk_malloc
 static void sk_free_releaseproc(void* ptr, void*) {
@@ -15,10 +16,9 @@ static void sk_free_releaseproc(void* ptr, void*) {
 }
 
 static bool is_valid(const SkImageInfo& info, SkColorTable* ctable) {
-    if (info.fWidth < 0 ||
-        info.fHeight < 0 ||
-        (unsigned)info.fColorType > (unsigned)kLastEnum_SkColorType ||
-        (unsigned)info.fAlphaType > (unsigned)kLastEnum_SkAlphaType)
+    if (info.width() < 0 || info.height() < 0 ||
+        (unsigned)info.colorType() > (unsigned)kLastEnum_SkColorType ||
+        (unsigned)info.alphaType() > (unsigned)kLastEnum_SkAlphaType)
     {
         return false;
     }
@@ -30,7 +30,7 @@ static bool is_valid(const SkImageInfo& info, SkColorTable* ctable) {
     if (kIndex8_SkColorType == info.fColorType && NULL == ctable) {
         return false;
     }
-    if (kIndex8_SkColorType != info.fColorType && NULL != ctable) {
+    if (kIndex8_SkColorType != info.fColorType && ctable) {
         return false;
     }
 #endif
@@ -48,6 +48,7 @@ SkMallocPixelRef* SkMallocPixelRef::NewDirect(const SkImageInfo& info,
                       (info, addr, rowBytes, ctable, NULL, NULL));
 }
 
+
 SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info,
                                                 size_t requestedRowBytes,
                                                 SkColorTable* ctable) {
@@ -70,7 +71,7 @@ SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info,
         rowBytes = minRB;
     }
 
-    int64_t bigSize = (int64_t)info.fHeight * rowBytes;
+    int64_t bigSize = (int64_t)info.height() * rowBytes;
     if (!sk_64_isS32(bigSize)) {
         return NULL;
     }
@@ -107,22 +108,19 @@ static void sk_data_releaseproc(void*, void* dataPtr) {
 SkMallocPixelRef* SkMallocPixelRef::NewWithData(const SkImageInfo& info,
                                                 size_t rowBytes,
                                                 SkColorTable* ctable,
-                                                SkData* data,
-                                                size_t offset) {
+                                                SkData* data) {
     SkASSERT(data != NULL);
-    SkASSERT(offset <= data->size());
     if (!is_valid(info, ctable)) {
         return NULL;
     }
     if ((rowBytes < info.minRowBytes())
-        || ((data->size() - offset) < info.getSafeSize(rowBytes))) {
+        || (data->size() < info.getSafeSize(rowBytes))) {
         return NULL;
     }
     data->ref();
-    const void* ptr = static_cast<const void*>(data->bytes() + offset);
     SkMallocPixelRef* pr
         = SkNEW_ARGS(SkMallocPixelRef,
-                     (info, const_cast<void*>(ptr), rowBytes, ctable,
+                     (info, const_cast<void*>(data->data()), rowBytes, ctable,
                       sk_data_releaseproc, static_cast<void*>(data)));
     SkASSERT(pr != NULL);
     // We rely on the immutability of the pixels to make the
@@ -143,7 +141,7 @@ SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage,
     SkASSERT(is_valid(info, ctable));
     SkASSERT(rowBytes >= info.minRowBytes());
 
-    if (kIndex_8_SkColorType != info.fColorType) {
+    if (kIndex_8_SkColorType != info.colorType()) {
         ctable = NULL;
     }
 
@@ -166,7 +164,7 @@ SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage,
     SkASSERT(is_valid(info, ctable));
     SkASSERT(rowBytes >= info.minRowBytes());
 
-    if (kIndex_8_SkColorType != info.fColorType) {
+    if (kIndex_8_SkColorType != info.colorType()) {
         ctable = NULL;
     }
 
@@ -201,47 +199,9 @@ size_t SkMallocPixelRef::getAllocatedSizeInBytes() const {
     return this->info().getSafeSize(fRB);
 }
 
-void SkMallocPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
-    this->INHERITED::flatten(buffer);
-
-    buffer.write32(SkToU32(fRB));
-
-    // TODO: replace this bulk write with a chunky one that can trim off any
-    // trailing bytes on each scanline (in case rowbytes > width*size)
-    size_t size = this->info().getSafeSize(fRB);
-    buffer.writeByteArray(fStorage, size);
-    buffer.writeBool(fCTable != NULL);
-    if (fCTable) {
-        fCTable->writeToBuffer(buffer);
-    }
-}
-
-SkMallocPixelRef::SkMallocPixelRef(SkFlattenableReadBuffer& buffer)
-    : INHERITED(buffer, NULL)
-    , fReleaseProc(sk_free_releaseproc)
-    , fReleaseProcContext(NULL)
-{
-    fRB = buffer.read32();
-    size_t size = buffer.isValid() ? this->info().getSafeSize(fRB) : 0;
-    if (buffer.validateAvailable(size)) {
-        fStorage = sk_malloc_throw(size);
-        buffer.readByteArray(fStorage, size);
-    } else {
-        fStorage = NULL;
-    }
-
-    if (buffer.readBool()) {
-        fCTable = SkNEW_ARGS(SkColorTable, (buffer));
-    } else {
-        fCTable = NULL;
-    }
-
-    this->setPreLocked(fStorage, fRB, fCTable);
-}
-
 ///////////////////////////////////////////////////////////////////////////////
 
-SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info,
+SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info, size_t rowBytes,
                                                 SkColorTable* ctable) {
-    return SkMallocPixelRef::NewAllocate(info, info.minRowBytes(), ctable);
+    return SkMallocPixelRef::NewAllocate(info, rowBytes, ctable);
 }