Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /*
2 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
17 #ifndef mozilla_HwcComposer2D
18 #define mozilla_HwcComposer2D
20 #include "Composer2D.h"
21 #include "Layers.h"
22 #include <vector>
23 #include <list>
25 #include <hardware/hwcomposer.h>
26 #if ANDROID_VERSION >= 17
27 #include <ui/Fence.h>
28 #endif
30 namespace mozilla {
32 namespace layers {
33 class ContainerLayer;
34 class Layer;
35 }
37 //Holds a dynamically allocated vector of rectangles
38 //used to decribe the complex visible region of a layer
39 typedef std::vector<hwc_rect_t> RectVector;
40 #if ANDROID_VERSION >= 17
41 typedef hwc_composer_device_1_t HwcDevice;
42 typedef hwc_display_contents_1_t HwcList;
43 typedef hwc_layer_1_t HwcLayer;
44 #else
45 typedef hwc_composer_device_t HwcDevice;
46 typedef hwc_layer_list_t HwcList;
47 typedef hwc_layer_t HwcLayer;
48 #endif
50 /*
51 * HwcComposer2D provides a way for gecko to render frames
52 * using hwcomposer.h in the AOSP HAL.
53 *
54 * hwcomposer.h defines an interface for display composition
55 * using dedicated hardware. This hardware is usually faster
56 * or more power efficient than the GPU. However, in exchange
57 * for better performance, generality has to be sacrificed:
58 * no 3d transforms, no intermediate surfaces, no special shader effects,
59 * and loss of other goodies depending on the platform.
60 *
61 * In general, when hwc is enabled gecko tries to compose
62 * its frames using HwcComposer2D first. Then if HwcComposer2D is
63 * unable to compose a frame then it falls back to compose it
64 * using the GPU with OpenGL.
65 *
66 */
67 class HwcComposer2D : public mozilla::layers::Composer2D {
68 public:
69 HwcComposer2D();
70 virtual ~HwcComposer2D();
72 int Init(hwc_display_t aDisplay, hwc_surface_t aSurface);
74 bool Initialized() const { return mHwc; }
76 static HwcComposer2D* GetInstance();
78 // Returns TRUE if the container has been succesfully rendered
79 // Returns FALSE if the container cannot be fully rendered
80 // by this composer so nothing was rendered at all
81 bool TryRender(layers::Layer* aRoot, const gfx::Matrix& aGLWorldTransform,
82 bool aGeometryChanged) MOZ_OVERRIDE;
84 bool Render(EGLDisplay dpy, EGLSurface sur);
86 private:
87 void Reset();
88 void Prepare(buffer_handle_t fbHandle, int fence);
89 bool Commit();
90 bool TryHwComposition();
91 bool ReallocLayerList();
92 bool PrepareLayerList(layers::Layer* aContainer, const nsIntRect& aClip,
93 const gfxMatrix& aParentTransform, const gfxMatrix& aGLWorldTransform);
94 void setCrop(HwcLayer* layer, hwc_rect_t srcCrop);
95 void setHwcGeometry(bool aGeometryChanged);
97 HwcDevice* mHwc;
98 HwcList* mList;
99 hwc_display_t mDpy;
100 hwc_surface_t mSur;
101 nsIntRect mScreenRect;
102 int mMaxLayerCount;
103 bool mColorFill;
104 bool mRBSwapSupport;
105 //Holds all the dynamically allocated RectVectors needed
106 //to render the current frame
107 std::list<RectVector> mVisibleRegions;
108 #if ANDROID_VERSION >= 17
109 android::sp<android::Fence> mPrevRetireFence;
110 android::sp<android::Fence> mPrevDisplayFence;
111 #endif
112 nsTArray<layers::LayerComposite*> mHwcLayerMap;
113 bool mPrepared;
114 };
116 } // namespace mozilla
118 #endif // mozilla_HwcComposer2D