michael@0: /* michael@0: * Copyright (C) 2012 The Android Open Source Project michael@0: * Copyright (C) 2013 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_GONKNATIVEWINDOW_KK_H michael@0: #define NATIVEWINDOW_GONKNATIVEWINDOW_KK_H michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "CameraCommon.h" michael@0: #include "GonkConsumerBaseKK.h" michael@0: #include "GrallocImages.h" michael@0: #include "IGonkGraphicBufferConsumer.h" michael@0: #include "mozilla/layers/ImageBridgeChild.h" michael@0: #include "mozilla/layers/LayersSurfaces.h" michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: class PGrallocBufferChild; michael@0: } michael@0: } michael@0: michael@0: namespace android { michael@0: michael@0: // The user of GonkNativeWindow who wants to receive notification of michael@0: // new frames should implement this interface. michael@0: class GonkNativeWindowNewFrameCallback { michael@0: public: michael@0: virtual void OnNewFrame() = 0; michael@0: }; michael@0: michael@0: /** michael@0: * GonkNativeWindow is a GonkBufferQueue consumer endpoint that allows clients michael@0: * access to the whole BufferItem entry from GonkBufferQueue. Multiple buffers may michael@0: * be acquired at once, to be used concurrently by the client. This consumer can michael@0: * operate either in synchronous or asynchronous mode. michael@0: */ michael@0: class GonkNativeWindow: public GonkConsumerBase michael@0: { michael@0: typedef mozilla::layers::TextureClient TextureClient; michael@0: public: michael@0: typedef GonkConsumerBase::FrameAvailableListener FrameAvailableListener; michael@0: typedef IGonkGraphicBufferConsumer::BufferItem BufferItem; michael@0: michael@0: enum { INVALID_BUFFER_SLOT = GonkBufferQueue::INVALID_BUFFER_SLOT }; michael@0: enum { NO_BUFFER_AVAILABLE = GonkBufferQueue::NO_BUFFER_AVAILABLE }; michael@0: michael@0: // Create a new buffer item consumer. The consumerUsage parameter determines michael@0: // the consumer usage flags passed to the graphics allocator. The michael@0: // bufferCount parameter specifies how many buffers can be locked for user michael@0: // access at the same time. michael@0: // controlledByApp tells whether this consumer is controlled by the michael@0: // application. michael@0: GonkNativeWindow(); michael@0: GonkNativeWindow(const sp& bq, uint32_t consumerUsage, michael@0: int bufferCount = GonkBufferQueue::MIN_UNDEQUEUED_BUFFERS, michael@0: bool controlledByApp = false); michael@0: michael@0: virtual ~GonkNativeWindow(); michael@0: michael@0: // set the name of the GonkNativeWindow that will be used to identify it in michael@0: // log messages. michael@0: void setName(const String8& name); michael@0: michael@0: // Gets the next graphics buffer from the producer, filling out the michael@0: // passed-in BufferItem structure. Returns NO_BUFFER_AVAILABLE if the queue michael@0: // of buffers is empty, and INVALID_OPERATION if the maximum number of michael@0: // buffers is already acquired. michael@0: // michael@0: // Only a fixed number of buffers can be acquired at a time, determined by michael@0: // the construction-time bufferCount parameter. If INVALID_OPERATION is michael@0: // returned by acquireBuffer, then old buffers must be returned to the michael@0: // queue by calling releaseBuffer before more buffers can be acquired. michael@0: // michael@0: // If waitForFence is true, and the acquired BufferItem has a valid fence object, michael@0: // acquireBuffer will wait on the fence with no timeout before returning. michael@0: status_t acquireBuffer(BufferItem *item, nsecs_t presentWhen, michael@0: bool waitForFence = true); michael@0: michael@0: // Returns an acquired buffer to the queue, allowing it to be reused. Since michael@0: // only a fixed number of buffers may be acquired at a time, old buffers michael@0: // must be released by calling releaseBuffer to ensure new buffers can be michael@0: // acquired by acquireBuffer. Once a BufferItem is released, the caller must michael@0: // not access any members of the BufferItem, and should immediately remove michael@0: // all of its references to the BufferItem itself. michael@0: status_t releaseBuffer(const BufferItem &item, michael@0: const sp& releaseFence = Fence::NO_FENCE); michael@0: michael@0: // setDefaultBufferSize is used to set the size of buffers returned by michael@0: // requestBuffers when a with and height of zero is requested. michael@0: status_t setDefaultBufferSize(uint32_t w, uint32_t h); michael@0: michael@0: // setDefaultBufferFormat allows the BufferQueue to create michael@0: // GraphicBuffers of a defaultFormat if no format is specified michael@0: // in dequeueBuffer michael@0: status_t setDefaultBufferFormat(uint32_t defaultFormat); michael@0: michael@0: // Get next frame from the queue, caller owns the returned buffer. michael@0: mozilla::TemporaryRef getCurrentBuffer(); michael@0: michael@0: // Return the buffer to the queue and mark it as FREE. After that michael@0: // the buffer is useable again for the decoder. michael@0: void returnBuffer(TextureClient* client); michael@0: michael@0: mozilla::TemporaryRef getTextureClientFromBuffer(ANativeWindowBuffer* buffer); michael@0: michael@0: void setNewFrameCallback(GonkNativeWindowNewFrameCallback* callback); michael@0: michael@0: static void RecycleCallback(TextureClient* client, void* closure); michael@0: michael@0: protected: michael@0: virtual void onFrameAvailable(); michael@0: michael@0: private: michael@0: GonkNativeWindowNewFrameCallback* mNewFrameCallback; michael@0: }; michael@0: michael@0: } // namespace android michael@0: michael@0: #endif // NATIVEWINDOW_GONKNATIVEWINDOW_JB_H