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