widget/gonk/HwcUtils.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * Copyright (c) 2013 The Linux Foundation. All rights reserved.
     3  *
     4  * Licensed under the Apache License, Version 2.0 (the "License");
     5  * you may not use this file except in compliance with the License.
     6  * You may obtain a copy of the License at
     7  *
     8  *      http://www.apache.org/licenses/LICENSE-2.0
     9  *
    10  * Unless required by applicable law or agreed to in writing, software
    11  * distributed under the License is distributed on an "AS IS" BASIS,
    12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  * See the License for the specific language governing permissions and
    14  * limitations under the License.
    15  */
    17 #include <android/log.h>
    18 #include "HwcUtils.h"
    19 #include "gfxUtils.h"
    21 #define LOG_TAG "HwcUtils"
    23 #if (LOG_NDEBUG == 0)
    24 #define LOGD(args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, ## args)
    25 #else
    26 #define LOGD(args...) ((void)0)
    27 #endif
    29 #define LOGE(args...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, ## args)
    32 namespace mozilla {
    34 /* Utility functions for HwcComposer */
    38 /* static */ bool
    39 HwcUtils::PrepareLayerRects(nsIntRect aVisible, const gfxMatrix& aTransform,
    40                             nsIntRect aClip, nsIntRect aBufferRect,
    41                             bool aYFlipped,
    42                             hwc_rect_t* aSourceCrop, hwc_rect_t* aVisibleRegionScreen) {
    44     gfxRect visibleRect(aVisible);
    45     gfxRect clip(aClip);
    46     gfxRect visibleRectScreen = aTransform.TransformBounds(visibleRect);
    47     // |clip| is guaranteed to be integer
    48     visibleRectScreen.IntersectRect(visibleRectScreen, clip);
    50     if (visibleRectScreen.IsEmpty()) {
    51         LOGD("Skip layer");
    52         return false;
    53     }
    55     gfxMatrix inverse(aTransform);
    56     inverse.Invert();
    57     gfxRect crop = inverse.TransformBounds(visibleRectScreen);
    59     //clip to buffer size
    60     crop.IntersectRect(crop, aBufferRect);
    61     crop.Round();
    63     if (crop.IsEmpty()) {
    64         LOGD("Skip layer");
    65         return false;
    66     }
    68     //propagate buffer clipping back to visible rect
    69     visibleRectScreen = aTransform.TransformBounds(crop);
    70     visibleRectScreen.Round();
    72     // Map from layer space to buffer space
    73     crop -= aBufferRect.TopLeft();
    74     if (aYFlipped) {
    75         crop.y = aBufferRect.height - (crop.y + crop.height);
    76     }
    78     aSourceCrop->left = crop.x;
    79     aSourceCrop->top  = crop.y;
    80     aSourceCrop->right  = crop.x + crop.width;
    81     aSourceCrop->bottom = crop.y + crop.height;
    83     aVisibleRegionScreen->left = visibleRectScreen.x;
    84     aVisibleRegionScreen->top  = visibleRectScreen.y;
    85     aVisibleRegionScreen->right  = visibleRectScreen.x + visibleRectScreen.width;
    86     aVisibleRegionScreen->bottom = visibleRectScreen.y + visibleRectScreen.height;
    88     return true;
    89 }
    91 /* static */ bool
    92 HwcUtils::PrepareVisibleRegion(const nsIntRegion& aVisible,
    93                                const gfxMatrix& aTransform,
    94                                nsIntRect aClip, nsIntRect aBufferRect,
    95                                RectVector* aVisibleRegionScreen) {
    97     nsIntRegionRectIterator rect(aVisible);
    98     bool isVisible = false;
    99     while (const nsIntRect* visibleRect = rect.Next()) {
   100         hwc_rect_t visibleRectScreen;
   101         gfxRect screenRect;
   103         screenRect.IntersectRect(gfxRect(*visibleRect), aBufferRect);
   104         screenRect = aTransform.TransformBounds(screenRect);
   105         screenRect.IntersectRect(screenRect, aClip);
   106         screenRect.Round();
   107         if (screenRect.IsEmpty()) {
   108             continue;
   109         }
   110         visibleRectScreen.left = screenRect.x;
   111         visibleRectScreen.top  = screenRect.y;
   112         visibleRectScreen.right  = screenRect.XMost();
   113         visibleRectScreen.bottom = screenRect.YMost();
   114         aVisibleRegionScreen->push_back(visibleRectScreen);
   115         isVisible = true;
   116     }
   118     return isVisible;
   119 }
   121 /* static */ bool
   122 HwcUtils::CalculateClipRect(const gfxMatrix& aTransform,
   123                             const nsIntRect* aLayerClip,
   124                             nsIntRect aParentClip, nsIntRect* aRenderClip) {
   126     *aRenderClip = aParentClip;
   128     if (!aLayerClip) {
   129         return true;
   130     }
   132     if (aLayerClip->IsEmpty()) {
   133         return false;
   134     }
   136     nsIntRect clip = *aLayerClip;
   138     gfxRect r(clip);
   139     gfxRect trClip = aTransform.TransformBounds(r);
   140     trClip.Round();
   141     gfxUtils::GfxRectToIntRect(trClip, &clip);
   143     aRenderClip->IntersectRect(*aRenderClip, clip);
   144     return true;
   145 }
   147 } // namespace mozilla

mercurial