Bumping manifests a=b2g-bump
[gecko.git] / gfx / layers / LayersTypes.h
blob0722f2512378e855b020e132432c498c460a3b2a
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GFX_LAYERSTYPES_H
7 #define GFX_LAYERSTYPES_H
9 #include <stdint.h> // for uint32_t
10 #include "nsPoint.h" // for nsIntPoint
11 #include "nsRegion.h"
13 #include "mozilla/TypedEnum.h"
14 #include "mozilla/TypedEnumBits.h"
16 #ifdef MOZ_WIDGET_GONK
17 #include <ui/GraphicBuffer.h>
18 #endif
19 #if defined(DEBUG) || defined(PR_LOGGING)
20 # include <stdio.h> // FILE
21 # include "prlog.h" // for PR_LOG
22 # ifndef MOZ_LAYERS_HAVE_LOG
23 # define MOZ_LAYERS_HAVE_LOG
24 # endif
25 # define MOZ_LAYERS_LOG(_args) \
26 PR_LOG(LayerManager::GetLog(), PR_LOG_DEBUG, _args)
27 # define MOZ_LAYERS_LOG_IF_SHADOWABLE(layer, _args) \
28 do { if (layer->AsShadowableLayer()) { PR_LOG(LayerManager::GetLog(), PR_LOG_DEBUG, _args); } } while (0)
29 #else
30 struct PRLogModuleInfo;
31 # define MOZ_LAYERS_LOG(_args)
32 # define MOZ_LAYERS_LOG_IF_SHADOWABLE(layer, _args)
33 #endif // if defined(DEBUG) || defined(PR_LOGGING)
35 #define INVALID_OVERLAY -1
37 namespace android {
38 class GraphicBuffer;
41 namespace mozilla {
42 namespace layers {
44 class TextureHost;
46 #undef NONE
47 #undef OPAQUE
49 MOZ_BEGIN_ENUM_CLASS(LayersBackend, int8_t)
50 LAYERS_NONE = 0,
51 LAYERS_BASIC,
52 LAYERS_OPENGL,
53 LAYERS_D3D9,
54 LAYERS_D3D10,
55 LAYERS_D3D11,
56 LAYERS_CLIENT,
57 LAYERS_LAST
58 MOZ_END_ENUM_CLASS(LayersBackend)
60 MOZ_BEGIN_ENUM_CLASS(BufferMode, int8_t)
61 BUFFER_NONE,
62 BUFFERED
63 MOZ_END_ENUM_CLASS(BufferMode)
65 MOZ_BEGIN_ENUM_CLASS(DrawRegionClip, int8_t)
66 DRAW,
67 NONE
68 MOZ_END_ENUM_CLASS(DrawRegionClip)
70 MOZ_BEGIN_ENUM_CLASS(SurfaceMode, int8_t)
71 SURFACE_NONE = 0,
72 SURFACE_OPAQUE,
73 SURFACE_SINGLE_CHANNEL_ALPHA,
74 SURFACE_COMPONENT_ALPHA
75 MOZ_END_ENUM_CLASS(SurfaceMode)
77 // LayerRenderState for Composer2D
78 // We currently only support Composer2D using gralloc. If we want to be backed
79 // by other surfaces we will need a more generic LayerRenderState.
80 MOZ_BEGIN_ENUM_CLASS(LayerRenderStateFlags, int8_t)
81 LAYER_RENDER_STATE_DEFAULT = 0,
82 ORIGIN_BOTTOM_LEFT = 1 << 0,
83 BUFFER_ROTATION = 1 << 1,
84 // Notify Composer2D to swap the RB pixels of gralloc buffer
85 FORMAT_RB_SWAP = 1 << 2,
86 // We record opaqueness here alongside the actual surface we're going to
87 // render. This avoids confusion when a layer might return different kinds
88 // of surfaces over time (e.g. video frames).
89 OPAQUE = 1 << 3
90 MOZ_END_ENUM_CLASS(LayerRenderStateFlags)
91 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(LayerRenderStateFlags)
93 // The 'ifdef MOZ_WIDGET_GONK' sadness here is because we don't want to include
94 // android::sp unless we have to.
95 struct LayerRenderState {
96 LayerRenderState()
97 #ifdef MOZ_WIDGET_GONK
98 : mFlags(LayerRenderStateFlags::LAYER_RENDER_STATE_DEFAULT)
99 , mHasOwnOffset(false)
100 , mSurface(nullptr)
101 , mOverlayId(INVALID_OVERLAY)
102 , mTexture(nullptr)
103 #endif
106 #ifdef MOZ_WIDGET_GONK
107 LayerRenderState(android::GraphicBuffer* aSurface,
108 const nsIntSize& aSize,
109 LayerRenderStateFlags aFlags,
110 TextureHost* aTexture)
111 : mFlags(aFlags)
112 , mHasOwnOffset(false)
113 , mSurface(aSurface)
114 , mOverlayId(INVALID_OVERLAY)
115 , mSize(aSize)
116 , mTexture(aTexture)
119 bool OriginBottomLeft() const
120 { return bool(mFlags & LayerRenderStateFlags::ORIGIN_BOTTOM_LEFT); }
122 bool BufferRotated() const
123 { return bool(mFlags & LayerRenderStateFlags::BUFFER_ROTATION); }
125 bool FormatRBSwapped() const
126 { return bool(mFlags & LayerRenderStateFlags::FORMAT_RB_SWAP); }
128 void SetOverlayId(const int32_t& aId)
129 { mOverlayId = aId; }
130 #endif
132 void SetOffset(const nsIntPoint& aOffset)
134 mOffset = aOffset;
135 mHasOwnOffset = true;
138 // see LayerRenderStateFlags
139 LayerRenderStateFlags mFlags;
140 // true if mOffset is applicable
141 bool mHasOwnOffset;
142 // the location of the layer's origin on mSurface
143 nsIntPoint mOffset;
144 #ifdef MOZ_WIDGET_GONK
145 // surface to render
146 android::sp<android::GraphicBuffer> mSurface;
147 int32_t mOverlayId;
148 // size of mSurface
149 nsIntSize mSize;
150 TextureHost* mTexture;
151 #endif
154 MOZ_BEGIN_ENUM_CLASS(ScaleMode, int8_t)
155 SCALE_NONE,
156 STRETCH,
157 SENTINEL
158 // Unimplemented - PRESERVE_ASPECT_RATIO_CONTAIN
159 MOZ_END_ENUM_CLASS(ScaleMode)
161 struct EventRegions {
162 nsIntRegion mHitRegion;
163 nsIntRegion mDispatchToContentHitRegion;
165 EventRegions()
169 explicit EventRegions(nsIntRegion aHitRegion)
170 : mHitRegion(aHitRegion)
174 bool operator==(const EventRegions& aRegions) const
176 return mHitRegion == aRegions.mHitRegion &&
177 mDispatchToContentHitRegion == aRegions.mDispatchToContentHitRegion;
179 bool operator!=(const EventRegions& aRegions) const
181 return !(*this == aRegions);
184 void OrWith(const EventRegions& aOther)
186 mHitRegion.OrWith(aOther.mHitRegion);
187 mDispatchToContentHitRegion.OrWith(aOther.mDispatchToContentHitRegion);
190 void AndWith(const nsIntRegion& aRegion)
192 mHitRegion.AndWith(aRegion);
193 mDispatchToContentHitRegion.AndWith(aRegion);
196 void Sub(const EventRegions& aMinuend, const nsIntRegion& aSubtrahend)
198 mHitRegion.Sub(aMinuend.mHitRegion, aSubtrahend);
199 mDispatchToContentHitRegion.Sub(aMinuend.mDispatchToContentHitRegion, aSubtrahend);
202 void ApplyTranslationAndScale(float aXTrans, float aYTrans, float aXScale, float aYScale)
204 mHitRegion.ScaleRoundOut(aXScale, aYScale);
205 mDispatchToContentHitRegion.ScaleRoundOut(aXScale, aYScale);
207 mHitRegion.MoveBy(aXTrans, aYTrans);
208 mDispatchToContentHitRegion.MoveBy(aXTrans, aYTrans);
211 void Transform(const gfx3DMatrix& aTransform)
213 mHitRegion.Transform(aTransform);
214 mDispatchToContentHitRegion.Transform(aTransform);
217 bool IsEmpty() const
219 return mHitRegion.IsEmpty()
220 && mDispatchToContentHitRegion.IsEmpty();
223 nsCString ToString() const
225 nsCString result = mHitRegion.ToString();
226 result.AppendLiteral(";dispatchToContent=");
227 result.Append(mDispatchToContentHitRegion.ToString());
228 return result;
232 // Bit flags that go on a ContainerLayer (or RefLayer) and override the
233 // event regions in the entire subtree below. This is needed for propagating
234 // various flags across processes since the child-process layout code doesn't
235 // know about parent-process listeners or CSS rules.
236 enum EventRegionsOverride {
237 // The default, no flags set
238 NoOverride = 0,
239 // Treat all hit regions in the subtree as dispatch-to-content
240 ForceDispatchToContent = (1 << 0),
241 // Treat all hit regions in the subtree as empty
242 ForceEmptyHitRegion = (1 << 1),
243 // OR union of all valid bit flags, for use in BitFlagsEnumSerializer
244 ALL_BITS = (1 << 2) - 1
247 MOZ_ALWAYS_INLINE EventRegionsOverride
248 operator|(EventRegionsOverride a, EventRegionsOverride b)
250 return (EventRegionsOverride)((int)a | (int)b);
253 MOZ_ALWAYS_INLINE EventRegionsOverride&
254 operator|=(EventRegionsOverride& a, EventRegionsOverride b)
256 a = a | b;
257 return a;
260 } // namespace
261 } // namespace
263 #endif /* GFX_LAYERSTYPES_H */