michael@0: /* michael@0: * Copyright (C) 2010 The Android Open Source Project michael@0: * Copyright (C) 2012 Mozilla Foundation michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_ICS_H michael@0: #define NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_ICS_H michael@0: michael@0: #include michael@0: michael@0: #include "GonkNativeWindow.h" michael@0: michael@0: namespace android { michael@0: michael@0: class GonkNativeWindowClient : public EGLNativeBase michael@0: { michael@0: public: michael@0: GonkNativeWindowClient(const sp& window); michael@0: ~GonkNativeWindowClient(); // this class cannot be overloaded michael@0: michael@0: private: michael@0: void init(); michael@0: michael@0: // ANativeWindow hooks michael@0: static int hook_cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer); michael@0: static int hook_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer); michael@0: static int hook_lockBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer); michael@0: static int hook_perform(ANativeWindow* window, int operation, ...); michael@0: static int hook_query(const ANativeWindow* window, int what, int* value); michael@0: static int hook_queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer); michael@0: static int hook_setSwapInterval(ANativeWindow* window, int interval); michael@0: michael@0: int dispatchConnect(va_list args); michael@0: int dispatchDisconnect(va_list args); michael@0: int dispatchSetBufferCount(va_list args); michael@0: int dispatchSetBuffersGeometry(va_list args); michael@0: int dispatchSetBuffersDimensions(va_list args); michael@0: int dispatchSetBuffersFormat(va_list args); michael@0: int dispatchSetBuffersTimestamp(va_list args); michael@0: int dispatchSetUsage(va_list args); michael@0: michael@0: protected: michael@0: virtual int cancelBuffer(ANativeWindowBuffer* buffer); michael@0: virtual int dequeueBuffer(ANativeWindowBuffer** buffer); michael@0: virtual int lockBuffer(ANativeWindowBuffer* buffer); michael@0: virtual int perform(int operation, va_list args); michael@0: virtual int query(int what, int* value) const; michael@0: virtual int queueBuffer(ANativeWindowBuffer* buffer); michael@0: virtual int setSwapInterval(int interval); michael@0: michael@0: virtual int connect(int api); michael@0: virtual int disconnect(int api); michael@0: virtual int setBufferCount(int bufferCount); michael@0: virtual int setBuffersDimensions(int w, int h); michael@0: virtual int setBuffersFormat(int format); michael@0: virtual int setBuffersTimestamp(int64_t timestamp); michael@0: virtual int setUsage(uint32_t reqUsage); michael@0: michael@0: int getNumberOfArgsForOperation(int operation); michael@0: michael@0: enum { MIN_UNDEQUEUED_BUFFERS = GonkNativeWindow::MIN_UNDEQUEUED_BUFFERS }; michael@0: enum { NUM_BUFFER_SLOTS = GonkNativeWindow::NUM_BUFFER_SLOTS }; michael@0: enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 }; michael@0: enum { NATIVE_WINDOW_SET_BUFFERS_SIZE = 0x10000000 }; michael@0: michael@0: private: michael@0: void freeAllBuffers(); michael@0: int getSlotFromBufferLocked(android_native_buffer_t* buffer) const; michael@0: michael@0: sp mNativeWindow; michael@0: michael@0: // mSlots stores the buffers that have been allocated for each buffer slot. michael@0: // It is initialized to null pointers, and gets filled in with the result of michael@0: // ISurfaceTexture::requestBuffer when the client dequeues a buffer from a michael@0: // slot that has not yet been used. The buffer allocated to a slot will also michael@0: // be replaced if the requested buffer usage or geometry differs from that michael@0: // of the buffer allocated to a slot. michael@0: sp mSlots[NUM_BUFFER_SLOTS]; michael@0: michael@0: // mReqWidth is the buffer width that will be requested at the next dequeue michael@0: // operation. It is initialized to 1. michael@0: uint32_t mReqWidth; michael@0: michael@0: // mReqHeight is the buffer height that will be requested at the next deuque michael@0: // operation. It is initialized to 1. michael@0: uint32_t mReqHeight; michael@0: michael@0: // mReqFormat is the buffer pixel format that will be requested at the next michael@0: // deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888. michael@0: uint32_t mReqFormat; michael@0: michael@0: // mReqUsage is the set of buffer usage flags that will be requested michael@0: // at the next deuque operation. It is initialized to 0. michael@0: uint32_t mReqUsage; michael@0: michael@0: // mTimestamp is the timestamp that will be used for the next buffer queue michael@0: // operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that michael@0: // a timestamp is auto-generated when queueBuffer is called. michael@0: int64_t mTimestamp; michael@0: michael@0: // mDefaultWidth is default width of the window, regardless of the michael@0: // native_window_set_buffers_dimensions call michael@0: uint32_t mDefaultWidth; michael@0: michael@0: // mDefaultHeight is default width of the window, regardless of the michael@0: // native_window_set_buffers_dimensions call michael@0: uint32_t mDefaultHeight; michael@0: michael@0: // mTransformHint is the transform probably applied to buffers of this michael@0: // window. this is only a hint, actual transform may differ. michael@0: uint32_t mTransformHint; michael@0: michael@0: // mMutex is the mutex used to prevent concurrent access to the member michael@0: // variables of GonkNativeWindow objects. It must be locked whenever the michael@0: // member variables are accessed. michael@0: mutable Mutex mMutex; michael@0: michael@0: bool mConnectedToCpu; michael@0: }; michael@0: michael@0: michael@0: }; // namespace android michael@0: michael@0: #endif // NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_ICS_H