1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/gonk/HwcComposer2D.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, The Linux Foundation. All rights reserved. 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 + 1.20 +#ifndef mozilla_HwcComposer2D 1.21 +#define mozilla_HwcComposer2D 1.22 + 1.23 +#include "Composer2D.h" 1.24 +#include "Layers.h" 1.25 +#include <vector> 1.26 +#include <list> 1.27 + 1.28 +#include <hardware/hwcomposer.h> 1.29 +#if ANDROID_VERSION >= 17 1.30 +#include <ui/Fence.h> 1.31 +#endif 1.32 + 1.33 +namespace mozilla { 1.34 + 1.35 +namespace layers { 1.36 +class ContainerLayer; 1.37 +class Layer; 1.38 +} 1.39 + 1.40 +//Holds a dynamically allocated vector of rectangles 1.41 +//used to decribe the complex visible region of a layer 1.42 +typedef std::vector<hwc_rect_t> RectVector; 1.43 +#if ANDROID_VERSION >= 17 1.44 +typedef hwc_composer_device_1_t HwcDevice; 1.45 +typedef hwc_display_contents_1_t HwcList; 1.46 +typedef hwc_layer_1_t HwcLayer; 1.47 +#else 1.48 +typedef hwc_composer_device_t HwcDevice; 1.49 +typedef hwc_layer_list_t HwcList; 1.50 +typedef hwc_layer_t HwcLayer; 1.51 +#endif 1.52 + 1.53 +/* 1.54 + * HwcComposer2D provides a way for gecko to render frames 1.55 + * using hwcomposer.h in the AOSP HAL. 1.56 + * 1.57 + * hwcomposer.h defines an interface for display composition 1.58 + * using dedicated hardware. This hardware is usually faster 1.59 + * or more power efficient than the GPU. However, in exchange 1.60 + * for better performance, generality has to be sacrificed: 1.61 + * no 3d transforms, no intermediate surfaces, no special shader effects, 1.62 + * and loss of other goodies depending on the platform. 1.63 + * 1.64 + * In general, when hwc is enabled gecko tries to compose 1.65 + * its frames using HwcComposer2D first. Then if HwcComposer2D is 1.66 + * unable to compose a frame then it falls back to compose it 1.67 + * using the GPU with OpenGL. 1.68 + * 1.69 + */ 1.70 +class HwcComposer2D : public mozilla::layers::Composer2D { 1.71 +public: 1.72 + HwcComposer2D(); 1.73 + virtual ~HwcComposer2D(); 1.74 + 1.75 + int Init(hwc_display_t aDisplay, hwc_surface_t aSurface); 1.76 + 1.77 + bool Initialized() const { return mHwc; } 1.78 + 1.79 + static HwcComposer2D* GetInstance(); 1.80 + 1.81 + // Returns TRUE if the container has been succesfully rendered 1.82 + // Returns FALSE if the container cannot be fully rendered 1.83 + // by this composer so nothing was rendered at all 1.84 + bool TryRender(layers::Layer* aRoot, const gfx::Matrix& aGLWorldTransform, 1.85 + bool aGeometryChanged) MOZ_OVERRIDE; 1.86 + 1.87 + bool Render(EGLDisplay dpy, EGLSurface sur); 1.88 + 1.89 +private: 1.90 + void Reset(); 1.91 + void Prepare(buffer_handle_t fbHandle, int fence); 1.92 + bool Commit(); 1.93 + bool TryHwComposition(); 1.94 + bool ReallocLayerList(); 1.95 + bool PrepareLayerList(layers::Layer* aContainer, const nsIntRect& aClip, 1.96 + const gfxMatrix& aParentTransform, const gfxMatrix& aGLWorldTransform); 1.97 + void setCrop(HwcLayer* layer, hwc_rect_t srcCrop); 1.98 + void setHwcGeometry(bool aGeometryChanged); 1.99 + 1.100 + HwcDevice* mHwc; 1.101 + HwcList* mList; 1.102 + hwc_display_t mDpy; 1.103 + hwc_surface_t mSur; 1.104 + nsIntRect mScreenRect; 1.105 + int mMaxLayerCount; 1.106 + bool mColorFill; 1.107 + bool mRBSwapSupport; 1.108 + //Holds all the dynamically allocated RectVectors needed 1.109 + //to render the current frame 1.110 + std::list<RectVector> mVisibleRegions; 1.111 +#if ANDROID_VERSION >= 17 1.112 + android::sp<android::Fence> mPrevRetireFence; 1.113 + android::sp<android::Fence> mPrevDisplayFence; 1.114 +#endif 1.115 + nsTArray<layers::LayerComposite*> mHwcLayerMap; 1.116 + bool mPrepared; 1.117 +}; 1.118 + 1.119 +} // namespace mozilla 1.120 + 1.121 +#endif // mozilla_HwcComposer2D