1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/gonk/HwcUtils.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,121 @@ 1.4 +/* 1.5 + * Copyright (c) 2013, 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_HwcUtils 1.21 +#define mozilla_HwcUtils 1.22 + 1.23 +#include "Layers.h" 1.24 +#include <vector> 1.25 +#include "hardware/hwcomposer.h" 1.26 + 1.27 +namespace mozilla { 1.28 + 1.29 +class HwcUtils { 1.30 +public: 1.31 + 1.32 +enum { 1.33 + HWC_USE_GPU = HWC_FRAMEBUFFER, 1.34 + HWC_USE_OVERLAY = HWC_OVERLAY, 1.35 + HWC_USE_COPYBIT 1.36 +}; 1.37 + 1.38 +// HWC layer flags 1.39 +enum { 1.40 + // Draw a solid color rectangle 1.41 + // The color should be set on the transform member of the hwc_layer_t struct 1.42 + // The expected format is a 32 bit ABGR with 8 bits per component 1.43 + HWC_COLOR_FILL = 0x8, 1.44 + // Swap the RB pixels of gralloc buffer, like RGBA<->BGRA or RGBX<->BGRX 1.45 + // The flag will be set inside LayerRenderState 1.46 + HWC_FORMAT_RB_SWAP = 0x40 1.47 +}; 1.48 + 1.49 +typedef std::vector<hwc_rect_t> RectVector; 1.50 + 1.51 +/* Utility functions - implemented in HwcUtils.cpp */ 1.52 + 1.53 +/** 1.54 + * Calculates the layer's clipping rectangle 1.55 + * 1.56 + * @param aTransform Input. A transformation matrix 1.57 + * It transforms the clip rect to screen space 1.58 + * @param aLayerClip Input. The layer's internal clipping rectangle. 1.59 + * This may be NULL which means the layer has no internal clipping 1.60 + * The origin is the top-left corner of the layer 1.61 + * @param aParentClip Input. The parent layer's rendering clipping rectangle 1.62 + * The origin is the top-left corner of the screen 1.63 + * @param aRenderClip Output. The layer's rendering clipping rectangle 1.64 + * The origin is the top-left corner of the screen 1.65 + * @return true if the layer should be rendered. 1.66 + * false if the layer can be skipped 1.67 + */ 1.68 +static bool CalculateClipRect(const gfxMatrix& aTransform, 1.69 + const nsIntRect* aLayerClip, 1.70 + nsIntRect aParentClip, nsIntRect* aRenderClip); 1.71 + 1.72 + 1.73 +/** 1.74 + * Prepares hwc layer visible region required for hwc composition 1.75 + * 1.76 + * @param aVisible Input. Layer's unclipped visible region 1.77 + * The origin is the top-left corner of the layer 1.78 + * @param aTransform Input. Layer's transformation matrix 1.79 + * It transforms from layer space to screen space 1.80 + * @param aClip Input. A clipping rectangle. 1.81 + * The origin is the top-left corner of the screen 1.82 + * @param aBufferRect Input. The layer's buffer bounds 1.83 + * The origin is the top-left corner of the layer 1.84 + * @param aVisibleRegionScreen Output. Visible region in screen space. 1.85 + * The origin is the top-left corner of the screen 1.86 + * @return true if the layer should be rendered. 1.87 + * false if the layer can be skipped 1.88 + */ 1.89 +static bool PrepareVisibleRegion(const nsIntRegion& aVisible, 1.90 + const gfxMatrix& aTransform, 1.91 + nsIntRect aClip, nsIntRect aBufferRect, 1.92 + RectVector* aVisibleRegionScreen); 1.93 + 1.94 + 1.95 +/** 1.96 + * Sets hwc layer rectangles required for hwc composition 1.97 + * 1.98 + * @param aVisible Input. Layer's unclipped visible rectangle 1.99 + * The origin is the top-left corner of the layer 1.100 + * @param aTransform Input. Layer's transformation matrix 1.101 + * It transforms from layer space to screen space 1.102 + * @param aClip Input. A clipping rectangle. 1.103 + * The origin is the top-left corner of the screen 1.104 + * @param aBufferRect Input. The layer's buffer bounds 1.105 + * The origin is the top-left corner of the layer 1.106 + * @param aYFlipped Input. true if the buffer is rendered as Y flipped 1.107 + * @param aSurceCrop Output. Area of the source to consider, 1.108 + * the origin is the top-left corner of the buffer 1.109 + * @param aVisibleRegionScreen Output. Visible region in screen space. 1.110 + * The origin is the top-left corner of the screen 1.111 + * @return true if the layer should be rendered. 1.112 + * false if the layer can be skipped 1.113 + */ 1.114 +static bool PrepareLayerRects(nsIntRect aVisible, const gfxMatrix& aTransform, 1.115 + nsIntRect aClip, nsIntRect aBufferRect, 1.116 + bool aYFlipped, 1.117 + hwc_rect_t* aSourceCrop, 1.118 + hwc_rect_t* aVisibleRegionScreen); 1.119 + 1.120 +}; 1.121 + 1.122 +} // namespace mozilla 1.123 + 1.124 +#endif // mozilla_HwcUtils