|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * vim: sw=2 ts=8 et : |
|
3 */ |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #ifndef GFX_LAYERS_BLOBSURFACE_H |
|
9 #define GFX_LAYERS_BLOBSURFACE_H |
|
10 |
|
11 #include <stdint.h> // for uint8_t, uint32_t |
|
12 #include "mozilla/Attributes.h" // for MOZ_STACK_CLASS |
|
13 #include "mozilla/RefPtr.h" // for TemporaryRef |
|
14 #include "mozilla/gfx/Point.h" // for IntSize |
|
15 #include "mozilla/gfx/Types.h" // for SurfaceFormat |
|
16 |
|
17 class gfxImageSurface; |
|
18 |
|
19 namespace mozilla { |
|
20 namespace gfx { |
|
21 class DataSourceSurface; |
|
22 class DrawTarget; |
|
23 } // namespace gfx |
|
24 } // namespace mozilla |
|
25 |
|
26 namespace mozilla { |
|
27 namespace layers { |
|
28 |
|
29 class ImageDataSerializerBase |
|
30 { |
|
31 public: |
|
32 bool IsValid() const { return mIsValid; } |
|
33 |
|
34 uint8_t* GetData(); |
|
35 uint32_t GetStride() const; |
|
36 gfx::IntSize GetSize() const; |
|
37 gfx::SurfaceFormat GetFormat() const; |
|
38 TemporaryRef<gfx::DataSourceSurface> GetAsSurface(); |
|
39 TemporaryRef<gfxImageSurface> GetAsThebesSurface(); |
|
40 TemporaryRef<gfx::DrawTarget> GetAsDrawTarget(gfx::BackendType aBackend); |
|
41 |
|
42 static uint32_t ComputeMinBufferSize(gfx::IntSize aSize, |
|
43 gfx::SurfaceFormat aFormat); |
|
44 |
|
45 protected: |
|
46 |
|
47 ImageDataSerializerBase(uint8_t* aData, size_t aDataSize) |
|
48 : mData(aData) |
|
49 , mDataSize(aDataSize) |
|
50 , mIsValid(false) |
|
51 {} |
|
52 |
|
53 void Validate(); |
|
54 |
|
55 uint8_t* mData; |
|
56 size_t mDataSize; |
|
57 bool mIsValid; |
|
58 }; |
|
59 |
|
60 /** |
|
61 * A facility to serialize an image into a buffer of memory. |
|
62 * This is intended for use with the IPC code, in order to copy image data |
|
63 * into shared memory. |
|
64 * Note that there is a separate serializer class for YCbCr images |
|
65 * (see YCbCrImageDataSerializer.h). |
|
66 */ |
|
67 class MOZ_STACK_CLASS ImageDataSerializer : public ImageDataSerializerBase |
|
68 { |
|
69 public: |
|
70 ImageDataSerializer(uint8_t* aData, size_t aDataSize) |
|
71 : ImageDataSerializerBase(aData, aDataSize) |
|
72 { |
|
73 // a serializer needs to be usable before correct buffer info has been written to it |
|
74 mIsValid = !!mData; |
|
75 } |
|
76 void InitializeBufferInfo(gfx::IntSize aSize, |
|
77 gfx::SurfaceFormat aFormat); |
|
78 }; |
|
79 |
|
80 /** |
|
81 * A facility to deserialize image data that has been serialized by an |
|
82 * ImageDataSerializer. |
|
83 */ |
|
84 class MOZ_STACK_CLASS ImageDataDeserializer : public ImageDataSerializerBase |
|
85 { |
|
86 public: |
|
87 ImageDataDeserializer(uint8_t* aData, size_t aDataSize) |
|
88 : ImageDataSerializerBase(aData, aDataSize) |
|
89 { |
|
90 Validate(); |
|
91 } |
|
92 |
|
93 }; |
|
94 |
|
95 } // namespace layers |
|
96 } // namespace mozilla |
|
97 |
|
98 #endif |