michael@0: /* michael@0: * Copyright (c) 2013, 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_HwcUtils michael@0: #define mozilla_HwcUtils michael@0: michael@0: #include "Layers.h" michael@0: #include michael@0: #include "hardware/hwcomposer.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: class HwcUtils { michael@0: public: michael@0: michael@0: enum { michael@0: HWC_USE_GPU = HWC_FRAMEBUFFER, michael@0: HWC_USE_OVERLAY = HWC_OVERLAY, michael@0: HWC_USE_COPYBIT michael@0: }; michael@0: michael@0: // HWC layer flags michael@0: enum { michael@0: // Draw a solid color rectangle michael@0: // The color should be set on the transform member of the hwc_layer_t struct michael@0: // The expected format is a 32 bit ABGR with 8 bits per component michael@0: HWC_COLOR_FILL = 0x8, michael@0: // Swap the RB pixels of gralloc buffer, like RGBA<->BGRA or RGBX<->BGRX michael@0: // The flag will be set inside LayerRenderState michael@0: HWC_FORMAT_RB_SWAP = 0x40 michael@0: }; michael@0: michael@0: typedef std::vector RectVector; michael@0: michael@0: /* Utility functions - implemented in HwcUtils.cpp */ michael@0: michael@0: /** michael@0: * Calculates the layer's clipping rectangle michael@0: * michael@0: * @param aTransform Input. A transformation matrix michael@0: * It transforms the clip rect to screen space michael@0: * @param aLayerClip Input. The layer's internal clipping rectangle. michael@0: * This may be NULL which means the layer has no internal clipping michael@0: * The origin is the top-left corner of the layer michael@0: * @param aParentClip Input. The parent layer's rendering clipping rectangle michael@0: * The origin is the top-left corner of the screen michael@0: * @param aRenderClip Output. The layer's rendering clipping rectangle michael@0: * The origin is the top-left corner of the screen michael@0: * @return true if the layer should be rendered. michael@0: * false if the layer can be skipped michael@0: */ michael@0: static bool CalculateClipRect(const gfxMatrix& aTransform, michael@0: const nsIntRect* aLayerClip, michael@0: nsIntRect aParentClip, nsIntRect* aRenderClip); michael@0: michael@0: michael@0: /** michael@0: * Prepares hwc layer visible region required for hwc composition michael@0: * michael@0: * @param aVisible Input. Layer's unclipped visible region michael@0: * The origin is the top-left corner of the layer michael@0: * @param aTransform Input. Layer's transformation matrix michael@0: * It transforms from layer space to screen space michael@0: * @param aClip Input. A clipping rectangle. michael@0: * The origin is the top-left corner of the screen michael@0: * @param aBufferRect Input. The layer's buffer bounds michael@0: * The origin is the top-left corner of the layer michael@0: * @param aVisibleRegionScreen Output. Visible region in screen space. michael@0: * The origin is the top-left corner of the screen michael@0: * @return true if the layer should be rendered. michael@0: * false if the layer can be skipped michael@0: */ michael@0: static bool PrepareVisibleRegion(const nsIntRegion& aVisible, michael@0: const gfxMatrix& aTransform, michael@0: nsIntRect aClip, nsIntRect aBufferRect, michael@0: RectVector* aVisibleRegionScreen); michael@0: michael@0: michael@0: /** michael@0: * Sets hwc layer rectangles required for hwc composition michael@0: * michael@0: * @param aVisible Input. Layer's unclipped visible rectangle michael@0: * The origin is the top-left corner of the layer michael@0: * @param aTransform Input. Layer's transformation matrix michael@0: * It transforms from layer space to screen space michael@0: * @param aClip Input. A clipping rectangle. michael@0: * The origin is the top-left corner of the screen michael@0: * @param aBufferRect Input. The layer's buffer bounds michael@0: * The origin is the top-left corner of the layer michael@0: * @param aYFlipped Input. true if the buffer is rendered as Y flipped michael@0: * @param aSurceCrop Output. Area of the source to consider, michael@0: * the origin is the top-left corner of the buffer michael@0: * @param aVisibleRegionScreen Output. Visible region in screen space. michael@0: * The origin is the top-left corner of the screen michael@0: * @return true if the layer should be rendered. michael@0: * false if the layer can be skipped michael@0: */ michael@0: static bool PrepareLayerRects(nsIntRect aVisible, const gfxMatrix& aTransform, michael@0: nsIntRect aClip, nsIntRect aBufferRect, michael@0: bool aYFlipped, michael@0: hwc_rect_t* aSourceCrop, michael@0: hwc_rect_t* aVisibleRegionScreen); michael@0: michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_HwcUtils