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
13 #include "mozilla/TypedEnum.h"
14 #include "mozilla/TypedEnumBits.h"
16 #ifdef MOZ_WIDGET_GONK
17 #include <ui/GraphicBuffer.h>
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
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)
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
49 MOZ_BEGIN_ENUM_CLASS(LayersBackend
, int8_t)
58 MOZ_END_ENUM_CLASS(LayersBackend
)
60 MOZ_BEGIN_ENUM_CLASS(BufferMode
, int8_t)
63 MOZ_END_ENUM_CLASS(BufferMode
)
65 MOZ_BEGIN_ENUM_CLASS(DrawRegionClip
, int8_t)
68 MOZ_END_ENUM_CLASS(DrawRegionClip
)
70 MOZ_BEGIN_ENUM_CLASS(SurfaceMode
, int8_t)
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).
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
{
97 #ifdef MOZ_WIDGET_GONK
98 : mFlags(LayerRenderStateFlags::LAYER_RENDER_STATE_DEFAULT
)
99 , mHasOwnOffset(false)
101 , mOverlayId(INVALID_OVERLAY
)
106 #ifdef MOZ_WIDGET_GONK
107 LayerRenderState(android::GraphicBuffer
* aSurface
,
108 const nsIntSize
& aSize
,
109 LayerRenderStateFlags aFlags
,
110 TextureHost
* aTexture
)
112 , mHasOwnOffset(false)
114 , mOverlayId(INVALID_OVERLAY
)
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
; }
132 void SetOffset(const nsIntPoint
& aOffset
)
135 mHasOwnOffset
= true;
138 // see LayerRenderStateFlags
139 LayerRenderStateFlags mFlags
;
140 // true if mOffset is applicable
142 // the location of the layer's origin on mSurface
144 #ifdef MOZ_WIDGET_GONK
146 android::sp
<android::GraphicBuffer
> mSurface
;
150 TextureHost
* mTexture
;
154 MOZ_BEGIN_ENUM_CLASS(ScaleMode
, int8_t)
158 // Unimplemented - PRESERVE_ASPECT_RATIO_CONTAIN
159 MOZ_END_ENUM_CLASS(ScaleMode
)
161 struct EventRegions
{
162 nsIntRegion mHitRegion
;
163 nsIntRegion mDispatchToContentHitRegion
;
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
);
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());
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
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
)
263 #endif /* GFX_LAYERSTYPES_H */