1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/ImageDataSerializer.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=8 et : 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#ifndef GFX_LAYERS_BLOBSURFACE_H 1.12 +#define GFX_LAYERS_BLOBSURFACE_H 1.13 + 1.14 +#include <stdint.h> // for uint8_t, uint32_t 1.15 +#include "mozilla/Attributes.h" // for MOZ_STACK_CLASS 1.16 +#include "mozilla/RefPtr.h" // for TemporaryRef 1.17 +#include "mozilla/gfx/Point.h" // for IntSize 1.18 +#include "mozilla/gfx/Types.h" // for SurfaceFormat 1.19 + 1.20 +class gfxImageSurface; 1.21 + 1.22 +namespace mozilla { 1.23 +namespace gfx { 1.24 +class DataSourceSurface; 1.25 +class DrawTarget; 1.26 +} // namespace gfx 1.27 +} // namespace mozilla 1.28 + 1.29 +namespace mozilla { 1.30 +namespace layers { 1.31 + 1.32 +class ImageDataSerializerBase 1.33 +{ 1.34 +public: 1.35 + bool IsValid() const { return mIsValid; } 1.36 + 1.37 + uint8_t* GetData(); 1.38 + uint32_t GetStride() const; 1.39 + gfx::IntSize GetSize() const; 1.40 + gfx::SurfaceFormat GetFormat() const; 1.41 + TemporaryRef<gfx::DataSourceSurface> GetAsSurface(); 1.42 + TemporaryRef<gfxImageSurface> GetAsThebesSurface(); 1.43 + TemporaryRef<gfx::DrawTarget> GetAsDrawTarget(gfx::BackendType aBackend); 1.44 + 1.45 + static uint32_t ComputeMinBufferSize(gfx::IntSize aSize, 1.46 + gfx::SurfaceFormat aFormat); 1.47 + 1.48 +protected: 1.49 + 1.50 + ImageDataSerializerBase(uint8_t* aData, size_t aDataSize) 1.51 + : mData(aData) 1.52 + , mDataSize(aDataSize) 1.53 + , mIsValid(false) 1.54 + {} 1.55 + 1.56 + void Validate(); 1.57 + 1.58 + uint8_t* mData; 1.59 + size_t mDataSize; 1.60 + bool mIsValid; 1.61 +}; 1.62 + 1.63 +/** 1.64 + * A facility to serialize an image into a buffer of memory. 1.65 + * This is intended for use with the IPC code, in order to copy image data 1.66 + * into shared memory. 1.67 + * Note that there is a separate serializer class for YCbCr images 1.68 + * (see YCbCrImageDataSerializer.h). 1.69 + */ 1.70 +class MOZ_STACK_CLASS ImageDataSerializer : public ImageDataSerializerBase 1.71 +{ 1.72 +public: 1.73 + ImageDataSerializer(uint8_t* aData, size_t aDataSize) 1.74 + : ImageDataSerializerBase(aData, aDataSize) 1.75 + { 1.76 + // a serializer needs to be usable before correct buffer info has been written to it 1.77 + mIsValid = !!mData; 1.78 + } 1.79 + void InitializeBufferInfo(gfx::IntSize aSize, 1.80 + gfx::SurfaceFormat aFormat); 1.81 +}; 1.82 + 1.83 +/** 1.84 + * A facility to deserialize image data that has been serialized by an 1.85 + * ImageDataSerializer. 1.86 + */ 1.87 +class MOZ_STACK_CLASS ImageDataDeserializer : public ImageDataSerializerBase 1.88 +{ 1.89 +public: 1.90 + ImageDataDeserializer(uint8_t* aData, size_t aDataSize) 1.91 + : ImageDataSerializerBase(aData, aDataSize) 1.92 + { 1.93 + Validate(); 1.94 + } 1.95 + 1.96 +}; 1.97 + 1.98 +} // namespace layers 1.99 +} // namespace mozilla 1.100 + 1.101 +#endif