/* * Copyright 2012 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "SkFlattenableBuffers.h" #include "SkPaint.h" #include "SkTypeface.h" #include "SkColorFilter.h" #include "SkDrawLooper.h" #include "SkImageFilter.h" #include "SkMaskFilter.h" #include "SkPathEffect.h" #include "SkPixelRef.h" #include "SkRasterizer.h" #include "SkShader.h" #include "SkUnitMapper.h" #include "SkXfermode.h" SkFlattenableReadBuffer::SkFlattenableReadBuffer() { // Set default values. These should be explicitly set by our client // via setFlags() if the buffer came from serialization. fFlags = 0; #ifdef SK_SCALAR_IS_FLOAT fFlags |= kScalarIsFloat_Flag; #endif if (8 == sizeof(void*)) { fFlags |= kPtrIs64Bit_Flag; } } SkFlattenableReadBuffer::~SkFlattenableReadBuffer() { } void* SkFlattenableReadBuffer::readFunctionPtr() { void* proc; SkASSERT(sizeof(void*) == this->getArrayCount()); this->readByteArray(&proc); return proc; } void SkFlattenableReadBuffer::readPaint(SkPaint* paint) { paint->unflatten(*this); } template T* SkFlattenableReadBuffer::readFlattenableT() { return static_cast(this->readFlattenable(T::GetFlattenableType())); } SkColorFilter* SkFlattenableReadBuffer::readColorFilter() { return this->readFlattenableT(); } SkDrawLooper* SkFlattenableReadBuffer::readDrawLooper() { return this->readFlattenableT(); } SkImageFilter* SkFlattenableReadBuffer::readImageFilter() { return this->readFlattenableT(); } SkMaskFilter* SkFlattenableReadBuffer::readMaskFilter() { return this->readFlattenableT(); } SkPathEffect* SkFlattenableReadBuffer::readPathEffect() { return this->readFlattenableT(); } SkPixelRef* SkFlattenableReadBuffer::readPixelRef() { return this->readFlattenableT(); } SkRasterizer* SkFlattenableReadBuffer::readRasterizer() { return this->readFlattenableT(); } SkShader* SkFlattenableReadBuffer::readShader() { return this->readFlattenableT(); } SkUnitMapper* SkFlattenableReadBuffer::readUnitMapper() { return this->readFlattenableT(); } SkXfermode* SkFlattenableReadBuffer::readXfermode() { return this->readFlattenableT(); } /////////////////////////////////////////////////////////////////////////////// SkFlattenableWriteBuffer::SkFlattenableWriteBuffer() { fFlags = (Flags)0; } SkFlattenableWriteBuffer::~SkFlattenableWriteBuffer() { } void SkFlattenableWriteBuffer::writeFunctionPtr(void* ptr) { void* ptrStorage[] = { ptr }; this->writeByteArray(ptrStorage, sizeof(void*)); } void SkFlattenableWriteBuffer::writePaint(const SkPaint& paint) { paint.flatten(*this); } void SkFlattenableWriteBuffer::flattenObject(const SkFlattenable* obj, SkFlattenableWriteBuffer& buffer) { obj->flatten(buffer); }