1edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project/*
2edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * Copyright (C) 2007 The Android Open Source Project
3edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project *
4edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
5edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * you may not use this file except in compliance with the License.
6edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * You may obtain a copy of the License at
7edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project *
8edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
9edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project *
10edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
11edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
12edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * See the License for the specific language governing permissions and
14edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * limitations under the License.
15edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project */
16edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
17edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <stdlib.h>
18edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <stdint.h>
19edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <sys/types.h>
20edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
21edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <utils/Errors.h>
22edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <utils/Log.h>
23310f8da0c3122ed5419db8f12a6e98d3188325b2Mathias Agopian#include <binder/IPCThreadState.h>
24310f8da0c3122ed5419db8f12a6e98d3188325b2Mathias Agopian#include <binder/IServiceManager.h>
25edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
26edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <GLES/gl.h>
27edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <GLES/glext.h>
28edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
29edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <hardware/hardware.h>
30edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
31edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "clz.h"
32db403e8ff0d7727015e1a5009bab20eb7ec205bcMathias Agopian#include "Client.h"
33edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "LayerBase.h"
34921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian#include "Layer.h"
35edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "SurfaceFlinger.h"
360f2f5ff75b7b48ceb64270655ee6b62d09bf4d00Mathias Agopian#include "DisplayDevice.h"
37edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
38edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectnamespace android {
39edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
40edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ---------------------------------------------------------------------------
41edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
42f6679fc6f70939643901f29a9a69e40c603e6e5fMathias Agopianint32_t LayerBase::sSequence = 1;
43f6679fc6f70939643901f29a9a69e40c603e6e5fMathias Agopian
443ee454a7bef8bd3d1c9cdd9d17108eb80ebadf2aMathias AgopianLayerBase::LayerBase(SurfaceFlinger* flinger)
453ee454a7bef8bd3d1c9cdd9d17108eb80ebadf2aMathias Agopian    : contentDirty(false),
46f6679fc6f70939643901f29a9a69e40c603e6e5fMathias Agopian      sequence(uint32_t(android_atomic_inc(&sSequence))),
47a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian      mFlinger(flinger), mFiltering(false),
48a2f4e56fec0fb36c4a370eb23d6e9dc57f250b59Mathias Agopian      mNeedsFiltering(false),
49edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      mTransactionFlags(0),
5099ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian      mPremultipliedAlpha(true), mName("unnamed"), mDebug(false)
51edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
52edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
53edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
54edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source ProjectLayerBase::~LayerBase()
55edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
56edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
57edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
58d12965934712ed0b9c1a264a6934dc0dad839ffdMathias Agopianvoid LayerBase::setName(const String8& name) {
59d12965934712ed0b9c1a264a6934dc0dad839ffdMathias Agopian    mName = name;
60d12965934712ed0b9c1a264a6934dc0dad839ffdMathias Agopian}
61d12965934712ed0b9c1a264a6934dc0dad839ffdMathias Agopian
62d12965934712ed0b9c1a264a6934dc0dad839ffdMathias AgopianString8 LayerBase::getName() const {
63d12965934712ed0b9c1a264a6934dc0dad839ffdMathias Agopian    return mName;
64d12965934712ed0b9c1a264a6934dc0dad839ffdMathias Agopian}
65d12965934712ed0b9c1a264a6934dc0dad839ffdMathias Agopian
66edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid LayerBase::initStates(uint32_t w, uint32_t h, uint32_t flags)
67edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
68edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    uint32_t layerFlags = 0;
693165cc21cfea781988407b19bd83292b19f05f55Mathias Agopian    if (flags & ISurfaceComposerClient::eHidden)
703165cc21cfea781988407b19bd83292b19f05f55Mathias Agopian        layerFlags = layer_state_t::eLayerHidden;
71edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
723165cc21cfea781988407b19bd83292b19f05f55Mathias Agopian    if (flags & ISurfaceComposerClient::eNonPremultiplied)
73edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        mPremultipliedAlpha = false;
74edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
7593ffb86b909005bbee4993fc9053f017466311c7Mathias Agopian    mCurrentState.active.w = w;
7693ffb86b909005bbee4993fc9053f017466311c7Mathias Agopian    mCurrentState.active.h = h;
7793ffb86b909005bbee4993fc9053f017466311c7Mathias Agopian    mCurrentState.active.crop.makeInvalid();
7893ffb86b909005bbee4993fc9053f017466311c7Mathias Agopian    mCurrentState.z = 0;
7993ffb86b909005bbee4993fc9053f017466311c7Mathias Agopian    mCurrentState.alpha = 0xFF;
808785578391eacd4192333d7b0ce3afedd7d163e6Mathias Agopian    mCurrentState.layerStack = 0;
8193ffb86b909005bbee4993fc9053f017466311c7Mathias Agopian    mCurrentState.flags = layerFlags;
8293ffb86b909005bbee4993fc9053f017466311c7Mathias Agopian    mCurrentState.sequence = 0;
83edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    mCurrentState.transform.set(0, 0);
8493ffb86b909005bbee4993fc9053f017466311c7Mathias Agopian    mCurrentState.requested = mCurrentState.active;
85edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
86edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // drawing state & current state are identical
87edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    mDrawingState = mCurrentState;
88edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
89edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
90eba8c688f633f3f3f1b75c2bc64faf799dd2b5f2Mathias Agopianbool LayerBase::needsFiltering(const sp<const DisplayDevice>& hw) const {
91eba8c688f633f3f3f1b75c2bc64faf799dd2b5f2Mathias Agopian    return mNeedsFiltering || hw->needsFiltering();
92eba8c688f633f3f3f1b75c2bc64faf799dd2b5f2Mathias Agopian}
93eba8c688f633f3f3f1b75c2bc64faf799dd2b5f2Mathias Agopian
94ba6be54876a19444f0b214b4b3b0749df227b013Mathias Agopianvoid LayerBase::commitTransaction() {
95edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    mDrawingState = mCurrentState;
96edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
97edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid LayerBase::forceVisibilityTransaction() {
98edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // this can be called without SurfaceFlinger.mStateLock, but if we
99edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // can atomically increment the sequence number, it doesn't matter.
100edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    android_atomic_inc(&mCurrentState.sequence);
101edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    requestTransaction();
102edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
103edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectbool LayerBase::requestTransaction() {
104edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    int32_t old = setTransactionFlags(eTransactionNeeded);
105edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return ((old & eTransactionNeeded) == 0);
106edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
107edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectuint32_t LayerBase::getTransactionFlags(uint32_t flags) {
108edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return android_atomic_and(~flags, &mTransactionFlags) & flags;
109edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
110edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectuint32_t LayerBase::setTransactionFlags(uint32_t flags) {
111edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return android_atomic_or(flags, &mTransactionFlags);
112edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
113edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
11441b6aabf356d8a505da37b1d046bc9010028fe8bMathias Agopianbool LayerBase::setPosition(float x, float y) {
115edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (mCurrentState.transform.tx() == x && mCurrentState.transform.ty() == y)
116edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return false;
117edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    mCurrentState.sequence++;
118edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    mCurrentState.transform.set(x, y);
119edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    requestTransaction();
120edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return true;
121edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
122edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectbool LayerBase::setLayer(uint32_t z) {
123edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (mCurrentState.z == z)
124edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return false;
125edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    mCurrentState.sequence++;
126edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    mCurrentState.z = z;
127edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    requestTransaction();
128edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return true;
129edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
130edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectbool LayerBase::setSize(uint32_t w, uint32_t h) {
13193ffb86b909005bbee4993fc9053f017466311c7Mathias Agopian    if (mCurrentState.requested.w == w && mCurrentState.requested.h == h)
132edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return false;
13393ffb86b909005bbee4993fc9053f017466311c7Mathias Agopian    mCurrentState.requested.w = w;
13493ffb86b909005bbee4993fc9053f017466311c7Mathias Agopian    mCurrentState.requested.h = h;
135edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    requestTransaction();
136edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return true;
137edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
138edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectbool LayerBase::setAlpha(uint8_t alpha) {
139edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (mCurrentState.alpha == alpha)
140edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return false;
141edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    mCurrentState.sequence++;
142edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    mCurrentState.alpha = alpha;
143edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    requestTransaction();
144edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return true;
145edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
146edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectbool LayerBase::setMatrix(const layer_state_t::matrix22_t& matrix) {
147edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    mCurrentState.sequence++;
148edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    mCurrentState.transform.set(
149edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy);
150edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    requestTransaction();
151edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return true;
152edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
153edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectbool LayerBase::setTransparentRegionHint(const Region& transparent) {
154edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    mCurrentState.sequence++;
155edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    mCurrentState.transparentRegion = transparent;
156edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    requestTransaction();
157edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return true;
158edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
159edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectbool LayerBase::setFlags(uint8_t flags, uint8_t mask) {
160edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
161edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (mCurrentState.flags == newFlags)
162edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return false;
163edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    mCurrentState.sequence++;
164edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    mCurrentState.flags = newFlags;
165edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    requestTransaction();
166edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return true;
167edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
168f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennisbool LayerBase::setCrop(const Rect& crop) {
169b30c415539813b96a831b75d07f3d12aef1aeab7Mathias Agopian    if (mCurrentState.requested.crop == crop)
170f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis        return false;
171f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis    mCurrentState.sequence++;
172b30c415539813b96a831b75d07f3d12aef1aeab7Mathias Agopian    mCurrentState.requested.crop = crop;
173f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis    requestTransaction();
174f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis    return true;
175f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis}
176edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1778785578391eacd4192333d7b0ce3afedd7d163e6Mathias Agopianbool LayerBase::setLayerStack(uint32_t layerStack) {
1788785578391eacd4192333d7b0ce3afedd7d163e6Mathias Agopian    if (mCurrentState.layerStack == layerStack)
1798785578391eacd4192333d7b0ce3afedd7d163e6Mathias Agopian        return false;
1808785578391eacd4192333d7b0ce3afedd7d163e6Mathias Agopian    mCurrentState.sequence++;
1818785578391eacd4192333d7b0ce3afedd7d163e6Mathias Agopian    mCurrentState.layerStack = layerStack;
1828785578391eacd4192333d7b0ce3afedd7d163e6Mathias Agopian    requestTransaction();
1838785578391eacd4192333d7b0ce3afedd7d163e6Mathias Agopian    return true;
1848785578391eacd4192333d7b0ce3afedd7d163e6Mathias Agopian}
1858785578391eacd4192333d7b0ce3afedd7d163e6Mathias Agopian
186edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid LayerBase::setVisibleRegion(const Region& visibleRegion) {
187edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // always called from main thread
1884fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    this->visibleRegion = visibleRegion;
189edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
190edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
191edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid LayerBase::setCoveredRegion(const Region& coveredRegion) {
192edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // always called from main thread
1934fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    this->coveredRegion = coveredRegion;
194edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
195edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
196a8026d21f3f2f09e3416cbd33c277fbd15d8cf4eJesse Hallvoid LayerBase::setVisibleNonTransparentRegion(const Region&
197a8026d21f3f2f09e3416cbd33c277fbd15d8cf4eJesse Hall        setVisibleNonTransparentRegion) {
198a8026d21f3f2f09e3416cbd33c277fbd15d8cf4eJesse Hall    // always called from main thread
199a8026d21f3f2f09e3416cbd33c277fbd15d8cf4eJesse Hall    this->visibleNonTransparentRegion = setVisibleNonTransparentRegion;
200a8026d21f3f2f09e3416cbd33c277fbd15d8cf4eJesse Hall}
201a8026d21f3f2f09e3416cbd33c277fbd15d8cf4eJesse Hall
202edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectuint32_t LayerBase::doTransaction(uint32_t flags)
203edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
204edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const Layer::State& front(drawingState());
205edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const Layer::State& temp(currentState());
206edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
20705cec9d1275fd939c2d1aec235dca2bdb8edef63Mathias Agopian    // always set active to requested, unless we're asked not to
20805cec9d1275fd939c2d1aec235dca2bdb8edef63Mathias Agopian    // this is used by Layer, which special cases resizes.
20905cec9d1275fd939c2d1aec235dca2bdb8edef63Mathias Agopian    if (flags & eDontUpdateGeometryState)  {
21005cec9d1275fd939c2d1aec235dca2bdb8edef63Mathias Agopian    } else {
2117e4a587f6038bcf9b58ca615fce9e52fd47e30c3Mathias Agopian        Layer::State& editTemp(currentState());
212b30c415539813b96a831b75d07f3d12aef1aeab7Mathias Agopian        editTemp.active = temp.requested;
2137e4a587f6038bcf9b58ca615fce9e52fd47e30c3Mathias Agopian    }
21405cec9d1275fd939c2d1aec235dca2bdb8edef63Mathias Agopian
215b30c415539813b96a831b75d07f3d12aef1aeab7Mathias Agopian    if (front.active != temp.active) {
2166656dbc81273424d9b4bf78c42a4e179dbe1cb71Mathias Agopian        // invalidate and recompute the visible regions if needed
2176656dbc81273424d9b4bf78c42a4e179dbe1cb71Mathias Agopian        flags |= Layer::eVisibleRegion;
2186656dbc81273424d9b4bf78c42a4e179dbe1cb71Mathias Agopian    }
2197e4a587f6038bcf9b58ca615fce9e52fd47e30c3Mathias Agopian
220edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (temp.sequence != front.sequence) {
221edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        // invalidate and recompute the visible regions if needed
222edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        flags |= eVisibleRegion;
223edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        this->contentDirty = true;
224a2fe0a234bd6823f868742a3c137acb8875e1b03Mathias Agopian
225733189d408e13b54fd70971b265244367efd0f51Mathias Agopian        // we may use linear filtering, if the matrix scales us
226733189d408e13b54fd70971b265244367efd0f51Mathias Agopian        const uint8_t type = temp.transform.getType();
227733189d408e13b54fd70971b265244367efd0f51Mathias Agopian        mNeedsFiltering = (!temp.transform.preserveRects() ||
228733189d408e13b54fd70971b265244367efd0f51Mathias Agopian                (type >= Transform::SCALE));
229a2fe0a234bd6823f868742a3c137acb8875e1b03Mathias Agopian    }
230a2fe0a234bd6823f868742a3c137acb8875e1b03Mathias Agopian
231edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // Commit the transaction
232ba6be54876a19444f0b214b4b3b0749df227b013Mathias Agopian    commitTransaction();
233edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return flags;
234edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
235edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
2364297734c1156fd8ede7e9c61b1e439f9e1c18cd9Mathias Agopianvoid LayerBase::computeGeometry(const sp<const DisplayDevice>& hw, LayerMesh* mesh) const
237edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
238edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const Layer::State& s(drawingState());
2394297734c1156fd8ede7e9c61b1e439f9e1c18cd9Mathias Agopian    const Transform tr(hw->getTransform() * s.transform);
2404297734c1156fd8ede7e9c61b1e439f9e1c18cd9Mathias Agopian    const uint32_t hw_h = hw->getHeight();
24193ffb86b909005bbee4993fc9053f017466311c7Mathias Agopian    Rect win(s.active.w, s.active.h);
242a046dd9772cd8da4ead9edc7a89d9992ff0d38cfMathias Agopian    if (!s.active.crop.isEmpty()) {
243a046dd9772cd8da4ead9edc7a89d9992ff0d38cfMathias Agopian        win.intersect(s.active.crop, &win);
244f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis    }
2454fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    if (mesh) {
2464fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian        tr.transform(mesh->mVertices[0], win.left,  win.top);
2474fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian        tr.transform(mesh->mVertices[1], win.left,  win.bottom);
2484fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian        tr.transform(mesh->mVertices[2], win.right, win.bottom);
2494fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian        tr.transform(mesh->mVertices[3], win.right, win.top);
2504fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian        for (size_t i=0 ; i<4 ; i++) {
2514fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian            mesh->mVertices[i][1] = hw_h - mesh->mVertices[i][1];
252edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
253edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
254edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
255edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
2564fec873a98f7b4380720cd1ad006f74c8cdc73daMathias AgopianRect LayerBase::computeBounds() const {
2574fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    const Layer::State& s(drawingState());
2584fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    Rect win(s.active.w, s.active.h);
259a046dd9772cd8da4ead9edc7a89d9992ff0d38cfMathias Agopian    if (!s.active.crop.isEmpty()) {
260a046dd9772cd8da4ead9edc7a89d9992ff0d38cfMathias Agopian        win.intersect(s.active.crop, &win);
2614fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    }
2624fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    return s.transform.transform(win);
263edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
264edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
2654fec873a98f7b4380720cd1ad006f74c8cdc73daMathias AgopianRegion LayerBase::latchBuffer(bool& recomputeVisibleRegions) {
2664fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    Region result;
2674fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    return result;
268edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
269edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
2704fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopianvoid LayerBase::setGeometry(
2714297734c1156fd8ede7e9c61b1e439f9e1c18cd9Mathias Agopian    const sp<const DisplayDevice>& hw,
2724fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian        HWComposer::HWCLayerInterface& layer)
273a537c0f42e8077baafcbc65844adf1ec8397c040Mathias Agopian{
2743e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    layer.setDefaultState();
275a537c0f42e8077baafcbc65844adf1ec8397c040Mathias Agopian
276a537c0f42e8077baafcbc65844adf1ec8397c040Mathias Agopian    // this gives us only the "orientation" component of the transform
277a537c0f42e8077baafcbc65844adf1ec8397c040Mathias Agopian    const State& s(drawingState());
278a537c0f42e8077baafcbc65844adf1ec8397c040Mathias Agopian    const uint32_t finalTransform = s.transform.getOrientation();
279a537c0f42e8077baafcbc65844adf1ec8397c040Mathias Agopian    // we can only handle simple transformation
280a537c0f42e8077baafcbc65844adf1ec8397c040Mathias Agopian    if (finalTransform & Transform::ROT_INVALID) {
2813e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        layer.setTransform(0);
282a537c0f42e8077baafcbc65844adf1ec8397c040Mathias Agopian    } else {
2833e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        layer.setTransform(finalTransform);
284a537c0f42e8077baafcbc65844adf1ec8397c040Mathias Agopian    }
285a537c0f42e8077baafcbc65844adf1ec8397c040Mathias Agopian
286a537c0f42e8077baafcbc65844adf1ec8397c040Mathias Agopian    if (!isOpaque()) {
2873e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        layer.setBlending(mPremultipliedAlpha ?
2883e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian                HWC_BLENDING_PREMULT :
2893e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian                HWC_BLENDING_COVERAGE);
290a537c0f42e8077baafcbc65844adf1ec8397c040Mathias Agopian    }
291a537c0f42e8077baafcbc65844adf1ec8397c040Mathias Agopian
2924297734c1156fd8ede7e9c61b1e439f9e1c18cd9Mathias Agopian    const Transform& tr = hw->getTransform();
2934fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    Rect transformedBounds(computeBounds());
2944fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    transformedBounds = tr.transform(transformedBounds);
2954fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian
2964fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    // scaling is already applied in transformedBounds
2974fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    layer.setFrame(transformedBounds);
2984fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    layer.setCrop(transformedBounds.getBounds());
2993e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian}
3003e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
3014297734c1156fd8ede7e9c61b1e439f9e1c18cd9Mathias Agopianvoid LayerBase::setPerFrameData(const sp<const DisplayDevice>& hw,
302d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian        HWComposer::HWCLayerInterface& layer) {
303c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian    // we have to set the visible region on every frame because
304c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian    // we currently free it during onLayerDisplayed(), which is called
305c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian    // after HWComposer::commit() -- every frame.
306c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian    const Transform& tr = hw->getTransform();
307c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian    layer.setVisibleRegionScreen(tr.transform(visibleRegion));
308c7f3381c3b2945e441747130eae88214435d0819Mathias Agopian}
309c7f3381c3b2945e441747130eae88214435d0819Mathias Agopian
3104297734c1156fd8ede7e9c61b1e439f9e1c18cd9Mathias Agopianvoid LayerBase::setAcquireFence(const sp<const DisplayDevice>& hw,
311d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian        HWComposer::HWCLayerInterface& layer) {
312c5c5a14c06de249d8e0445fd24699e1d9aa04549Jesse Hall    layer.setAcquireFenceFd(-1);
313c5c5a14c06de249d8e0445fd24699e1d9aa04549Jesse Hall}
314c5c5a14c06de249d8e0445fd24699e1d9aa04549Jesse Hall
315c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopianvoid LayerBase::onLayerDisplayed(const sp<const DisplayDevice>& hw,
316c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian        HWComposer::HWCLayerInterface* layer) {
317c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian    if (layer) {
318c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian        layer->onDisplayed();
319c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian    }
320c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian}
321c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian
322a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopianvoid LayerBase::setFiltering(bool filtering)
323a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian{
324a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian    mFiltering = filtering;
325a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian}
326a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian
327a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopianbool LayerBase::getFiltering() const
328a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian{
329a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian    return mFiltering;
330a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian}
331a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian
332da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopianbool LayerBase::isVisible() const {
333da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian    const Layer::State& s(mDrawingState);
334da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian    return !(s.flags & layer_state_t::eLayerHidden) && s.alpha;
335da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian}
336da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian
3374297734c1156fd8ede7e9c61b1e439f9e1c18cd9Mathias Agopianvoid LayerBase::draw(const sp<const DisplayDevice>& hw, const Region& clip) const
338edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
3391b03149f3533db04e72e088d3fdd09d0087ca594Mathias Agopian    onDraw(hw, clip);
340edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
341edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
3424297734c1156fd8ede7e9c61b1e439f9e1c18cd9Mathias Agopianvoid LayerBase::draw(const sp<const DisplayDevice>& hw)
34374c40c0a273dbfd7d10617c4cc1b0c066bfc812eMathias Agopian{
3444297734c1156fd8ede7e9c61b1e439f9e1c18cd9Mathias Agopian    onDraw( hw, Region(hw->bounds()) );
34574c40c0a273dbfd7d10617c4cc1b0c066bfc812eMathias Agopian}
34674c40c0a273dbfd7d10617c4cc1b0c066bfc812eMathias Agopian
3474297734c1156fd8ede7e9c61b1e439f9e1c18cd9Mathias Agopianvoid LayerBase::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip,
3481b03149f3533db04e72e088d3fdd09d0087ca594Mathias Agopian        GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) const
349edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
3504297734c1156fd8ede7e9c61b1e439f9e1c18cd9Mathias Agopian    const uint32_t fbHeight = hw->getHeight();
351010fccb0637f8a69a35ee1a7feb228d213f6d542Mathias Agopian    glColor4f(red,green,blue,alpha);
3520a91775c4df380d6a5b7f3ccad5127388ac01306Mathias Agopian
353c492e67810814bf86301abffe1d31598b775cf45Mathias Agopian    glDisable(GL_TEXTURE_EXTERNAL_OES);
354a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian    glDisable(GL_TEXTURE_2D);
355edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    glDisable(GL_BLEND);
35620f68782a4ea71c6a977d7f87d8288d3daa265ecMathias Agopian
3574fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    LayerMesh mesh;
3584fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    computeGeometry(hw, &mesh);
3594fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian
3604fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
3614fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
362edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
363edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
3644297734c1156fd8ede7e9c61b1e439f9e1c18cd9Mathias Agopianvoid LayerBase::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const
36529aa74c546751ed04d17dc248a967eebaef63b21Rebecca Schultz Zavin{
3661b03149f3533db04e72e088d3fdd09d0087ca594Mathias Agopian    clearWithOpenGL(hw, clip, 0,0,0,0);
36729aa74c546751ed04d17dc248a967eebaef63b21Rebecca Schultz Zavin}
36829aa74c546751ed04d17dc248a967eebaef63b21Rebecca Schultz Zavin
3694297734c1156fd8ede7e9c61b1e439f9e1c18cd9Mathias Agopianvoid LayerBase::drawWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const
370edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
3714297734c1156fd8ede7e9c61b1e439f9e1c18cd9Mathias Agopian    const uint32_t fbHeight = hw->getHeight();
372edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const State& s(drawingState());
373edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
37449753266d2219d2fbf5c33dc4626f299dffcdd76Mathias Agopian    GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
37599ed22412db547c59d3da08114d9d5a586442b30Glenn Kasten    if (CC_UNLIKELY(s.alpha < 0xFF)) {
37649753266d2219d2fbf5c33dc4626f299dffcdd76Mathias Agopian        const GLfloat alpha = s.alpha * (1.0f/255.0f);
37749753266d2219d2fbf5c33dc4626f299dffcdd76Mathias Agopian        if (mPremultipliedAlpha) {
37849753266d2219d2fbf5c33dc4626f299dffcdd76Mathias Agopian            glColor4f(alpha, alpha, alpha, alpha);
379edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        } else {
38049753266d2219d2fbf5c33dc4626f299dffcdd76Mathias Agopian            glColor4f(1, 1, 1, alpha);
381edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
382edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        glEnable(GL_BLEND);
383edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
38449753266d2219d2fbf5c33dc4626f299dffcdd76Mathias Agopian        glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
385edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } else {
38678fd5010a87425d2be401d10a306dd68638fc1ddMathias Agopian        glColor4f(1, 1, 1, 1);
38749753266d2219d2fbf5c33dc4626f299dffcdd76Mathias Agopian        glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
388a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian        if (!isOpaque()) {
389edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            glEnable(GL_BLEND);
390edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
391edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        } else {
392edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            glDisable(GL_BLEND);
393edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
394edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
395edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
3964fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    LayerMesh mesh;
3974fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    computeGeometry(hw, &mesh);
3984fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian
3994fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    // TODO: we probably want to generate the texture coords with the mesh
4004fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    // here we assume that we only have 4 vertices
4014fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian
402b661d66013b9803c50dc78ca0247ac39caef443aMathias Agopian    struct TexCoords {
403b661d66013b9803c50dc78ca0247ac39caef443aMathias Agopian        GLfloat u;
404b661d66013b9803c50dc78ca0247ac39caef443aMathias Agopian        GLfloat v;
40578fd5010a87425d2be401d10a306dd68638fc1ddMathias Agopian    };
40678fd5010a87425d2be401d10a306dd68638fc1ddMathias Agopian
407a046dd9772cd8da4ead9edc7a89d9992ff0d38cfMathias Agopian    Rect win(s.active.w, s.active.h);
40893ffb86b909005bbee4993fc9053f017466311c7Mathias Agopian    if (!s.active.crop.isEmpty()) {
409a046dd9772cd8da4ead9edc7a89d9992ff0d38cfMathias Agopian        win.intersect(s.active.crop, &win);
410f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis    }
411a046dd9772cd8da4ead9edc7a89d9992ff0d38cfMathias Agopian
412a046dd9772cd8da4ead9edc7a89d9992ff0d38cfMathias Agopian    GLfloat left   = GLfloat(win.left)   / GLfloat(s.active.w);
413a046dd9772cd8da4ead9edc7a89d9992ff0d38cfMathias Agopian    GLfloat top    = GLfloat(win.top)    / GLfloat(s.active.h);
414a046dd9772cd8da4ead9edc7a89d9992ff0d38cfMathias Agopian    GLfloat right  = GLfloat(win.right)  / GLfloat(s.active.w);
415a046dd9772cd8da4ead9edc7a89d9992ff0d38cfMathias Agopian    GLfloat bottom = GLfloat(win.bottom) / GLfloat(s.active.h);
416f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis
417b661d66013b9803c50dc78ca0247ac39caef443aMathias Agopian    TexCoords texCoords[4];
418f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis    texCoords[0].u = left;
419f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis    texCoords[0].v = top;
420f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis    texCoords[1].u = left;
421f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis    texCoords[1].v = bottom;
422f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis    texCoords[2].u = right;
423f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis    texCoords[2].v = bottom;
424f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis    texCoords[3].u = right;
425f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis    texCoords[3].v = top;
426f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis    for (int i = 0; i < 4; i++) {
427f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis        texCoords[i].v = 1.0f - texCoords[i].v;
428f15a83f5814219c167f87cb8aaea622fc8493499Jamie Gennis    }
429edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
43078fd5010a87425d2be401d10a306dd68638fc1ddMathias Agopian    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
43178fd5010a87425d2be401d10a306dd68638fc1ddMathias Agopian    glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
4324fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
4334fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
434edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
43578fd5010a87425d2be401d10a306dd68638fc1ddMathias Agopian    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
436c492e67810814bf86301abffe1d31598b775cf45Mathias Agopian    glDisable(GL_BLEND);
437edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
438edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
4391b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopianvoid LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
4401b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian{
4411b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian    const Layer::State& s(drawingState());
442c95dbdc236acf002b5f8aed8c8a9e43047fc75b5Mathias Agopian
443c95dbdc236acf002b5f8aed8c8a9e43047fc75b5Mathias Agopian    snprintf(buffer, SIZE,
444c95dbdc236acf002b5f8aed8c8a9e43047fc75b5Mathias Agopian            "+ %s %p (%s)\n",
445c95dbdc236acf002b5f8aed8c8a9e43047fc75b5Mathias Agopian            getTypeId(), this, getName().string());
446c95dbdc236acf002b5f8aed8c8a9e43047fc75b5Mathias Agopian    result.append(buffer);
447c95dbdc236acf002b5f8aed8c8a9e43047fc75b5Mathias Agopian
44882d7ab6c7e0cf971e515134ccf072682dd1a2cdbMathias Agopian    s.transparentRegion.dump(result, "transparentRegion");
4494fec873a98f7b4380720cd1ad006f74c8cdc73daMathias Agopian    visibleRegion.dump(result, "visibleRegion");
450c95dbdc236acf002b5f8aed8c8a9e43047fc75b5Mathias Agopian
4511b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian    snprintf(buffer, SIZE,
4521b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian            "      "
4535f20e2d4462da3471f59152b32cd8640fa4a21daMathias Agopian            "layerStack=%4d, z=%9d, pos=(%g,%g), size=(%4d,%4d), crop=(%4d,%4d,%4d,%4d), "
454a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian            "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
4551b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian            "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
456791da60dd322f596b29320edb97c5366070c9ddcMathias Agopian            s.layerStack, s.z, s.transform.tx(), s.transform.ty(), s.active.w, s.active.h,
45793ffb86b909005bbee4993fc9053f017466311c7Mathias Agopian            s.active.crop.left, s.active.crop.top,
45893ffb86b909005bbee4993fc9053f017466311c7Mathias Agopian            s.active.crop.right, s.active.crop.bottom,
459a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian            isOpaque(), needsDithering(), contentDirty,
4601b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian            s.alpha, s.flags,
4611b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian            s.transform[0][0], s.transform[0][1],
4621b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian            s.transform[1][0], s.transform[1][1]);
4631b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian    result.append(buffer);
4641b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian}
46554ba51dff21de666c5ae3bf3abd4f0634ebb0676Mathias Agopian
46625e66fc324bbc004fa8902b2d4699e41bb601104Mathias Agopianvoid LayerBase::shortDump(String8& result, char* scratch, size_t size) const {
46748b888aab9fdcfba250722dffbdffe61f11c64f3Mathias Agopian    LayerBase::dump(result, scratch, size);
46848b888aab9fdcfba250722dffbdffe61f11c64f3Mathias Agopian}
46948b888aab9fdcfba250722dffbdffe61f11c64f3Mathias Agopian
47025e66fc324bbc004fa8902b2d4699e41bb601104Mathias Agopianvoid LayerBase::dumpStats(String8& result, char* scratch, size_t SIZE) const {
47125e66fc324bbc004fa8902b2d4699e41bb601104Mathias Agopian}
47225e66fc324bbc004fa8902b2d4699e41bb601104Mathias Agopian
47325e66fc324bbc004fa8902b2d4699e41bb601104Mathias Agopianvoid LayerBase::clearStats() {
47482d7ab6c7e0cf971e515134ccf072682dd1a2cdbMathias Agopian}
47548b888aab9fdcfba250722dffbdffe61f11c64f3Mathias Agopian
476921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopiansp<LayerBaseClient> LayerBase::getLayerBaseClient() const {
477921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    return 0;
478921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian}
479921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
480921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopiansp<Layer> LayerBase::getLayer() const {
481921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    return 0;
482921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian}
483921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
484edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ---------------------------------------------------------------------------
485edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
486631f358d348ea5e7813ca01f86fc9f2a6536add6Mathias Agopianint32_t LayerBaseClient::sIdentity = 1;
4872e123245811a1f31c080a29728fcc1655045f011Mathias Agopian
4883ee454a7bef8bd3d1c9cdd9d17108eb80ebadf2aMathias AgopianLayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger,
48996f0819f81293076e652792794a961543e6750d7Mathias Agopian        const sp<Client>& client)
4903ee454a7bef8bd3d1c9cdd9d17108eb80ebadf2aMathias Agopian    : LayerBase(flinger),
491a1f47b90ab53af978be45b8bda16c5d084ae66e6Mathias Agopian      mHasSurface(false),
492a1f47b90ab53af978be45b8bda16c5d084ae66e6Mathias Agopian      mClientRef(client),
493948d69fca450a5a85e3e3e17d5776bfb26e48b85Mathias Agopian      mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
494edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
495076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian}
496edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
497edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source ProjectLayerBaseClient::~LayerBaseClient()
498edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
499b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian    sp<Client> c(mClientRef.promote());
50096f0819f81293076e652792794a961543e6750d7Mathias Agopian    if (c != 0) {
501b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian        c->detachLayer(this);
502edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
503edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
504edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
505a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopiansp<ISurface> LayerBaseClient::createSurface()
506a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian{
507a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian    class BSurface : public BnSurface, public LayerCleaner {
508a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian        virtual sp<ISurfaceTexture> getSurfaceTexture() const { return 0; }
509a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian    public:
510a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian        BSurface(const sp<SurfaceFlinger>& flinger,
511a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian                const sp<LayerBaseClient>& layer)
512a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian            : LayerCleaner(flinger, layer) { }
513a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian    };
514a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian    sp<ISurface> sur(new BSurface(mFlinger, this));
515a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian    return sur;
516a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian}
517a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian
518a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopiansp<ISurface> LayerBaseClient::getSurface()
519076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{
520a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian    sp<ISurface> s;
521076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    Mutex::Autolock _l(mLock);
522a1f47b90ab53af978be45b8bda16c5d084ae66e6Mathias Agopian
523a1f47b90ab53af978be45b8bda16c5d084ae66e6Mathias Agopian    LOG_ALWAYS_FATAL_IF(mHasSurface,
524a1f47b90ab53af978be45b8bda16c5d084ae66e6Mathias Agopian            "LayerBaseClient::getSurface() has already been called");
525a1f47b90ab53af978be45b8bda16c5d084ae66e6Mathias Agopian
526a1f47b90ab53af978be45b8bda16c5d084ae66e6Mathias Agopian    mHasSurface = true;
527a1f47b90ab53af978be45b8bda16c5d084ae66e6Mathias Agopian    s = createSurface();
528a1f47b90ab53af978be45b8bda16c5d084ae66e6Mathias Agopian    mClientSurfaceBinder = s->asBinder();
529076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    return s;
530076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian}
531076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
5320d1561275e80073807ac04728951782d943f8882Mathias Agopianwp<IBinder> LayerBaseClient::getSurfaceBinder() const {
5330d1561275e80073807ac04728951782d943f8882Mathias Agopian    return mClientSurfaceBinder;
5340d1561275e80073807ac04728951782d943f8882Mathias Agopian}
5350d1561275e80073807ac04728951782d943f8882Mathias Agopian
536582270d69db94286a248bd829f1ae6f910d45124Jamie Genniswp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
537582270d69db94286a248bd829f1ae6f910d45124Jamie Gennis    return 0;
538582270d69db94286a248bd829f1ae6f910d45124Jamie Gennis}
539582270d69db94286a248bd829f1ae6f910d45124Jamie Gennis
5401b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopianvoid LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
5411b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian{
5421b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian    LayerBase::dump(result, buffer, SIZE);
5431b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian
544b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian    sp<Client> client(mClientRef.promote());
5451b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian    snprintf(buffer, SIZE,
54696f0819f81293076e652792794a961543e6750d7Mathias Agopian            "      client=%p, identity=%u\n",
54796f0819f81293076e652792794a961543e6750d7Mathias Agopian            client.get(), getIdentity());
5481b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian
5491b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian    result.append(buffer);
5501b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian}
5511b5e1021b8c9b87113b70d94dfb7b50f8c5b01b8Mathias Agopian
55248b888aab9fdcfba250722dffbdffe61f11c64f3Mathias Agopian
55348b888aab9fdcfba250722dffbdffe61f11c64f3Mathias Agopianvoid LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const
55448b888aab9fdcfba250722dffbdffe61f11c64f3Mathias Agopian{
55548b888aab9fdcfba250722dffbdffe61f11c64f3Mathias Agopian    LayerBaseClient::dump(result, scratch, size);
55648b888aab9fdcfba250722dffbdffe61f11c64f3Mathias Agopian}
55748b888aab9fdcfba250722dffbdffe61f11c64f3Mathias Agopian
558076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian// ---------------------------------------------------------------------------
559076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
560a67932fe6864ac346e7f78b86df11cf6c5344137Mathias AgopianLayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
561a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian        const sp<LayerBaseClient>& layer)
562a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian    : mFlinger(flinger), mLayer(layer) {
563076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian}
564076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
565a67932fe6864ac346e7f78b86df11cf6c5344137Mathias AgopianLayerBaseClient::LayerCleaner::~LayerCleaner() {
5669a11206fe793363c0e8897b478cbe6ef8c52b543Mathias Agopian    // destroy client resources
567921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    mFlinger->onLayerDestroyed(mLayer);
568b5b7f260da2c1a2a82e0311e2015d49a82f43667Mathias Agopian}
569b5b7f260da2c1a2a82e0311e2015d49a82f43667Mathias Agopian
570edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ---------------------------------------------------------------------------
571edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
572edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}; // namespace android
573