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