Surface.h revision 812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2
1edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project/* 2e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * Copyright (C) 2010 The Android Open Source Project 3edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * 4edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 5edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * you may not use this file except in compliance with the License. 6edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * You may obtain a copy of the License at 7edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * 8edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 9edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * 10edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 11edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 12edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * See the License for the specific language governing permissions and 14edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * limitations under the License. 15edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project */ 16edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project 1790ac799241f077a7b7e6c1875fd933864c8dd2a7Mathias Agopian#ifndef ANDROID_GUI_SURFACE_H 1890ac799241f077a7b7e6c1875fd933864c8dd2a7Mathias Agopian#define ANDROID_GUI_SURFACE_H 19edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project 20e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#include <gui/IGraphicBufferProducer.h> 21e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#include <gui/BufferQueue.h> 22e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 23e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#include <ui/ANativeObjectBase.h> 24e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#include <ui/Region.h> 25edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project 26edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <utils/RefBase.h> 27edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <utils/threads.h> 28e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#include <utils/KeyedVector.h> 29edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project 30e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianstruct ANativeWindow_Buffer; 319cce325fae8adcf7560a28eef394489f09bad74dMathias Agopian 32edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectnamespace android { 33edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project 340273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden/* 35e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * An implementation of ANativeWindow that feeds graphics buffers into a 36e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * BufferQueue. 370273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden * 38e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * This is typically used by programs that want to render frames through 39e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * some means (maybe OpenGL, a software renderer, or a hardware decoder) 40e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * and have the frames they create forwarded to SurfaceFlinger for 41e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * compositing. For example, a video decoder could render a frame and call 42e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * eglSwapBuffers(), which invokes ANativeWindow callbacks defined by 43e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * Surface. Surface then forwards the buffers through Binder IPC 44e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * to the BufferQueue's producer interface, providing the new frame to a 45e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * consumer such as GLConsumer. 460273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden */ 47e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianclass Surface 48e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian : public ANativeObjectBase<ANativeWindow, Surface, RefBase> 49076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{ 50edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectpublic: 51edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project 52cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian /* 53cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian * creates a Surface from the given IGraphicBufferProducer (which concrete 54cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian * implementation is a BufferQueue). 55cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian * 56cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian * Surface is mainly state-less while it's disconnected, it can be 57cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian * viewed as a glorified IGraphicBufferProducer holder. It's therefore 58cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian * safe to create other Surfaces from the same IGraphicBufferProducer. 59cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian * 60cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian * However, once a Surface is connected, it'll prevent other Surfaces 61cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian * referring to the same IGraphicBufferProducer to become connected and 62cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian * therefore prevent them to be used as actual producers of buffers. 63595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian * 64595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian * the controlledByApp flag indicates that this Surface (producer) is 65595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian * controlled by the application. This flag is used at connect time. 66cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian */ 67595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian Surface(const sp<IGraphicBufferProducer>& bufferProducer, bool controlledByApp = false); 68bd050ab2af1421d527d1a80ce59dd8d9940a838cTed Bonkenburg 69cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian /* getIGraphicBufferProducer() returns the IGraphicBufferProducer this 70cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian * Surface was created with. Usually it's an error to use the 71cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian * IGraphicBufferProducer while the Surface is connected. 72cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian */ 73e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian sp<IGraphicBufferProducer> getIGraphicBufferProducer() const; 74bd050ab2af1421d527d1a80ce59dd8d9940a838cTed Bonkenburg 75cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian /* convenience function to check that the given surface is non NULL as 76cf0b8c85fb0106751256dba7821f86b5ad03126cMathias Agopian * well as its IGraphicBufferProducer */ 77c4905eb49d20667381f3cda7c6f6894234404bd3Mathias Agopian static bool isValid(const sp<Surface>& surface) { 78f25c5086cf46eb029d887f34f25a09220e44958cMathias Agopian return surface != NULL && surface->getIGraphicBufferProducer() != NULL; 79f25c5086cf46eb029d887f34f25a09220e44958cMathias Agopian } 80f25c5086cf46eb029d887f34f25a09220e44958cMathias Agopian 81399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall /* Attaches a sideband buffer stream to the Surface's IGraphicBufferProducer. 82399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall * 83399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall * A sideband stream is a device-specific mechanism for passing buffers 84399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall * from the producer to the consumer without using dequeueBuffer/ 85399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall * queueBuffer. If a sideband stream is present, the consumer can choose 86399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall * whether to acquire buffers from the sideband stream or from the queued 87399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall * buffers. 88399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall * 89399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall * Passing NULL or a different stream handle will detach the previous 90399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall * handle if any. 91399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall */ 92399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall void setSidebandStream(const sp<NativeHandle>& stream); 93399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall 9429a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza /* Allocates buffers based on the current dimensions/format. 9529a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza * 9629a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza * This function will allocate up to the maximum number of buffers 9729a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza * permitted by the current BufferQueue configuration. It will use the 9829a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza * default format and dimensions. This is most useful to avoid an allocation 9929a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza * delay during dequeueBuffer. If there are already the maximum number of 10029a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza * buffers allocated, this function has no effect. 10129a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza */ 10229a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza void allocateBuffers(); 10329a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza 104812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza /* Sets the generation number on the IGraphicBufferProducer and updates the 105812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza * generation number on any buffers attached to the Surface after this call. 106812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza * See IGBP::setGenerationNumber for more information. */ 107812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza status_t setGenerationNumber(uint32_t generationNumber); 108812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza 109e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianprotected: 110e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual ~Surface(); 111edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project 112b296533607232357597b255679db29470ab5925dMathias Agopianprivate: 113b296533607232357597b255679db29470ab5925dMathias Agopian // can't be copied 114e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian Surface& operator = (const Surface& rhs); 115b296533607232357597b255679db29470ab5925dMathias Agopian Surface(const Surface& rhs); 116e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 117e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // ANativeWindow hooks 118e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian static int hook_cancelBuffer(ANativeWindow* window, 119e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian ANativeWindowBuffer* buffer, int fenceFd); 120e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian static int hook_dequeueBuffer(ANativeWindow* window, 121e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian ANativeWindowBuffer** buffer, int* fenceFd); 122e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian static int hook_perform(ANativeWindow* window, int operation, ...); 123e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian static int hook_query(const ANativeWindow* window, int what, int* value); 124e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian static int hook_queueBuffer(ANativeWindow* window, 125e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian ANativeWindowBuffer* buffer, int fenceFd); 126e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian static int hook_setSwapInterval(ANativeWindow* window, int interval); 127e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 128e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian static int hook_cancelBuffer_DEPRECATED(ANativeWindow* window, 129e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian ANativeWindowBuffer* buffer); 130e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian static int hook_dequeueBuffer_DEPRECATED(ANativeWindow* window, 131e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian ANativeWindowBuffer** buffer); 132e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian static int hook_lockBuffer_DEPRECATED(ANativeWindow* window, 133e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian ANativeWindowBuffer* buffer); 134e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian static int hook_queueBuffer_DEPRECATED(ANativeWindow* window, 135e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian ANativeWindowBuffer* buffer); 136e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 137e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int dispatchConnect(va_list args); 138e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int dispatchDisconnect(va_list args); 139e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int dispatchSetBufferCount(va_list args); 140e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int dispatchSetBuffersGeometry(va_list args); 141e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int dispatchSetBuffersDimensions(va_list args); 142e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int dispatchSetBuffersUserDimensions(va_list args); 143e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int dispatchSetBuffersFormat(va_list args); 144e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int dispatchSetScalingMode(va_list args); 145e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int dispatchSetBuffersTransform(va_list args); 1461681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk int dispatchSetBuffersStickyTransform(va_list args); 147e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int dispatchSetBuffersTimestamp(va_list args); 148e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int dispatchSetCrop(va_list args); 149e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int dispatchSetPostTransformCrop(va_list args); 150e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int dispatchSetUsage(va_list args); 151e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int dispatchLock(va_list args); 152e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int dispatchUnlockAndPost(va_list args); 1537cb0d39016ff8061fe9fc2967870c145a6ffa2acRachad int dispatchSetSidebandStream(va_list args); 15482c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala int dispatchSetBuffersDataSpace(va_list args); 1555065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza int dispatchSetSurfaceDamage(va_list args); 156e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 157e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianprotected: 158e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd); 159e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd); 160e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd); 161e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int perform(int operation, va_list args); 162e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int query(int what, int* value) const; 163e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int setSwapInterval(int interval); 164e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 165e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int lockBuffer_DEPRECATED(ANativeWindowBuffer* buffer); 166e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 167e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int connect(int api); 168e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int disconnect(int api); 169e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int setBufferCount(int bufferCount); 1703be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza virtual int setBuffersDimensions(uint32_t width, uint32_t height); 1713be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza virtual int setBuffersUserDimensions(uint32_t width, uint32_t height); 1723be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza virtual int setBuffersFormat(PixelFormat format); 173e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int setScalingMode(int mode); 1743be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza virtual int setBuffersTransform(uint32_t transform); 1753be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza virtual int setBuffersStickyTransform(uint32_t transform); 176e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int setBuffersTimestamp(int64_t timestamp); 17782c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala virtual int setBuffersDataSpace(android_dataspace dataSpace); 178e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int setCrop(Rect const* rect); 179e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int setUsage(uint32_t reqUsage); 1805065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza virtual void setSurfaceDamage(android_native_rect_t* rects, size_t numRects); 181076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 182e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianpublic: 183e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds); 184e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian virtual int unlockAndPost(); 185b296533607232357597b255679db29470ab5925dMathias Agopian 186231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza virtual int connect(int api, const sp<IProducerListener>& listener); 187d9c4971da2f2c4f980a748006bd40469c3332a13Dan Stoza virtual int detachNextBuffer(sp<GraphicBuffer>* outBuffer, 188231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza sp<Fence>* outFence); 189231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza virtual int attachBuffer(ANativeWindowBuffer*); 190231832eb27107fb561467f5f4a9be2c577c61ea8Dan Stoza 191e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianprotected: 192e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian enum { NUM_BUFFER_SLOTS = BufferQueue::NUM_BUFFER_SLOTS }; 193e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 }; 194aca4e2287939b4ce3d9e9aced64c5c9641333503Jamie Gennis 195e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianprivate: 196e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian void freeAllBuffers(); 197e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int getSlotFromBufferLocked(android_native_buffer_t* buffer) const; 1988f9dbf9e13b927de2524116c30544f7dfbbbf56cMathias Agopian 199e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian struct BufferSlot { 200e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian sp<GraphicBuffer> buffer; 201e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian Region dirtyRegion; 202e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian }; 203ba5972ffdc7179dd9a387f22032eb18666d97917Mathias Agopian 204e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // mSurfaceTexture is the interface to the surface texture server. All 205e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // operations on the surface texture client ultimately translate into 206e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // interactions with the server using this interface. 207e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // TODO: rename to mBufferProducer 208e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian sp<IGraphicBufferProducer> mGraphicBufferProducer; 209e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 210e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // mSlots stores the buffers that have been allocated for each buffer slot. 211e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // It is initialized to null pointers, and gets filled in with the result of 212e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // IGraphicBufferProducer::requestBuffer when the client dequeues a buffer from a 213e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // slot that has not yet been used. The buffer allocated to a slot will also 214e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // be replaced if the requested buffer usage or geometry differs from that 215e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // of the buffer allocated to a slot. 216e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian BufferSlot mSlots[NUM_BUFFER_SLOTS]; 217e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 218e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // mReqWidth is the buffer width that will be requested at the next dequeue 219e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // operation. It is initialized to 1. 220e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian uint32_t mReqWidth; 221e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 222e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // mReqHeight is the buffer height that will be requested at the next 223e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // dequeue operation. It is initialized to 1. 224e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian uint32_t mReqHeight; 225e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 226e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // mReqFormat is the buffer pixel format that will be requested at the next 227e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888. 2283be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza PixelFormat mReqFormat; 229e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 230e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // mReqUsage is the set of buffer usage flags that will be requested 231e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // at the next deuque operation. It is initialized to 0. 232e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian uint32_t mReqUsage; 233e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 234e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // mTimestamp is the timestamp that will be used for the next buffer queue 235e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that 236e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // a timestamp is auto-generated when queueBuffer is called. 237e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int64_t mTimestamp; 238e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 23982c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala // mDataSpace is the buffer dataSpace that will be used for the next buffer 24082c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala // queue operation. It defaults to HAL_DATASPACE_UNKNOWN, which 24182c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala // means that the buffer contains some type of color data. 24282c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala android_dataspace mDataSpace; 24382c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala 244e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // mCrop is the crop rectangle that will be used for the next buffer 245e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // that gets queued. It is set by calling setCrop. 246e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian Rect mCrop; 247e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 248e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // mScalingMode is the scaling mode that will be used for the next 249e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // buffers that get queued. It is set by calling setScalingMode. 250e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian int mScalingMode; 251e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 252e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // mTransform is the transform identifier that will be used for the next 253e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // buffer that gets queued. It is set by calling setTransform. 254e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian uint32_t mTransform; 255e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 2561681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk // mStickyTransform is a transform that is applied on top of mTransform 2571681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk // in each buffer that is queued. This is typically used to force the 2581681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk // compositor to apply a transform, and will prevent the transform hint 2591681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk // from being set by the compositor. 2601681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk uint32_t mStickyTransform; 2611681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk 2623be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza // mDefaultWidth is default width of the buffers, regardless of the 2633be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza // native_window_set_buffers_dimensions call. 2643be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza uint32_t mDefaultWidth; 265e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 2663be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza // mDefaultHeight is default height of the buffers, regardless of the 2673be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza // native_window_set_buffers_dimensions call. 2683be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza uint32_t mDefaultHeight; 269e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 2703be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza // mUserWidth, if non-zero, is an application-specified override 2713be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza // of mDefaultWidth. This is lower priority than the width set by 2723be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza // native_window_set_buffers_dimensions. 2733be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza uint32_t mUserWidth; 274e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 2753be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza // mUserHeight, if non-zero, is an application-specified override 2763be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza // of mDefaultHeight. This is lower priority than the height set 2773be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza // by native_window_set_buffers_dimensions. 2783be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza uint32_t mUserHeight; 279e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 280e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // mTransformHint is the transform probably applied to buffers of this 281e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // window. this is only a hint, actual transform may differ. 282e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian uint32_t mTransformHint; 283e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 284595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian // mProducerControlledByApp whether this buffer producer is controlled 285595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian // by the application 286595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian bool mProducerControlledByApp; 287595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian 2887cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian // mSwapIntervalZero set if we should drop buffers at queue() time to 2897cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian // achieve an asynchronous swap interval 2907cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian bool mSwapIntervalZero; 2917cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian 292e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // mConsumerRunningBehind whether the consumer is running more than 293e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // one buffer behind the producer. 294e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian mutable bool mConsumerRunningBehind; 295e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 296e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // mMutex is the mutex used to prevent concurrent access to the member 297e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // variables of Surface objects. It must be locked whenever the 298e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // member variables are accessed. 299e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian mutable Mutex mMutex; 300e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 301e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian // must be used from the lock/unlock thread 302e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian sp<GraphicBuffer> mLockedBuffer; 303e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian sp<GraphicBuffer> mPostedBuffer; 304e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian bool mConnectedToCpu; 305e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian 306c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza // When a CPU producer is attached, this reflects the region that the 307c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza // producer wished to update as well as whether the Surface was able to copy 308c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza // the previous buffer back to allow a partial update. 3095065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza // 310c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza // When a non-CPU producer is attached, this reflects the surface damage 311c62acbd12711ee6cff1ef94c146316dfe5169045Dan Stoza // (the change since the previous frame) passed in by the producer. 312e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian Region mDirtyRegion; 313812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza 314812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza // Stores the current generation number. See setGenerationNumber and 315812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza // IGraphicBufferProducer::setGenerationNumber for more information. 316812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza uint32_t mGenerationNumber; 317edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}; 318edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project 319edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}; // namespace android 320edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project 321e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#endif // ANDROID_GUI_SURFACE_H 322