michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=8 et : michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GFX_LAYERS_BLOBSURFACE_H michael@0: #define GFX_LAYERS_BLOBSURFACE_H michael@0: michael@0: #include // for uint8_t, uint32_t michael@0: #include "mozilla/Attributes.h" // for MOZ_STACK_CLASS michael@0: #include "mozilla/RefPtr.h" // for TemporaryRef michael@0: #include "mozilla/gfx/Point.h" // for IntSize michael@0: #include "mozilla/gfx/Types.h" // for SurfaceFormat michael@0: michael@0: class gfxImageSurface; michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: class DataSourceSurface; michael@0: class DrawTarget; michael@0: } // namespace gfx michael@0: } // namespace mozilla michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: class ImageDataSerializerBase michael@0: { michael@0: public: michael@0: bool IsValid() const { return mIsValid; } michael@0: michael@0: uint8_t* GetData(); michael@0: uint32_t GetStride() const; michael@0: gfx::IntSize GetSize() const; michael@0: gfx::SurfaceFormat GetFormat() const; michael@0: TemporaryRef GetAsSurface(); michael@0: TemporaryRef GetAsThebesSurface(); michael@0: TemporaryRef GetAsDrawTarget(gfx::BackendType aBackend); michael@0: michael@0: static uint32_t ComputeMinBufferSize(gfx::IntSize aSize, michael@0: gfx::SurfaceFormat aFormat); michael@0: michael@0: protected: michael@0: michael@0: ImageDataSerializerBase(uint8_t* aData, size_t aDataSize) michael@0: : mData(aData) michael@0: , mDataSize(aDataSize) michael@0: , mIsValid(false) michael@0: {} michael@0: michael@0: void Validate(); michael@0: michael@0: uint8_t* mData; michael@0: size_t mDataSize; michael@0: bool mIsValid; michael@0: }; michael@0: michael@0: /** michael@0: * A facility to serialize an image into a buffer of memory. michael@0: * This is intended for use with the IPC code, in order to copy image data michael@0: * into shared memory. michael@0: * Note that there is a separate serializer class for YCbCr images michael@0: * (see YCbCrImageDataSerializer.h). michael@0: */ michael@0: class MOZ_STACK_CLASS ImageDataSerializer : public ImageDataSerializerBase michael@0: { michael@0: public: michael@0: ImageDataSerializer(uint8_t* aData, size_t aDataSize) michael@0: : ImageDataSerializerBase(aData, aDataSize) michael@0: { michael@0: // a serializer needs to be usable before correct buffer info has been written to it michael@0: mIsValid = !!mData; michael@0: } michael@0: void InitializeBufferInfo(gfx::IntSize aSize, michael@0: gfx::SurfaceFormat aFormat); michael@0: }; michael@0: michael@0: /** michael@0: * A facility to deserialize image data that has been serialized by an michael@0: * ImageDataSerializer. michael@0: */ michael@0: class MOZ_STACK_CLASS ImageDataDeserializer : public ImageDataSerializerBase michael@0: { michael@0: public: michael@0: ImageDataDeserializer(uint8_t* aData, size_t aDataSize) michael@0: : ImageDataSerializerBase(aData, aDataSize) michael@0: { michael@0: Validate(); michael@0: } michael@0: michael@0: }; michael@0: michael@0: } // namespace layers michael@0: } // namespace mozilla michael@0: michael@0: #endif