michael@0: /* michael@0: * Copyright (c) 2012, The Linux Foundation. All rights reserved. michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef mozilla_HwcComposer2D michael@0: #define mozilla_HwcComposer2D michael@0: michael@0: #include "Composer2D.h" michael@0: #include "Layers.h" michael@0: #include michael@0: #include michael@0: michael@0: #include michael@0: #if ANDROID_VERSION >= 17 michael@0: #include michael@0: #endif michael@0: michael@0: namespace mozilla { michael@0: michael@0: namespace layers { michael@0: class ContainerLayer; michael@0: class Layer; michael@0: } michael@0: michael@0: //Holds a dynamically allocated vector of rectangles michael@0: //used to decribe the complex visible region of a layer michael@0: typedef std::vector RectVector; michael@0: #if ANDROID_VERSION >= 17 michael@0: typedef hwc_composer_device_1_t HwcDevice; michael@0: typedef hwc_display_contents_1_t HwcList; michael@0: typedef hwc_layer_1_t HwcLayer; michael@0: #else michael@0: typedef hwc_composer_device_t HwcDevice; michael@0: typedef hwc_layer_list_t HwcList; michael@0: typedef hwc_layer_t HwcLayer; michael@0: #endif michael@0: michael@0: /* michael@0: * HwcComposer2D provides a way for gecko to render frames michael@0: * using hwcomposer.h in the AOSP HAL. michael@0: * michael@0: * hwcomposer.h defines an interface for display composition michael@0: * using dedicated hardware. This hardware is usually faster michael@0: * or more power efficient than the GPU. However, in exchange michael@0: * for better performance, generality has to be sacrificed: michael@0: * no 3d transforms, no intermediate surfaces, no special shader effects, michael@0: * and loss of other goodies depending on the platform. michael@0: * michael@0: * In general, when hwc is enabled gecko tries to compose michael@0: * its frames using HwcComposer2D first. Then if HwcComposer2D is michael@0: * unable to compose a frame then it falls back to compose it michael@0: * using the GPU with OpenGL. michael@0: * michael@0: */ michael@0: class HwcComposer2D : public mozilla::layers::Composer2D { michael@0: public: michael@0: HwcComposer2D(); michael@0: virtual ~HwcComposer2D(); michael@0: michael@0: int Init(hwc_display_t aDisplay, hwc_surface_t aSurface); michael@0: michael@0: bool Initialized() const { return mHwc; } michael@0: michael@0: static HwcComposer2D* GetInstance(); michael@0: michael@0: // Returns TRUE if the container has been succesfully rendered michael@0: // Returns FALSE if the container cannot be fully rendered michael@0: // by this composer so nothing was rendered at all michael@0: bool TryRender(layers::Layer* aRoot, const gfx::Matrix& aGLWorldTransform, michael@0: bool aGeometryChanged) MOZ_OVERRIDE; michael@0: michael@0: bool Render(EGLDisplay dpy, EGLSurface sur); michael@0: michael@0: private: michael@0: void Reset(); michael@0: void Prepare(buffer_handle_t fbHandle, int fence); michael@0: bool Commit(); michael@0: bool TryHwComposition(); michael@0: bool ReallocLayerList(); michael@0: bool PrepareLayerList(layers::Layer* aContainer, const nsIntRect& aClip, michael@0: const gfxMatrix& aParentTransform, const gfxMatrix& aGLWorldTransform); michael@0: void setCrop(HwcLayer* layer, hwc_rect_t srcCrop); michael@0: void setHwcGeometry(bool aGeometryChanged); michael@0: michael@0: HwcDevice* mHwc; michael@0: HwcList* mList; michael@0: hwc_display_t mDpy; michael@0: hwc_surface_t mSur; michael@0: nsIntRect mScreenRect; michael@0: int mMaxLayerCount; michael@0: bool mColorFill; michael@0: bool mRBSwapSupport; michael@0: //Holds all the dynamically allocated RectVectors needed michael@0: //to render the current frame michael@0: std::list mVisibleRegions; michael@0: #if ANDROID_VERSION >= 17 michael@0: android::sp mPrevRetireFence; michael@0: android::sp mPrevDisplayFence; michael@0: #endif michael@0: nsTArray mHwcLayerMap; michael@0: bool mPrepared; michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_HwcComposer2D