Surface.h revision 9bad0d7e726e6b264c528a3dd13d0c58fd92c0e1
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
202b5dd4062dd951b2cafc4b80bd3a1813b013d71aMathias Agopian#include <gui/BufferQueueDefs.h>
219bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter#include <gui/HdrMetadata.h>
229bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter#include <gui/IGraphicBufferProducer.h>
23e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
24e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#include <ui/ANativeObjectBase.h>
25e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#include <ui/Region.h>
26edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
272b5dd4062dd951b2cafc4b80bd3a1813b013d71aMathias Agopian#include <utils/Condition.h>
282b5dd4062dd951b2cafc4b80bd3a1813b013d71aMathias Agopian#include <utils/Mutex.h>
29edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <utils/RefBase.h>
30edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
316a3c05bcfab588fd99dd8d619a53d15374e99507Mathias Agopian#include <system/window.h>
329cce325fae8adcf7560a28eef394489f09bad74dMathias Agopian
33edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectnamespace android {
34edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
353da8d2748580b2575e368e203ce2c7f8d34dea05Brian Andersonclass ISurfaceComposer;
363da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson
370273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden/*
38e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * An implementation of ANativeWindow that feeds graphics buffers into a
39e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * BufferQueue.
400273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden *
41e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * This is typically used by programs that want to render frames through
42e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * some means (maybe OpenGL, a software renderer, or a hardware decoder)
43e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * and have the frames they create forwarded to SurfaceFlinger for
44e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * compositing.  For example, a video decoder could render a frame and call
45e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * eglSwapBuffers(), which invokes ANativeWindow callbacks defined by
46e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * Surface.  Surface then forwards the buffers through Binder IPC
47e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * to the BufferQueue's producer interface, providing the new frame to a
48e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * consumer such as GLConsumer.
490273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden */
50e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianclass Surface
51e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    : public ANativeObjectBase<ANativeWindow, Surface, RefBase>
52076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{
53edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectpublic:
54edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
55cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian    /*
56cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * creates a Surface from the given IGraphicBufferProducer (which concrete
57cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * implementation is a BufferQueue).
58cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     *
59cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * Surface is mainly state-less while it's disconnected, it can be
60cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * viewed as a glorified IGraphicBufferProducer holder. It's therefore
61cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * safe to create other Surfaces from the same IGraphicBufferProducer.
62cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     *
63cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * However, once a Surface is connected, it'll prevent other Surfaces
64cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * referring to the same IGraphicBufferProducer to become connected and
65cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * therefore prevent them to be used as actual producers of buffers.
66595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian     *
67595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian     * the controlledByApp flag indicates that this Surface (producer) is
68595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian     * controlled by the application. This flag is used at connect time.
69cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     */
703da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson    explicit Surface(const sp<IGraphicBufferProducer>& bufferProducer,
713da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson            bool controlledByApp = false);
72bd050ab2af1421d527d1a80ce59dd8d9940a838cTed Bonkenburg
73cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian    /* getIGraphicBufferProducer() returns the IGraphicBufferProducer this
74cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * Surface was created with. Usually it's an error to use the
75cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * IGraphicBufferProducer while the Surface is connected.
76cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     */
77e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    sp<IGraphicBufferProducer> getIGraphicBufferProducer() const;
78bd050ab2af1421d527d1a80ce59dd8d9940a838cTed Bonkenburg
79cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian    /* convenience function to check that the given surface is non NULL as
80cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian     * well as its IGraphicBufferProducer */
81c4905eb49d20667381f3cda7c6f6894234404bd3Mathias Agopian    static bool isValid(const sp<Surface>& surface) {
82f25c5086cf46eb029d887f34f25a09220e44958cMathias Agopian        return surface != NULL && surface->getIGraphicBufferProducer() != NULL;
83f25c5086cf46eb029d887f34f25a09220e44958cMathias Agopian    }
84f25c5086cf46eb029d887f34f25a09220e44958cMathias Agopian
85399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    /* Attaches a sideband buffer stream to the Surface's IGraphicBufferProducer.
86399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     *
87399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     * A sideband stream is a device-specific mechanism for passing buffers
88399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     * from the producer to the consumer without using dequeueBuffer/
89399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     * queueBuffer. If a sideband stream is present, the consumer can choose
90399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     * whether to acquire buffers from the sideband stream or from the queued
91399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     * buffers.
92399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     *
93399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     * Passing NULL or a different stream handle will detach the previous
94399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     * handle if any.
95399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall     */
96399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    void setSidebandStream(const sp<NativeHandle>& stream);
97399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall
9829a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza    /* Allocates buffers based on the current dimensions/format.
9929a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza     *
10029a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza     * This function will allocate up to the maximum number of buffers
10129a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza     * permitted by the current BufferQueue configuration. It will use the
10229a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza     * default format and dimensions. This is most useful to avoid an allocation
10329a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza     * delay during dequeueBuffer. If there are already the maximum number of
10429a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza     * buffers allocated, this function has no effect.
10529a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza     */
10629a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza    void allocateBuffers();
10729a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza
108812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    /* Sets the generation number on the IGraphicBufferProducer and updates the
109812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza     * generation number on any buffers attached to the Surface after this call.
110812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza     * See IGBP::setGenerationNumber for more information. */
111812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    status_t setGenerationNumber(uint32_t generationNumber);
112812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza
113c6f30bdee1f634eb90d68cb76efe935b6535a1e8Dan Stoza    // See IGraphicBufferProducer::getConsumerName
114c6f30bdee1f634eb90d68cb76efe935b6535a1e8Dan Stoza    String8 getConsumerName() const;
115c6f30bdee1f634eb90d68cb76efe935b6535a1e8Dan Stoza
1167dde599bf1a0dbef7390d91c2689d506371cdbd7Dan Stoza    // See IGraphicBufferProducer::getNextFrameNumber
1177dde599bf1a0dbef7390d91c2689d506371cdbd7Dan Stoza    uint64_t getNextFrameNumber() const;
1187dde599bf1a0dbef7390d91c2689d506371cdbd7Dan Stoza
119c2e7788721489c5a2ef681fd0bfa591d2ce41175Robert Carr    /* Set the scaling mode to be used with a Surface.
120c2e7788721489c5a2ef681fd0bfa591d2ce41175Robert Carr     * See NATIVE_WINDOW_SET_SCALING_MODE and its parameters
121c2e7788721489c5a2ef681fd0bfa591d2ce41175Robert Carr     * in <system/window.h>. */
122c2e7788721489c5a2ef681fd0bfa591d2ce41175Robert Carr    int setScalingMode(int mode);
123c2e7788721489c5a2ef681fd0bfa591d2ce41175Robert Carr
124127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // See IGraphicBufferProducer::setDequeueTimeout
125127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    status_t setDequeueTimeout(nsecs_t timeout);
126127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza
1279f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr    /*
1289f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr     * Wait for frame number to increase past lastFrame for at most
1299f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr     * timeoutNs. Useful for one thread to wait for another unknown
1309f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr     * thread to queue a buffer.
1319f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr     */
1329f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr    bool waitForNextFrame(uint64_t lastFrame, nsecs_t timeout);
1339f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr
13450101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza    // See IGraphicBufferProducer::getLastQueuedBuffer
1351a61da5e28fa16ad556a58193c8bbeb32a5f636dJohn Reck    // See GLConsumer::getTransformMatrix for outTransformMatrix format
13650101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza    status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
1371a61da5e28fa16ad556a58193c8bbeb32a5f636dJohn Reck            sp<Fence>* outFence, float outTransformMatrix[16]);
13850101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza
1390a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson    status_t getDisplayRefreshCycleDuration(nsecs_t* outRefreshDuration);
1400a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson
1417c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson    /* Enables or disables frame timestamp tracking. It is disabled by default
1427c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson     * to avoid overhead during queue and dequeue for applications that don't
1437c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson     * need the feature. If disabled, calls to getFrameTimestamps will fail.
1447c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson     */
1457c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson    void enableFrameTimestamps(bool enable);
1467c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson
1470a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson    status_t getCompositorTiming(
1480a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson            nsecs_t* compositeDeadline, nsecs_t* compositeInterval,
1490a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson            nsecs_t* compositeToPresentLatency);
1500a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson
151ce796e78a57018f186b062199c75d94545318acaPablo Ceballos    // See IGraphicBufferProducer::getFrameTimestamps
152069b365163470d2736eb6f591c354d208b5da23bBrian Anderson    status_t getFrameTimestamps(uint64_t frameNumber,
153dbd0ea80021cbc61c578385f534f41a33338085bBrian Anderson            nsecs_t* outRequestedPresentTime, nsecs_t* outAcquireTime,
154f7fd56a649f07133ad78d31eb5d3ae7a4e95d522Brian Anderson            nsecs_t* outLatchTime, nsecs_t* outFirstRefreshStartTime,
155f7fd56a649f07133ad78d31eb5d3ae7a4e95d522Brian Anderson            nsecs_t* outLastRefreshStartTime, nsecs_t* outGlCompositionDoneTime,
1564e606e3901b500bdd0f3ea21b8cb63734087bf0aBrian Anderson            nsecs_t* outDisplayPresentTime, nsecs_t* outDequeueReadyTime,
1574e606e3901b500bdd0f3ea21b8cb63734087bf0aBrian Anderson            nsecs_t* outReleaseTime);
15862c48c931f88ec44c41621afe988c34cab1fb41dIan Elliott
1591eb1b2703754beda3c20bedfca2b4fae885b7164Courtney Goeltzenleuchter    status_t getWideColorSupport(bool* supported);
160c5b97c5b5610b2fe6186f599798c97250bb01b95Courtney Goeltzenleuchter    status_t getHdrSupport(bool* supported);
1611eb1b2703754beda3c20bedfca2b4fae885b7164Courtney Goeltzenleuchter
1628e3e92b906db431c4fa822f21242977d4ee99942Pablo Ceballos    status_t getUniqueId(uint64_t* outId) const;
163e2786ea5aec3a12d948feb85ffbb535fc89c0fe6Chia-I Wu    status_t getConsumerUsage(uint64_t* outUsage) const;
1648e3e92b906db431c4fa822f21242977d4ee99942Pablo Ceballos
165932f008485dbb6fb452c8616abd7586f914f72ceDan Stoza    // Returns the CLOCK_MONOTONIC start time of the last dequeueBuffer call
166932f008485dbb6fb452c8616abd7586f914f72ceDan Stoza    nsecs_t getLastDequeueStartTime() const;
167932f008485dbb6fb452c8616abd7586f914f72ceDan Stoza
168e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianprotected:
169e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual ~Surface();
170edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1713da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson    // Virtual for testing.
1723da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson    virtual sp<ISurfaceComposer> composerService() const;
1730a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson    virtual nsecs_t now() const;
1743da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson
175b296533607232357597b255679db29470ab5925dMathias Agopianprivate:
176b296533607232357597b255679db29470ab5925dMathias Agopian    // can't be copied
177e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    Surface& operator = (const Surface& rhs);
178b296533607232357597b255679db29470ab5925dMathias Agopian    Surface(const Surface& rhs);
179e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
180e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // ANativeWindow hooks
181e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_cancelBuffer(ANativeWindow* window,
182e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer* buffer, int fenceFd);
183e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_dequeueBuffer(ANativeWindow* window,
184e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer** buffer, int* fenceFd);
185e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_perform(ANativeWindow* window, int operation, ...);
186e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_query(const ANativeWindow* window, int what, int* value);
187e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_queueBuffer(ANativeWindow* window,
188e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer* buffer, int fenceFd);
189e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_setSwapInterval(ANativeWindow* window, int interval);
190e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
191e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_cancelBuffer_DEPRECATED(ANativeWindow* window,
192e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer* buffer);
193e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_dequeueBuffer_DEPRECATED(ANativeWindow* window,
194e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer** buffer);
195e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_lockBuffer_DEPRECATED(ANativeWindow* window,
196e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer* buffer);
197e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_queueBuffer_DEPRECATED(ANativeWindow* window,
198e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer* buffer);
199e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
200e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchConnect(va_list args);
201e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchDisconnect(va_list args);
202e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBufferCount(va_list args);
203e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersGeometry(va_list args);
204e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersDimensions(va_list args);
205e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersUserDimensions(va_list args);
206e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersFormat(va_list args);
207e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetScalingMode(va_list args);
208e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersTransform(va_list args);
2091681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    int dispatchSetBuffersStickyTransform(va_list args);
210e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersTimestamp(va_list args);
211e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetCrop(va_list args);
212e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetUsage(va_list args);
213cb496acbe593326e8d5d563847067d02b2df40ecMathias Agopian    int dispatchSetUsage64(va_list args);
214e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchLock(va_list args);
215e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchUnlockAndPost(va_list args);
2167cb0d39016ff8061fe9fc2967870c145a6ffa2acRachad    int dispatchSetSidebandStream(va_list args);
21782c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    int dispatchSetBuffersDataSpace(va_list args);
2189bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter    int dispatchSetBuffersSmpte2086Metadata(va_list args);
2199bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter    int dispatchSetBuffersCta8613Metadata(va_list args);
2205065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza    int dispatchSetSurfaceDamage(va_list args);
2213559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    int dispatchSetSharedBufferMode(va_list args);
222ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    int dispatchSetAutoRefresh(va_list args);
2230a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson    int dispatchGetDisplayRefreshCycleDuration(va_list args);
2241049d1d0b21ee318e309f9a90098c092cb879c41Brian Anderson    int dispatchGetNextFrameId(va_list args);
2257c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson    int dispatchEnableFrameTimestamps(va_list args);
2260a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson    int dispatchGetCompositorTiming(va_list args);
227ce796e78a57018f186b062199c75d94545318acaPablo Ceballos    int dispatchGetFrameTimestamps(va_list args);
2281eb1b2703754beda3c20bedfca2b4fae885b7164Courtney Goeltzenleuchter    int dispatchGetWideColorSupport(va_list args);
229c5b97c5b5610b2fe6186f599798c97250bb01b95Courtney Goeltzenleuchter    int dispatchGetHdrSupport(va_list args);
230e2786ea5aec3a12d948feb85ffbb535fc89c0fe6Chia-I Wu    int dispatchGetConsumerUsage64(va_list args);
231e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
232e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianprotected:
233e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd);
234e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd);
235e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd);
236e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int perform(int operation, va_list args);
237e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int setSwapInterval(int interval);
238e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
239e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int lockBuffer_DEPRECATED(ANativeWindowBuffer* buffer);
240e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
241e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int connect(int api);
242e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int setBufferCount(int bufferCount);
2433be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    virtual int setBuffersUserDimensions(uint32_t width, uint32_t height);
2443be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    virtual int setBuffersFormat(PixelFormat format);
2453be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    virtual int setBuffersTransform(uint32_t transform);
2463be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    virtual int setBuffersStickyTransform(uint32_t transform);
247e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int setBuffersTimestamp(int64_t timestamp);
24882c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    virtual int setBuffersDataSpace(android_dataspace dataSpace);
2499bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter    virtual int setBuffersSmpte2086Metadata(const android_smpte2086_metadata* metadata);
2509bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter    virtual int setBuffersCta8613Metadata(const android_cta861_3_metadata* metadata);
251e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int setCrop(Rect const* rect);
252cb496acbe593326e8d5d563847067d02b2df40ecMathias Agopian    virtual int setUsage(uint64_t reqUsage);
2535065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza    virtual void setSurfaceDamage(android_native_rect_t* rects, size_t numRects);
254076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
255e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianpublic:
25697b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr    virtual int disconnect(int api,
25797b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr            IGraphicBufferProducer::DisconnectMode mode =
25897b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr                    IGraphicBufferProducer::DisconnectMode::Api);
25997b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr
26019e3e06e3c65a7c001a6fe0971744ba5ff536515Pablo Ceballos    virtual int setMaxDequeuedBufferCount(int maxDequeuedBuffers);
26119e3e06e3c65a7c001a6fe0971744ba5ff536515Pablo Ceballos    virtual int setAsyncMode(bool async);
2623559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    virtual int setSharedBufferMode(bool sharedBufferMode);
263ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    virtual int setAutoRefresh(bool autoRefresh);
264c1ba5c4649554e744844b07cfe402b42fbe12ff3Sahil Dhanju    virtual int setBuffersDimensions(uint32_t width, uint32_t height);
265e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds);
266e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int unlockAndPost();
26770ccba596c586b7effde1ff99d36c911873b4ed4Dan Stoza    virtual int query(int what, int* value) const;
268b296533607232357597b255679db29470ab5925dMathias Agopian
269231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza    virtual int connect(int api, const sp<IProducerListener>& listener);
270e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh
271e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // When reportBufferRemoval is true, clients must call getAndFlushRemovedBuffers to fetch
272e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // GraphicBuffers removed from this surface after a dequeueBuffer, detachNextBuffer or
273e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // attachBuffer call. This allows clients with their own buffer caches to free up buffers no
274e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // longer in use by this surface.
275e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    virtual int connect(
276e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh            int api, const sp<IProducerListener>& listener,
277e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh            bool reportBufferRemoval);
278d9c4971da2f2c4f980a748006bd40469c3332a13Dan Stoza    virtual int detachNextBuffer(sp<GraphicBuffer>* outBuffer,
279231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza            sp<Fence>* outFence);
280231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza    virtual int attachBuffer(ANativeWindowBuffer*);
281231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza
282e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // When client connects to Surface with reportBufferRemoval set to true, any buffers removed
283e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // from this Surface will be collected and returned here. Once this method returns, these
284e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // buffers will no longer be referenced by this Surface unless they are attached to this
285e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // Surface later. The list of removed buffers will only be stored until the next dequeueBuffer,
286e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // detachNextBuffer, or attachBuffer call.
287e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    status_t getAndFlushRemovedBuffers(std::vector<sp<GraphicBuffer>>* out);
288e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh
289152279d2725cd59369bcdf70f9622b011cae5a14Courtney Goeltzenleuchter    android_dataspace_t getBuffersDataSpace();
290152279d2725cd59369bcdf70f9622b011cae5a14Courtney Goeltzenleuchter
29140482ff650751819d4104c10a30974838168438cChavi Weingarten    static status_t attachAndQueueBuffer(Surface* surface, sp<GraphicBuffer> buffer);
29240482ff650751819d4104c10a30974838168438cChavi Weingarten
293e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianprotected:
2942b5dd4062dd951b2cafc4b80bd3a1813b013d71aMathias Agopian    enum { NUM_BUFFER_SLOTS = BufferQueueDefs::NUM_BUFFER_SLOTS };
295e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
296aca4e2287939b4ce3d9e9aced64c5c9641333503Jamie Gennis
297069b365163470d2736eb6f591c354d208b5da23bBrian Anderson    void querySupportedTimestampsLocked() const;
298069b365163470d2736eb6f591c354d208b5da23bBrian Anderson
299e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    void freeAllBuffers();
300e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int getSlotFromBufferLocked(android_native_buffer_t* buffer) const;
3018f9dbf9e13b927de2524116c30544f7dfbbbf56cMathias Agopian
302e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    struct BufferSlot {
303e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian        sp<GraphicBuffer> buffer;
304e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian        Region dirtyRegion;
305e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    };
306ba5972ffdc7179dd9a387f22032eb18666d97917Mathias Agopian
307e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mSurfaceTexture is the interface to the surface texture server. All
308e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // operations on the surface texture client ultimately translate into
309e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // interactions with the server using this interface.
310e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // TODO: rename to mBufferProducer
311e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    sp<IGraphicBufferProducer> mGraphicBufferProducer;
312e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
313e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mSlots stores the buffers that have been allocated for each buffer slot.
314e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // It is initialized to null pointers, and gets filled in with the result of
315e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // IGraphicBufferProducer::requestBuffer when the client dequeues a buffer from a
316e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // slot that has not yet been used. The buffer allocated to a slot will also
317e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // be replaced if the requested buffer usage or geometry differs from that
318e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // of the buffer allocated to a slot.
319e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    BufferSlot mSlots[NUM_BUFFER_SLOTS];
320e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
321e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mReqWidth is the buffer width that will be requested at the next dequeue
322e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // operation. It is initialized to 1.
323e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    uint32_t mReqWidth;
324e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
325e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mReqHeight is the buffer height that will be requested at the next
326e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // dequeue operation. It is initialized to 1.
327e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    uint32_t mReqHeight;
328e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
329e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mReqFormat is the buffer pixel format that will be requested at the next
330e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888.
3313be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    PixelFormat mReqFormat;
332e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
333e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mReqUsage is the set of buffer usage flags that will be requested
334e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // at the next deuque operation. It is initialized to 0.
335cb496acbe593326e8d5d563847067d02b2df40ecMathias Agopian    uint64_t mReqUsage;
336e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
337e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mTimestamp is the timestamp that will be used for the next buffer queue
338e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that
339e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // a timestamp is auto-generated when queueBuffer is called.
340e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int64_t mTimestamp;
341e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
34282c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    // mDataSpace is the buffer dataSpace that will be used for the next buffer
34382c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    // queue operation. It defaults to HAL_DATASPACE_UNKNOWN, which
34482c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    // means that the buffer contains some type of color data.
34582c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    android_dataspace mDataSpace;
34682c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala
3479bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter    // mHdrMetadata is the HDR metadata that will be used for the next buffer
3489bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter    // queue operation.  There is no HDR metadata by default.
3499bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter    HdrMetadata mHdrMetadata;
3509bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter
351e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mCrop is the crop rectangle that will be used for the next buffer
352e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // that gets queued. It is set by calling setCrop.
353e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    Rect mCrop;
354e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
355e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mScalingMode is the scaling mode that will be used for the next
356e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // buffers that get queued. It is set by calling setScalingMode.
357e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int mScalingMode;
358e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
359e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mTransform is the transform identifier that will be used for the next
360e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // buffer that gets queued. It is set by calling setTransform.
361e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    uint32_t mTransform;
362e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
3631681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    // mStickyTransform is a transform that is applied on top of mTransform
3641681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    // in each buffer that is queued.  This is typically used to force the
3651681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    // compositor to apply a transform, and will prevent the transform hint
3661681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    // from being set by the compositor.
3671681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    uint32_t mStickyTransform;
3681681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk
3693be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // mDefaultWidth is default width of the buffers, regardless of the
3703be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // native_window_set_buffers_dimensions call.
3713be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    uint32_t mDefaultWidth;
372e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
3733be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // mDefaultHeight is default height of the buffers, regardless of the
3743be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // native_window_set_buffers_dimensions call.
3753be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    uint32_t mDefaultHeight;
376e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
3773be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // mUserWidth, if non-zero, is an application-specified override
3783be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // of mDefaultWidth.  This is lower priority than the width set by
3793be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // native_window_set_buffers_dimensions.
3803be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    uint32_t mUserWidth;
381e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
3823be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // mUserHeight, if non-zero, is an application-specified override
3833be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // of mDefaultHeight.  This is lower priority than the height set
3843be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // by native_window_set_buffers_dimensions.
3853be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    uint32_t mUserHeight;
386e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
387e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mTransformHint is the transform probably applied to buffers of this
388e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // window. this is only a hint, actual transform may differ.
389e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    uint32_t mTransformHint;
390e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
391595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian    // mProducerControlledByApp whether this buffer producer is controlled
392595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian    // by the application
393595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian    bool mProducerControlledByApp;
394595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian
3957cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian    // mSwapIntervalZero set if we should drop buffers at queue() time to
3967cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian    // achieve an asynchronous swap interval
3977cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian    bool mSwapIntervalZero;
3987cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian
399e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mConsumerRunningBehind whether the consumer is running more than
400e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // one buffer behind the producer.
401e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    mutable bool mConsumerRunningBehind;
402e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
403e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mMutex is the mutex used to prevent concurrent access to the member
404e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // variables of Surface objects. It must be locked whenever the
405e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // member variables are accessed.
406e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    mutable Mutex mMutex;
407e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
408e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // must be used from the lock/unlock thread
409e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    sp<GraphicBuffer>           mLockedBuffer;
410e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    sp<GraphicBuffer>           mPostedBuffer;
411e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    bool                        mConnectedToCpu;
412e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
413c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza    // When a CPU producer is attached, this reflects the region that the
414c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza    // producer wished to update as well as whether the Surface was able to copy
415c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza    // the previous buffer back to allow a partial update.
4165065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza    //
417c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza    // When a non-CPU producer is attached, this reflects the surface damage
418c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza    // (the change since the previous frame) passed in by the producer.
419e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    Region mDirtyRegion;
420812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza
421a2eb34cfbe089deb9a519e9702e17d9dfe26f9e8Ian Elliott    // mBufferAge tracks the age of the contents of the most recently dequeued
422a2eb34cfbe089deb9a519e9702e17d9dfe26f9e8Ian Elliott    // buffer as the number of frames that have elapsed since it was last queued
423a2eb34cfbe089deb9a519e9702e17d9dfe26f9e8Ian Elliott    uint64_t mBufferAge;
424a2eb34cfbe089deb9a519e9702e17d9dfe26f9e8Ian Elliott
425812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    // Stores the current generation number. See setGenerationNumber and
426812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    // IGraphicBufferProducer::setGenerationNumber for more information.
427812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    uint32_t mGenerationNumber;
428ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos
429ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // Caches the values that have been passed to the producer.
4303559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    bool mSharedBufferMode;
431ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    bool mAutoRefresh;
432ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos
4333559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    // If in shared buffer mode and auto refresh is enabled, store the shared
434ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // buffer slot and return it for all calls to queue/dequeue without going
435ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // over Binder.
436ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    int mSharedBufferSlot;
437ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos
438ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // This is true if the shared buffer has already been queued/canceled. It's
439ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // used to prevent a mismatch between the number of queue/dequeue calls.
440ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    bool mSharedBufferHasBeenQueued;
4419f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr
44270ccba596c586b7effde1ff99d36c911873b4ed4Dan Stoza    // These are used to satisfy the NATIVE_WINDOW_LAST_*_DURATION queries
44370ccba596c586b7effde1ff99d36c911873b4ed4Dan Stoza    nsecs_t mLastDequeueDuration = 0;
44470ccba596c586b7effde1ff99d36c911873b4ed4Dan Stoza    nsecs_t mLastQueueDuration = 0;
44570ccba596c586b7effde1ff99d36c911873b4ed4Dan Stoza
446932f008485dbb6fb452c8616abd7586f914f72ceDan Stoza    // Stores the time right before we call IGBP::dequeueBuffer
447932f008485dbb6fb452c8616abd7586f914f72ceDan Stoza    nsecs_t mLastDequeueStartTime = 0;
448932f008485dbb6fb452c8616abd7586f914f72ceDan Stoza
4499f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr    Condition mQueueBufferCondition;
450bc8c1928e1dbdaf6a2820f6e426c96ed61284043Pablo Ceballos
45150143b3780ad2aaa544c8d2d47619214b79c3c56Brian Anderson    uint64_t mNextFrameNumber = 1;
45250143b3780ad2aaa544c8d2d47619214b79c3c56Brian Anderson    uint64_t mLastFrameNumber = 0;
453069b365163470d2736eb6f591c354d208b5da23bBrian Anderson
4546b376713907086c9642e7b7e66e51ddfa531b003Brian Anderson    // Mutable because ANativeWindow::query needs this class const.
4556b376713907086c9642e7b7e66e51ddfa531b003Brian Anderson    mutable bool mQueriedSupportedTimestamps;
4566b376713907086c9642e7b7e66e51ddfa531b003Brian Anderson    mutable bool mFrameTimestampsSupportsPresent;
4576b376713907086c9642e7b7e66e51ddfa531b003Brian Anderson
4583890c3995c4a52439844faeb80b5503d42b977d8Brian Anderson    // A cached copy of the FrameEventHistory maintained by the consumer.
4597c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson    bool mEnableFrameTimestamps = false;
4603da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson    std::unique_ptr<ProducerFrameEventHistory> mFrameEventHistory;
461e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh
462e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    bool mReportRemovedBuffers = false;
463e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    std::vector<sp<GraphicBuffer>> mRemovedBuffers;
464edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
465edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
46605debe1d787b7471c2bc9c8f7569a338ca5c7ad4Mathias Agopian} // namespace android
467edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
468e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#endif  // ANDROID_GUI_SURFACE_H
469