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>
2534beb7a0ff0494b0c5ad81104171f8a49e599163Peiyong Lin#include <ui/GraphicTypes.h>
26e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#include <ui/Region.h>
27edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
282b5dd4062dd951b2cafc4b80bd3a1813b013d71aMathias Agopian#include <utils/Condition.h>
292b5dd4062dd951b2cafc4b80bd3a1813b013d71aMathias Agopian#include <utils/Mutex.h>
30edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <utils/RefBase.h>
31edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
326a3c05bcfab588fd99dd8d619a53d15374e99507Mathias Agopian#include <system/window.h>
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
1400a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson    status_t getDisplayRefreshCycleDuration(nsecs_t* outRefreshDuration);
1410a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson
1427c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson    /* Enables or disables frame timestamp tracking. It is disabled by default
1437c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson     * to avoid overhead during queue and dequeue for applications that don't
1447c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson     * need the feature. If disabled, calls to getFrameTimestamps will fail.
1457c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson     */
1467c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson    void enableFrameTimestamps(bool enable);
1477c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson
1480a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson    status_t getCompositorTiming(
1490a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson            nsecs_t* compositeDeadline, nsecs_t* compositeInterval,
1500a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson            nsecs_t* compositeToPresentLatency);
1510a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson
152ce796e78a57018f186b062199c75d94545318acaPablo Ceballos    // See IGraphicBufferProducer::getFrameTimestamps
153069b365163470d2736eb6f591c354d208b5da23bBrian Anderson    status_t getFrameTimestamps(uint64_t frameNumber,
154dbd0ea80021cbc61c578385f534f41a33338085bBrian Anderson            nsecs_t* outRequestedPresentTime, nsecs_t* outAcquireTime,
155f7fd56a649f07133ad78d31eb5d3ae7a4e95d522Brian Anderson            nsecs_t* outLatchTime, nsecs_t* outFirstRefreshStartTime,
156f7fd56a649f07133ad78d31eb5d3ae7a4e95d522Brian Anderson            nsecs_t* outLastRefreshStartTime, nsecs_t* outGlCompositionDoneTime,
1574e606e3901b500bdd0f3ea21b8cb63734087bf0aBrian Anderson            nsecs_t* outDisplayPresentTime, nsecs_t* outDequeueReadyTime,
1584e606e3901b500bdd0f3ea21b8cb63734087bf0aBrian Anderson            nsecs_t* outReleaseTime);
15962c48c931f88ec44c41621afe988c34cab1fb41dIan Elliott
1601eb1b2703754beda3c20bedfca2b4fae885b7164Courtney Goeltzenleuchter    status_t getWideColorSupport(bool* supported);
161c5b97c5b5610b2fe6186f599798c97250bb01b95Courtney Goeltzenleuchter    status_t getHdrSupport(bool* supported);
1621eb1b2703754beda3c20bedfca2b4fae885b7164Courtney Goeltzenleuchter
1638e3e92b906db431c4fa822f21242977d4ee99942Pablo Ceballos    status_t getUniqueId(uint64_t* outId) const;
164e2786ea5aec3a12d948feb85ffbb535fc89c0fe6Chia-I Wu    status_t getConsumerUsage(uint64_t* outUsage) const;
1658e3e92b906db431c4fa822f21242977d4ee99942Pablo Ceballos
166932f008485dbb6fb452c8616abd7586f914f72ceDan Stoza    // Returns the CLOCK_MONOTONIC start time of the last dequeueBuffer call
167932f008485dbb6fb452c8616abd7586f914f72ceDan Stoza    nsecs_t getLastDequeueStartTime() const;
168932f008485dbb6fb452c8616abd7586f914f72ceDan Stoza
169e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianprotected:
170e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual ~Surface();
171edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1723da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson    // Virtual for testing.
1733da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson    virtual sp<ISurfaceComposer> composerService() const;
1740a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson    virtual nsecs_t now() const;
1753da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson
176b296533607232357597b255679db29470ab5925dMathias Agopianprivate:
177b296533607232357597b255679db29470ab5925dMathias Agopian    // can't be copied
178e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    Surface& operator = (const Surface& rhs);
179b296533607232357597b255679db29470ab5925dMathias Agopian    Surface(const Surface& rhs);
180e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
181e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // ANativeWindow hooks
182e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_cancelBuffer(ANativeWindow* window,
183e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer* buffer, int fenceFd);
184e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_dequeueBuffer(ANativeWindow* window,
185e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer** buffer, int* fenceFd);
186e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_perform(ANativeWindow* window, int operation, ...);
187e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_query(const ANativeWindow* window, int what, int* value);
188e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_queueBuffer(ANativeWindow* window,
189e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer* buffer, int fenceFd);
190e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_setSwapInterval(ANativeWindow* window, int interval);
191e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
192e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_cancelBuffer_DEPRECATED(ANativeWindow* window,
193e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer* buffer);
194e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_dequeueBuffer_DEPRECATED(ANativeWindow* window,
195e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer** buffer);
196e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_lockBuffer_DEPRECATED(ANativeWindow* window,
197e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer* buffer);
198e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    static int hook_queueBuffer_DEPRECATED(ANativeWindow* window,
199e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian            ANativeWindowBuffer* buffer);
200e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
201e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchConnect(va_list args);
202e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchDisconnect(va_list args);
203e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBufferCount(va_list args);
204e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersGeometry(va_list args);
205e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersDimensions(va_list args);
206e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersUserDimensions(va_list args);
207e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersFormat(va_list args);
208e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetScalingMode(va_list args);
209e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersTransform(va_list args);
2101681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    int dispatchSetBuffersStickyTransform(va_list args);
211e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetBuffersTimestamp(va_list args);
212e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetCrop(va_list args);
213e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchSetUsage(va_list args);
214cb496acbe593326e8d5d563847067d02b2df40ecMathias Agopian    int dispatchSetUsage64(va_list args);
215e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchLock(va_list args);
216e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int dispatchUnlockAndPost(va_list args);
2177cb0d39016ff8061fe9fc2967870c145a6ffa2acRachad    int dispatchSetSidebandStream(va_list args);
21882c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    int dispatchSetBuffersDataSpace(va_list args);
2199bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter    int dispatchSetBuffersSmpte2086Metadata(va_list args);
2209bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter    int dispatchSetBuffersCta8613Metadata(va_list args);
2215065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza    int dispatchSetSurfaceDamage(va_list args);
2223559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    int dispatchSetSharedBufferMode(va_list args);
223ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    int dispatchSetAutoRefresh(va_list args);
2240a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson    int dispatchGetDisplayRefreshCycleDuration(va_list args);
2251049d1d0b21ee318e309f9a90098c092cb879c41Brian Anderson    int dispatchGetNextFrameId(va_list args);
2267c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson    int dispatchEnableFrameTimestamps(va_list args);
2270a61b0c813f5991bf462e36a2314dda062727a10Brian Anderson    int dispatchGetCompositorTiming(va_list args);
228ce796e78a57018f186b062199c75d94545318acaPablo Ceballos    int dispatchGetFrameTimestamps(va_list args);
2291eb1b2703754beda3c20bedfca2b4fae885b7164Courtney Goeltzenleuchter    int dispatchGetWideColorSupport(va_list args);
230c5b97c5b5610b2fe6186f599798c97250bb01b95Courtney Goeltzenleuchter    int dispatchGetHdrSupport(va_list args);
231e2786ea5aec3a12d948feb85ffbb535fc89c0fe6Chia-I Wu    int dispatchGetConsumerUsage64(va_list args);
232e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
233e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianprotected:
234e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd);
235e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd);
236e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd);
237e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int perform(int operation, va_list args);
238e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int setSwapInterval(int interval);
239e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
240e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int lockBuffer_DEPRECATED(ANativeWindowBuffer* buffer);
241e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
242e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int connect(int api);
243e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int setBufferCount(int bufferCount);
2443be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    virtual int setBuffersUserDimensions(uint32_t width, uint32_t height);
2453be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    virtual int setBuffersFormat(PixelFormat format);
2463be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    virtual int setBuffersTransform(uint32_t transform);
2473be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    virtual int setBuffersStickyTransform(uint32_t transform);
248e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int setBuffersTimestamp(int64_t timestamp);
24934beb7a0ff0494b0c5ad81104171f8a49e599163Peiyong Lin    virtual int setBuffersDataSpace(ui::Dataspace dataSpace);
2509bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter    virtual int setBuffersSmpte2086Metadata(const android_smpte2086_metadata* metadata);
2519bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter    virtual int setBuffersCta8613Metadata(const android_cta861_3_metadata* metadata);
252e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int setCrop(Rect const* rect);
253cb496acbe593326e8d5d563847067d02b2df40ecMathias Agopian    virtual int setUsage(uint64_t reqUsage);
2545065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza    virtual void setSurfaceDamage(android_native_rect_t* rects, size_t numRects);
255076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
256e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianpublic:
25797b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr    virtual int disconnect(int api,
25897b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr            IGraphicBufferProducer::DisconnectMode mode =
25997b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr                    IGraphicBufferProducer::DisconnectMode::Api);
26097b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr
26119e3e06e3c65a7c001a6fe0971744ba5ff536515Pablo Ceballos    virtual int setMaxDequeuedBufferCount(int maxDequeuedBuffers);
26219e3e06e3c65a7c001a6fe0971744ba5ff536515Pablo Ceballos    virtual int setAsyncMode(bool async);
2633559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    virtual int setSharedBufferMode(bool sharedBufferMode);
264ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    virtual int setAutoRefresh(bool autoRefresh);
265c1ba5c4649554e744844b07cfe402b42fbe12ff3Sahil Dhanju    virtual int setBuffersDimensions(uint32_t width, uint32_t height);
266e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds);
267e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    virtual int unlockAndPost();
26870ccba596c586b7effde1ff99d36c911873b4ed4Dan Stoza    virtual int query(int what, int* value) const;
269b296533607232357597b255679db29470ab5925dMathias Agopian
270231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza    virtual int connect(int api, const sp<IProducerListener>& listener);
271e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh
272e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // When reportBufferRemoval is true, clients must call getAndFlushRemovedBuffers to fetch
273e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // GraphicBuffers removed from this surface after a dequeueBuffer, detachNextBuffer or
274e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // attachBuffer call. This allows clients with their own buffer caches to free up buffers no
275e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // longer in use by this surface.
276e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    virtual int connect(
277e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh            int api, const sp<IProducerListener>& listener,
278e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh            bool reportBufferRemoval);
279d9c4971da2f2c4f980a748006bd40469c3332a13Dan Stoza    virtual int detachNextBuffer(sp<GraphicBuffer>* outBuffer,
280231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza            sp<Fence>* outFence);
281231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza    virtual int attachBuffer(ANativeWindowBuffer*);
282231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza
283e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // When client connects to Surface with reportBufferRemoval set to true, any buffers removed
284e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // from this Surface will be collected and returned here. Once this method returns, these
285e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // buffers will no longer be referenced by this Surface unless they are attached to this
286e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // Surface later. The list of removed buffers will only be stored until the next dequeueBuffer,
287e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    // detachNextBuffer, or attachBuffer call.
288e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    status_t getAndFlushRemovedBuffers(std::vector<sp<GraphicBuffer>>* out);
289e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh
29034beb7a0ff0494b0c5ad81104171f8a49e599163Peiyong Lin    ui::Dataspace getBuffersDataSpace();
291152279d2725cd59369bcdf70f9622b011cae5a14Courtney Goeltzenleuchter
29240482ff650751819d4104c10a30974838168438cChavi Weingarten    static status_t attachAndQueueBuffer(Surface* surface, sp<GraphicBuffer> buffer);
29340482ff650751819d4104c10a30974838168438cChavi Weingarten
294e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianprotected:
2952b5dd4062dd951b2cafc4b80bd3a1813b013d71aMathias Agopian    enum { NUM_BUFFER_SLOTS = BufferQueueDefs::NUM_BUFFER_SLOTS };
296e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
297aca4e2287939b4ce3d9e9aced64c5c9641333503Jamie Gennis
298069b365163470d2736eb6f591c354d208b5da23bBrian Anderson    void querySupportedTimestampsLocked() const;
299069b365163470d2736eb6f591c354d208b5da23bBrian Anderson
300e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    void freeAllBuffers();
301e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int getSlotFromBufferLocked(android_native_buffer_t* buffer) const;
3028f9dbf9e13b927de2524116c30544f7dfbbbf56cMathias Agopian
303e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    struct BufferSlot {
304e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian        sp<GraphicBuffer> buffer;
305e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian        Region dirtyRegion;
306e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    };
307ba5972ffdc7179dd9a387f22032eb18666d97917Mathias Agopian
308e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mSurfaceTexture is the interface to the surface texture server. All
309e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // operations on the surface texture client ultimately translate into
310e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // interactions with the server using this interface.
311e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // TODO: rename to mBufferProducer
312e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    sp<IGraphicBufferProducer> mGraphicBufferProducer;
313e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
314e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mSlots stores the buffers that have been allocated for each buffer slot.
315e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // It is initialized to null pointers, and gets filled in with the result of
316e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // IGraphicBufferProducer::requestBuffer when the client dequeues a buffer from a
317e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // slot that has not yet been used. The buffer allocated to a slot will also
318e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // be replaced if the requested buffer usage or geometry differs from that
319e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // of the buffer allocated to a slot.
320e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    BufferSlot mSlots[NUM_BUFFER_SLOTS];
321e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
322e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mReqWidth is the buffer width that will be requested at the next dequeue
323e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // operation. It is initialized to 1.
324e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    uint32_t mReqWidth;
325e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
326e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mReqHeight is the buffer height that will be requested at the next
327e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // dequeue operation. It is initialized to 1.
328e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    uint32_t mReqHeight;
329e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
330e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mReqFormat is the buffer pixel format that will be requested at the next
331e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888.
3323be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    PixelFormat mReqFormat;
333e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
334e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mReqUsage is the set of buffer usage flags that will be requested
335e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // at the next deuque operation. It is initialized to 0.
336cb496acbe593326e8d5d563847067d02b2df40ecMathias Agopian    uint64_t mReqUsage;
337e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
338e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mTimestamp is the timestamp that will be used for the next buffer queue
339e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that
340e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // a timestamp is auto-generated when queueBuffer is called.
341e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int64_t mTimestamp;
342e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
34382c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    // mDataSpace is the buffer dataSpace that will be used for the next buffer
34434beb7a0ff0494b0c5ad81104171f8a49e599163Peiyong Lin    // queue operation. It defaults to Dataspace::UNKNOWN, which
34582c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    // means that the buffer contains some type of color data.
34634beb7a0ff0494b0c5ad81104171f8a49e599163Peiyong Lin    ui::Dataspace mDataSpace;
34782c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala
3489bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter    // mHdrMetadata is the HDR metadata that will be used for the next buffer
3499bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter    // queue operation.  There is no HDR metadata by default.
3509bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter    HdrMetadata mHdrMetadata;
3519bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter
352e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mCrop is the crop rectangle that will be used for the next buffer
353e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // that gets queued. It is set by calling setCrop.
354e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    Rect mCrop;
355e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
356e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mScalingMode is the scaling mode that will be used for the next
357e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // buffers that get queued. It is set by calling setScalingMode.
358e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    int mScalingMode;
359e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
360e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mTransform is the transform identifier that will be used for the next
361e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // buffer that gets queued. It is set by calling setTransform.
362e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    uint32_t mTransform;
363e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
3641681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    // mStickyTransform is a transform that is applied on top of mTransform
3651681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    // in each buffer that is queued.  This is typically used to force the
3661681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    // compositor to apply a transform, and will prevent the transform hint
3671681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    // from being set by the compositor.
3681681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    uint32_t mStickyTransform;
3691681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk
3703be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // mDefaultWidth is default width of the buffers, regardless of the
3713be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // native_window_set_buffers_dimensions call.
3723be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    uint32_t mDefaultWidth;
373e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
3743be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // mDefaultHeight is default height of the buffers, regardless of the
3753be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // native_window_set_buffers_dimensions call.
3763be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    uint32_t mDefaultHeight;
377e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
3783be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // mUserWidth, if non-zero, is an application-specified override
3793be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // of mDefaultWidth.  This is lower priority than the width set by
3803be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // native_window_set_buffers_dimensions.
3813be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    uint32_t mUserWidth;
382e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
3833be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // mUserHeight, if non-zero, is an application-specified override
3843be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // of mDefaultHeight.  This is lower priority than the height set
3853be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // by native_window_set_buffers_dimensions.
3863be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    uint32_t mUserHeight;
387e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
388e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mTransformHint is the transform probably applied to buffers of this
389e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // window. this is only a hint, actual transform may differ.
390e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    uint32_t mTransformHint;
391e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
392595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian    // mProducerControlledByApp whether this buffer producer is controlled
393595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian    // by the application
394595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian    bool mProducerControlledByApp;
395595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian
3967cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian    // mSwapIntervalZero set if we should drop buffers at queue() time to
3977cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian    // achieve an asynchronous swap interval
3987cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian    bool mSwapIntervalZero;
3997cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian
400e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mConsumerRunningBehind whether the consumer is running more than
401e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // one buffer behind the producer.
402e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    mutable bool mConsumerRunningBehind;
403e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
404e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // mMutex is the mutex used to prevent concurrent access to the member
405e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // variables of Surface objects. It must be locked whenever the
406e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // member variables are accessed.
407e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    mutable Mutex mMutex;
408e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
409e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    // must be used from the lock/unlock thread
410e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    sp<GraphicBuffer>           mLockedBuffer;
411e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    sp<GraphicBuffer>           mPostedBuffer;
412e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    bool                        mConnectedToCpu;
413e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian
414c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza    // When a CPU producer is attached, this reflects the region that the
415c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza    // producer wished to update as well as whether the Surface was able to copy
416c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza    // the previous buffer back to allow a partial update.
4175065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza    //
418c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza    // When a non-CPU producer is attached, this reflects the surface damage
419c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza    // (the change since the previous frame) passed in by the producer.
420e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian    Region mDirtyRegion;
421812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza
422a2eb34cfbe089deb9a519e9702e17d9dfe26f9e8Ian Elliott    // mBufferAge tracks the age of the contents of the most recently dequeued
423a2eb34cfbe089deb9a519e9702e17d9dfe26f9e8Ian Elliott    // buffer as the number of frames that have elapsed since it was last queued
424a2eb34cfbe089deb9a519e9702e17d9dfe26f9e8Ian Elliott    uint64_t mBufferAge;
425a2eb34cfbe089deb9a519e9702e17d9dfe26f9e8Ian Elliott
426812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    // Stores the current generation number. See setGenerationNumber and
427812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    // IGraphicBufferProducer::setGenerationNumber for more information.
428812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    uint32_t mGenerationNumber;
429ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos
430ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // Caches the values that have been passed to the producer.
4313559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    bool mSharedBufferMode;
432ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    bool mAutoRefresh;
433ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos
4343559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    // If in shared buffer mode and auto refresh is enabled, store the shared
435ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // buffer slot and return it for all calls to queue/dequeue without going
436ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // over Binder.
437ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    int mSharedBufferSlot;
438ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos
439ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // This is true if the shared buffer has already been queued/canceled. It's
440ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // used to prevent a mismatch between the number of queue/dequeue calls.
441ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    bool mSharedBufferHasBeenQueued;
4429f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr
44370ccba596c586b7effde1ff99d36c911873b4ed4Dan Stoza    // These are used to satisfy the NATIVE_WINDOW_LAST_*_DURATION queries
44470ccba596c586b7effde1ff99d36c911873b4ed4Dan Stoza    nsecs_t mLastDequeueDuration = 0;
44570ccba596c586b7effde1ff99d36c911873b4ed4Dan Stoza    nsecs_t mLastQueueDuration = 0;
44670ccba596c586b7effde1ff99d36c911873b4ed4Dan Stoza
447932f008485dbb6fb452c8616abd7586f914f72ceDan Stoza    // Stores the time right before we call IGBP::dequeueBuffer
448932f008485dbb6fb452c8616abd7586f914f72ceDan Stoza    nsecs_t mLastDequeueStartTime = 0;
449932f008485dbb6fb452c8616abd7586f914f72ceDan Stoza
4509f31e299b3ec93b7bac969846105e7e926e3efcdRobert Carr    Condition mQueueBufferCondition;
451bc8c1928e1dbdaf6a2820f6e426c96ed61284043Pablo Ceballos
45250143b3780ad2aaa544c8d2d47619214b79c3c56Brian Anderson    uint64_t mNextFrameNumber = 1;
45350143b3780ad2aaa544c8d2d47619214b79c3c56Brian Anderson    uint64_t mLastFrameNumber = 0;
454069b365163470d2736eb6f591c354d208b5da23bBrian Anderson
4556b376713907086c9642e7b7e66e51ddfa531b003Brian Anderson    // Mutable because ANativeWindow::query needs this class const.
4566b376713907086c9642e7b7e66e51ddfa531b003Brian Anderson    mutable bool mQueriedSupportedTimestamps;
4576b376713907086c9642e7b7e66e51ddfa531b003Brian Anderson    mutable bool mFrameTimestampsSupportsPresent;
4586b376713907086c9642e7b7e66e51ddfa531b003Brian Anderson
4593890c3995c4a52439844faeb80b5503d42b977d8Brian Anderson    // A cached copy of the FrameEventHistory maintained by the consumer.
4607c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson    bool mEnableFrameTimestamps = false;
4613da8d2748580b2575e368e203ce2c7f8d34dea05Brian Anderson    std::unique_ptr<ProducerFrameEventHistory> mFrameEventHistory;
462e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh
463e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    bool mReportRemovedBuffers = false;
464e572fd7b6262389e89cc23d9eb25129394698eb8Yin-Chia Yeh    std::vector<sp<GraphicBuffer>> mRemovedBuffers;
465edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
466edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
46705debe1d787b7471c2bc9c8f7569a338ca5c7ad4Mathias Agopian} // namespace android
468edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
469e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#endif  // ANDROID_GUI_SURFACE_H
470