Surface.h revision 3da8d2748580b2575e368e203ce2c7f8d34dea05
1edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project/*
2e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * Copyright (C) 2010 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
1790ac799241f077a7b7e6c1875fd933864c8dd2a7Mathias Agopian#ifndef ANDROID_GUI_SURFACE_H
1890ac799241f077a7b7e6c1875fd933864c8dd2a7Mathias Agopian#define ANDROID_GUI_SURFACE_H
19edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
20e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#include <gui/IGraphicBufferProducer.h>
21e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#include <gui/BufferQueue.h>
22e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
23e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#include <ui/ANativeObjectBase.h>
24e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#include <ui/Region.h>
25edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
2688612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala#include <binder/Parcelable.h>
2788612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala
28edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <utils/RefBase.h>
29edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <utils/threads.h>
30e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#include <utils/KeyedVector.h>
31edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
32e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianstruct ANativeWindow_Buffer;
339cce325fae8adcf7560a28eef394489f09bad74dMathias Agopian
34edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectnamespace android {
35edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
363da8d2748580b2575e368e203ce2c7f8d34dea05Brian Andersonclass ISurfaceComposer;
373da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson
380273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden/*
39e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * An implementation of ANativeWindow that feeds graphics buffers into a
40e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * BufferQueue.
410273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden *
42e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * This is typically used by programs that want to render frames through
43e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * some means (maybe OpenGL, a software renderer, or a hardware decoder)
44e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * and have the frames they create forwarded to SurfaceFlinger for
45e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * compositing.  For example, a video decoder could render a frame and call
46e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * eglSwapBuffers(), which invokes ANativeWindow callbacks defined by
47e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * Surface.  Surface then forwards the buffers through Binder IPC
48e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * to the BufferQueue's producer interface, providing the new frame to a
49e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * consumer such as GLConsumer.
500273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden */
51e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianclass Surface
52e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    : public ANativeObjectBase<ANativeWindow, Surface, RefBase>
53076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{
54edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectpublic:
55edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
56cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian    /*
57cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * creates a Surface from the given IGraphicBufferProducer (which concrete
58cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * implementation is a BufferQueue).
59cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     *
60cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * Surface is mainly state-less while it's disconnected, it can be
61cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * viewed as a glorified IGraphicBufferProducer holder. It's therefore
62cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * safe to create other Surfaces from the same IGraphicBufferProducer.
63cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     *
64cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * However, once a Surface is connected, it'll prevent other Surfaces
65cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * referring to the same IGraphicBufferProducer to become connected and
66cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * therefore prevent them to be used as actual producers of buffers.
67595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian     *
68595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian     * the controlledByApp flag indicates that this Surface (producer) is
69595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian     * controlled by the application. This flag is used at connect time.
70cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     */
713da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson    explicit Surface(const sp<IGraphicBufferProducer>& bufferProducer,
723da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson            bool controlledByApp = false);
73bd050ab2af1421d527d1a80ce59dd8d9940a838cTed Bonkenburg
74cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian    /* getIGraphicBufferProducer() returns the IGraphicBufferProducer this
75cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * Surface was created with. Usually it's an error to use the
76cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * IGraphicBufferProducer while the Surface is connected.
77cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     */
78e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    sp<IGraphicBufferProducer> getIGraphicBufferProducer() const;
79bd050ab2af1421d527d1a80ce59dd8d9940a838cTed Bonkenburg
80cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian    /* convenience function to check that the given surface is non NULL as
81cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * well as its IGraphicBufferProducer */
82c4905eb49d20667381f3cda7c6f6894234404bd3Mathias Agopian    static bool isValid(const sp<Surface>& surface) {
83f25c5086cf46eb029d887f34f25a09220e44958cMathias Agopian        return surface != NULL && surface->getIGraphicBufferProducer() != NULL;
84f25c5086cf46eb029d887f34f25a09220e44958cMathias Agopian    }
85f25c5086cf46eb029d887f34f25a09220e44958cMathias Agopian
86399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    /* Attaches a sideband buffer stream to the Surface's IGraphicBufferProducer.
87399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     *
88399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     * A sideband stream is a device-specific mechanism for passing buffers
89399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     * from the producer to the consumer without using dequeueBuffer/
90399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     * queueBuffer. If a sideband stream is present, the consumer can choose
91399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     * whether to acquire buffers from the sideband stream or from the queued
92399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     * buffers.
93399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     *
94399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     * Passing NULL or a different stream handle will detach the previous
95399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     * handle if any.
96399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     */
97399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    void setSidebandStream(const sp<NativeHandle>& stream);
98399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall
9929a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza    /* Allocates buffers based on the current dimensions/format.
10029a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza     *
10129a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza     * This function will allocate up to the maximum number of buffers
10229a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza     * permitted by the current BufferQueue configuration. It will use the
10329a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza     * default format and dimensions. This is most useful to avoid an allocation
10429a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza     * delay during dequeueBuffer. If there are already the maximum number of
10529a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza     * buffers allocated, this function has no effect.
10629a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza     */
10729a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza    void allocateBuffers();
10829a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza
109812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    /* Sets the generation number on the IGraphicBufferProducer and updates the
110812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza     * generation number on any buffers attached to the Surface after this call.
111812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza     * See IGBP::setGenerationNumber for more information. */
112812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    status_t setGenerationNumber(uint32_t generationNumber);
113812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza
114c6f30bdee1f634eb90d68cb76efe935b6535a1e8Dan Stoza    // See IGraphicBufferProducer::getConsumerName
115c6f30bdee1f634eb90d68cb76efe935b6535a1e8Dan Stoza    String8 getConsumerName() const;
116c6f30bdee1f634eb90d68cb76efe935b6535a1e8Dan Stoza
1177dde599bf1a0dbef7390d91c2689d506371cdbd7Dan Stoza    // See IGraphicBufferProducer::getNextFrameNumber
1187dde599bf1a0dbef7390d91c2689d506371cdbd7Dan Stoza    uint64_t getNextFrameNumber() const;
1197dde599bf1a0dbef7390d91c2689d506371cdbd7Dan Stoza
120c2e7788721489c5a2ef681fd0bfa591d2ce41175Robert Carr    /* Set the scaling mode to be used with a Surface.
121c2e7788721489c5a2ef681fd0bfa591d2ce41175Robert Carr     * See NATIVE_WINDOW_SET_SCALING_MODE and its parameters
122c2e7788721489c5a2ef681fd0bfa591d2ce41175Robert Carr     * in <system/window.h>. */
123c2e7788721489c5a2ef681fd0bfa591d2ce41175Robert Carr    int setScalingMode(int mode);
124c2e7788721489c5a2ef681fd0bfa591d2ce41175Robert Carr
125127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // See IGraphicBufferProducer::setDequeueTimeout
126127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    status_t setDequeueTimeout(nsecs_t timeout);
127127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza
1289f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr    /*
1299f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr     * Wait for frame number to increase past lastFrame for at most
1309f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr     * timeoutNs. Useful for one thread to wait for another unknown
1319f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr     * thread to queue a buffer.
1329f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr     */
1339f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr    bool waitForNextFrame(uint64_t lastFrame, nsecs_t timeout);
1349f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr
13550101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza    // See IGraphicBufferProducer::getLastQueuedBuffer
1361a61da5e28fa16ad556a58193c8bbeb32a5f636dJohn Reck    // See GLConsumer::getTransformMatrix for outTransformMatrix format
13750101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza    status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
1381a61da5e28fa16ad556a58193c8bbeb32a5f636dJohn Reck            sp<Fence>* outFence, float outTransformMatrix[16]);
13950101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza
1407c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson    /* Enables or disables frame timestamp tracking. It is disabled by default
1417c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson     * to avoid overhead during queue and dequeue for applications that don't
1427c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson     * need the feature. If disabled, calls to getFrameTimestamps will fail.
1437c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson     */
1447c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson    void enableFrameTimestamps(bool enable);
1457c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson
146ce796e78a57018f186b062199c75d94545318acaPablo Ceballos    // See IGraphicBufferProducer::getFrameTimestamps
147069b365163470d2736eb6f591c354d208b5da23bBrian Anderson    status_t getFrameTimestamps(uint64_t frameNumber,
148dbd0ea80021cbc61c578385f534f41a33338085bBrian Anderson            nsecs_t* outRequestedPresentTime, nsecs_t* outAcquireTime,
149dbd0ea80021cbc61c578385f534f41a33338085bBrian Anderson            nsecs_t* outRefreshStartTime, nsecs_t* outGlCompositionDoneTime,
150069b365163470d2736eb6f591c354d208b5da23bBrian Anderson            nsecs_t* outDisplayPresentTime, nsecs_t* outDisplayRetireTime,
151069b365163470d2736eb6f591c354d208b5da23bBrian Anderson            nsecs_t* outReleaseTime);
152ce796e78a57018f186b062199c75d94545318acaPablo Ceballos
1538e3e92b906db431c4fa822f21242977d4ee99942Pablo Ceballos    status_t getUniqueId(uint64_t* outId) const;
1548e3e92b906db431c4fa822f21242977d4ee99942Pablo Ceballos
155e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianprotected:
156e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual ~Surface();
157edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1583da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson    // Virtual for testing.
1593da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson    virtual sp<ISurfaceComposer> composerService() const;
1603da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson
161b296533607232357597b255679db29470ab5925dMathias Agopianprivate:
162b296533607232357597b255679db29470ab5925dMathias Agopian    // can't be copied
163e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    Surface& operator = (const Surface& rhs);
164b296533607232357597b255679db29470ab5925dMathias Agopian    Surface(const Surface& rhs);
165e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
166e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // ANativeWindow hooks
167e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_cancelBuffer(ANativeWindow* window,
168e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer* buffer, int fenceFd);
169e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_dequeueBuffer(ANativeWindow* window,
170e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer** buffer, int* fenceFd);
171e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_perform(ANativeWindow* window, int operation, ...);
172e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_query(const ANativeWindow* window, int what, int* value);
173e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_queueBuffer(ANativeWindow* window,
174e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer* buffer, int fenceFd);
175e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_setSwapInterval(ANativeWindow* window, int interval);
176e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
177e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_cancelBuffer_DEPRECATED(ANativeWindow* window,
178e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer* buffer);
179e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_dequeueBuffer_DEPRECATED(ANativeWindow* window,
180e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer** buffer);
181e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_lockBuffer_DEPRECATED(ANativeWindow* window,
182e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer* buffer);
183e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_queueBuffer_DEPRECATED(ANativeWindow* window,
184e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer* buffer);
185e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
186e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchConnect(va_list args);
187e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchDisconnect(va_list args);
188e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBufferCount(va_list args);
189e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersGeometry(va_list args);
190e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersDimensions(va_list args);
191e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersUserDimensions(va_list args);
192e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersFormat(va_list args);
193e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetScalingMode(va_list args);
194e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersTransform(va_list args);
1951681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    int dispatchSetBuffersStickyTransform(va_list args);
196e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersTimestamp(va_list args);
197e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetCrop(va_list args);
198e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetPostTransformCrop(va_list args);
199e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetUsage(va_list args);
200e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchLock(va_list args);
201e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchUnlockAndPost(va_list args);
2027cb0d39016ff8061fe9fc2967870c145a6ffa2acRachad    int dispatchSetSidebandStream(va_list args);
20382c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    int dispatchSetBuffersDataSpace(va_list args);
2045065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza    int dispatchSetSurfaceDamage(va_list args);
2053559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    int dispatchSetSharedBufferMode(va_list args);
206ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    int dispatchSetAutoRefresh(va_list args);
2077c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson    int dispatchEnableFrameTimestamps(va_list args);
208ce796e78a57018f186b062199c75d94545318acaPablo Ceballos    int dispatchGetFrameTimestamps(va_list args);
209e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
210e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianprotected:
211e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd);
212e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd);
213e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd);
214e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int perform(int operation, va_list args);
215e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int setSwapInterval(int interval);
216e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
217e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int lockBuffer_DEPRECATED(ANativeWindowBuffer* buffer);
218e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
219e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int connect(int api);
220e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int setBufferCount(int bufferCount);
2213be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    virtual int setBuffersUserDimensions(uint32_t width, uint32_t height);
2223be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    virtual int setBuffersFormat(PixelFormat format);
2233be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    virtual int setBuffersTransform(uint32_t transform);
2243be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    virtual int setBuffersStickyTransform(uint32_t transform);
225e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int setBuffersTimestamp(int64_t timestamp);
22682c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    virtual int setBuffersDataSpace(android_dataspace dataSpace);
227e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int setCrop(Rect const* rect);
228e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int setUsage(uint32_t reqUsage);
2295065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza    virtual void setSurfaceDamage(android_native_rect_t* rects, size_t numRects);
230076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
231e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianpublic:
23297b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr    virtual int disconnect(int api,
23397b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr            IGraphicBufferProducer::DisconnectMode mode =
23497b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr                    IGraphicBufferProducer::DisconnectMode::Api);
23597b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr
23619e3e06e3c65a7c001a6fe0971744ba5ff536515Pablo Ceballos    virtual int setMaxDequeuedBufferCount(int maxDequeuedBuffers);
23719e3e06e3c65a7c001a6fe0971744ba5ff536515Pablo Ceballos    virtual int setAsyncMode(bool async);
2383559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    virtual int setSharedBufferMode(bool sharedBufferMode);
239ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    virtual int setAutoRefresh(bool autoRefresh);
240c1ba5c4649554e744844b07cfe402b42fbe12ff3Sahil Dhanju    virtual int setBuffersDimensions(uint32_t width, uint32_t height);
241e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds);
242e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int unlockAndPost();
24370ccba596c586b7effde1ff99d36c911873b4ed4Dan Stoza    virtual int query(int what, int* value) const;
244b296533607232357597b255679db29470ab5925dMathias Agopian
245231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza    virtual int connect(int api, const sp<IProducerListener>& listener);
246d9c4971da2f2c4f980a748006bd40469c3332a13Dan Stoza    virtual int detachNextBuffer(sp<GraphicBuffer>* outBuffer,
247231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza            sp<Fence>* outFence);
248231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza    virtual int attachBuffer(ANativeWindowBuffer*);
249231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza
250e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianprotected:
251e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    enum { NUM_BUFFER_SLOTS = BufferQueue::NUM_BUFFER_SLOTS };
252e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
253aca4e2287939b4ce3d9e9aced64c5c9641333503Jamie Gennis
254069b365163470d2736eb6f591c354d208b5da23bBrian Anderson    void querySupportedTimestampsLocked() const;
255069b365163470d2736eb6f591c354d208b5da23bBrian Anderson
256e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    void freeAllBuffers();
257e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int getSlotFromBufferLocked(android_native_buffer_t* buffer) const;
2588f9dbf9e13b927de2524116c30544f7dfbbbf56cMathias Agopian
259e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    struct BufferSlot {
260e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian        sp<GraphicBuffer> buffer;
261e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian        Region dirtyRegion;
262e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    };
263ba5972ffdc7179dd9a387f22032eb18666d97917Mathias Agopian
264e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mSurfaceTexture is the interface to the surface texture server. All
265e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // operations on the surface texture client ultimately translate into
266e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // interactions with the server using this interface.
267e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // TODO: rename to mBufferProducer
268e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    sp<IGraphicBufferProducer> mGraphicBufferProducer;
269e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
270e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mSlots stores the buffers that have been allocated for each buffer slot.
271e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // It is initialized to null pointers, and gets filled in with the result of
272e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // IGraphicBufferProducer::requestBuffer when the client dequeues a buffer from a
273e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // slot that has not yet been used. The buffer allocated to a slot will also
274e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // be replaced if the requested buffer usage or geometry differs from that
275e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // of the buffer allocated to a slot.
276e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    BufferSlot mSlots[NUM_BUFFER_SLOTS];
277e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
278e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mReqWidth is the buffer width that will be requested at the next dequeue
279e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // operation. It is initialized to 1.
280e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    uint32_t mReqWidth;
281e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
282e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mReqHeight is the buffer height that will be requested at the next
283e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // dequeue operation. It is initialized to 1.
284e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    uint32_t mReqHeight;
285e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
286e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mReqFormat is the buffer pixel format that will be requested at the next
287e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888.
2883be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    PixelFormat mReqFormat;
289e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
290e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mReqUsage is the set of buffer usage flags that will be requested
291e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // at the next deuque operation. It is initialized to 0.
292e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    uint32_t mReqUsage;
293e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
294e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mTimestamp is the timestamp that will be used for the next buffer queue
295e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that
296e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // a timestamp is auto-generated when queueBuffer is called.
297e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int64_t mTimestamp;
298e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
29982c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    // mDataSpace is the buffer dataSpace that will be used for the next buffer
30082c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    // queue operation. It defaults to HAL_DATASPACE_UNKNOWN, which
30182c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    // means that the buffer contains some type of color data.
30282c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    android_dataspace mDataSpace;
30382c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala
304e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mCrop is the crop rectangle that will be used for the next buffer
305e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // that gets queued. It is set by calling setCrop.
306e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    Rect mCrop;
307e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
308e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mScalingMode is the scaling mode that will be used for the next
309e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // buffers that get queued. It is set by calling setScalingMode.
310e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int mScalingMode;
311e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
312e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mTransform is the transform identifier that will be used for the next
313e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // buffer that gets queued. It is set by calling setTransform.
314e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    uint32_t mTransform;
315e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
3161681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    // mStickyTransform is a transform that is applied on top of mTransform
3171681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    // in each buffer that is queued.  This is typically used to force the
3181681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    // compositor to apply a transform, and will prevent the transform hint
3191681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    // from being set by the compositor.
3201681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    uint32_t mStickyTransform;
3211681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk
3223be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // mDefaultWidth is default width of the buffers, regardless of the
3233be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // native_window_set_buffers_dimensions call.
3243be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    uint32_t mDefaultWidth;
325e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
3263be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // mDefaultHeight is default height of the buffers, regardless of the
3273be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // native_window_set_buffers_dimensions call.
3283be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    uint32_t mDefaultHeight;
329e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
3303be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // mUserWidth, if non-zero, is an application-specified override
3313be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // of mDefaultWidth.  This is lower priority than the width set by
3323be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // native_window_set_buffers_dimensions.
3333be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    uint32_t mUserWidth;
334e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
3353be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // mUserHeight, if non-zero, is an application-specified override
3363be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // of mDefaultHeight.  This is lower priority than the height set
3373be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // by native_window_set_buffers_dimensions.
3383be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    uint32_t mUserHeight;
339e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
340e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mTransformHint is the transform probably applied to buffers of this
341e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // window. this is only a hint, actual transform may differ.
342e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    uint32_t mTransformHint;
343e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
344595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian    // mProducerControlledByApp whether this buffer producer is controlled
345595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian    // by the application
346595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian    bool mProducerControlledByApp;
347595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian
3487cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian    // mSwapIntervalZero set if we should drop buffers at queue() time to
3497cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian    // achieve an asynchronous swap interval
3507cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian    bool mSwapIntervalZero;
3517cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian
352e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mConsumerRunningBehind whether the consumer is running more than
353e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // one buffer behind the producer.
354e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    mutable bool mConsumerRunningBehind;
355e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
356e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mMutex is the mutex used to prevent concurrent access to the member
357e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // variables of Surface objects. It must be locked whenever the
358e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // member variables are accessed.
359e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    mutable Mutex mMutex;
360e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
361e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // must be used from the lock/unlock thread
362e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    sp<GraphicBuffer>           mLockedBuffer;
363e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    sp<GraphicBuffer>           mPostedBuffer;
364e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    bool                        mConnectedToCpu;
365e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
366c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza    // When a CPU producer is attached, this reflects the region that the
367c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza    // producer wished to update as well as whether the Surface was able to copy
368c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza    // the previous buffer back to allow a partial update.
3695065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza    //
370c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza    // When a non-CPU producer is attached, this reflects the surface damage
371c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza    // (the change since the previous frame) passed in by the producer.
372e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    Region mDirtyRegion;
373812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza
374812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    // Stores the current generation number. See setGenerationNumber and
375812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    // IGraphicBufferProducer::setGenerationNumber for more information.
376812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    uint32_t mGenerationNumber;
377ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos
378ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // Caches the values that have been passed to the producer.
3793559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    bool mSharedBufferMode;
380ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    bool mAutoRefresh;
381ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos
3823559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    // If in shared buffer mode and auto refresh is enabled, store the shared
383ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // buffer slot and return it for all calls to queue/dequeue without going
384ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // over Binder.
385ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    int mSharedBufferSlot;
386ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos
387ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // This is true if the shared buffer has already been queued/canceled. It's
388ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // used to prevent a mismatch between the number of queue/dequeue calls.
389ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    bool mSharedBufferHasBeenQueued;
3909f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr
39170ccba596c586b7effde1ff99d36c911873b4ed4Dan Stoza    // These are used to satisfy the NATIVE_WINDOW_LAST_*_DURATION queries
39270ccba596c586b7effde1ff99d36c911873b4ed4Dan Stoza    nsecs_t mLastDequeueDuration = 0;
39370ccba596c586b7effde1ff99d36c911873b4ed4Dan Stoza    nsecs_t mLastQueueDuration = 0;
39470ccba596c586b7effde1ff99d36c911873b4ed4Dan Stoza
3959f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr    Condition mQueueBufferCondition;
396bc8c1928e1dbdaf6a2820f6e426c96ed61284043Pablo Ceballos
39750143b3780ad2aaa544c8d2d47619214b79c3c56Brian Anderson    uint64_t mNextFrameNumber = 1;
39850143b3780ad2aaa544c8d2d47619214b79c3c56Brian Anderson    uint64_t mLastFrameNumber = 0;
399069b365163470d2736eb6f591c354d208b5da23bBrian Anderson
400069b365163470d2736eb6f591c354d208b5da23bBrian Anderson    // Mutable because ANativeWindow::query needs this class const.
401069b365163470d2736eb6f591c354d208b5da23bBrian Anderson    mutable bool mQueriedSupportedTimestamps;
402069b365163470d2736eb6f591c354d208b5da23bBrian Anderson    mutable bool mFrameTimestampsSupportsPresent;
403069b365163470d2736eb6f591c354d208b5da23bBrian Anderson    mutable bool mFrameTimestampsSupportsRetire;
4043890c3995c4a52439844faeb80b5503d42b977d8Brian Anderson
4053890c3995c4a52439844faeb80b5503d42b977d8Brian Anderson    // A cached copy of the FrameEventHistory maintained by the consumer.
4067c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson    bool mEnableFrameTimestamps = false;
4073da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson    std::unique_ptr<ProducerFrameEventHistory> mFrameEventHistory;
408edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
409edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
41088612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvalanamespace view {
41188612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala
41288612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala/**
41388612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala * A simple holder for an IGraphicBufferProducer, to match the managed-side
41488612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala * android.view.Surface parcelable behavior.
41588612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala *
41688612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala * This implements android/view/Surface.aidl
41788612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala *
41888612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala * TODO: Convert IGraphicBufferProducer into AIDL so that it can be directly
41988612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala * used in managed Binder calls.
42088612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala */
42188612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvalaclass Surface : public Parcelable {
42288612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala  public:
42388612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala
42488612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala    String16 name;
42588612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala    sp<IGraphicBufferProducer> graphicBufferProducer;
42688612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala
42788612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala    virtual status_t writeToParcel(Parcel* parcel) const override;
42888612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala    virtual status_t readFromParcel(const Parcel* parcel) override;
42988612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala
43088612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala    // nameAlreadyWritten set to true by Surface.java, because it splits
43188612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala    // Parceling itself between managed and native code, so it only wants a part
43288612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala    // of the full parceling to happen on its native side.
43388612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala    status_t writeToParcel(Parcel* parcel, bool nameAlreadyWritten) const;
43488612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala
43588612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala    // nameAlreadyRead set to true by Surface.java, because it splits
43688612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala    // Parceling itself between managed and native code, so it only wants a part
43788612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala    // of the full parceling to happen on its native side.
43888612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala    status_t readFromParcel(const Parcel* parcel, bool nameAlreadyRead);
43988612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala
44088612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala  private:
44188612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala
44288612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala    static String16 readMaybeEmptyString16(const Parcel* parcel);
44388612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala};
44488612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala
44588612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala} // namespace view
44688612912ac8406f2be0eeff97892274f98509017Eino-Ville Talvala
447edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}; // namespace android
448edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
449e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#endif  // ANDROID_GUI_SURFACE_H
450