Home | History | Annotate | Download | only in core
      1 
      2 /*
      3  * Copyright 2012 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 #include "SkFlattenableBuffers.h"
      9 #include "SkPaint.h"
     10 #include "SkTypeface.h"
     11 
     12 SkFlattenableReadBuffer::SkFlattenableReadBuffer() {
     13     // Set default values. These should be explicitly set by our client
     14     // via setFlags() if the buffer came from serialization.
     15     fFlags = 0;
     16 #ifdef SK_SCALAR_IS_FLOAT
     17     fFlags |= kScalarIsFloat_Flag;
     18 #endif
     19     if (8 == sizeof(void*)) {
     20         fFlags |= kPtrIs64Bit_Flag;
     21     }
     22 }
     23 
     24 SkFlattenableReadBuffer::~SkFlattenableReadBuffer() { }
     25 
     26 void* SkFlattenableReadBuffer::readFunctionPtr() {
     27     void* proc;
     28     SkASSERT(sizeof(void*) == this->getArrayCount());
     29     this->readByteArray(&proc);
     30     return proc;
     31 }
     32 
     33 void SkFlattenableReadBuffer::readPaint(SkPaint* paint) {
     34     paint->unflatten(*this);
     35 }
     36 
     37 ///////////////////////////////////////////////////////////////////////////////
     38 
     39 SkFlattenableWriteBuffer::SkFlattenableWriteBuffer() {
     40     fFlags = (Flags)0;
     41 }
     42 
     43 SkFlattenableWriteBuffer::~SkFlattenableWriteBuffer() { }
     44 
     45 void SkFlattenableWriteBuffer::writeFunctionPtr(void* ptr) {
     46     void* ptrStorage[] = { ptr };
     47     this->writeByteArray(ptrStorage, sizeof(void*));
     48 }
     49 
     50 void SkFlattenableWriteBuffer::writePaint(const SkPaint& paint) {
     51     paint.flatten(*this);
     52 }
     53 
     54 void SkFlattenableWriteBuffer::flattenObject(SkFlattenable* obj, SkFlattenableWriteBuffer& buffer) {
     55     obj->flatten(buffer);
     56 }
     57