1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/gonk/nativewindow/GonkNativeWindowJB.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,134 @@ 1.4 +/* 1.5 + * Copyright (C) 2012 The Android Open Source Project 1.6 + * Copyright (C) 2013 Mozilla Foundation 1.7 + * 1.8 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.9 + * you may not use this file except in compliance with the License. 1.10 + * You may obtain a copy of the License at 1.11 + * 1.12 + * http://www.apache.org/licenses/LICENSE-2.0 1.13 + * 1.14 + * Unless required by applicable law or agreed to in writing, software 1.15 + * distributed under the License is distributed on an "AS IS" BASIS, 1.16 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.17 + * See the License for the specific language governing permissions and 1.18 + * limitations under the License. 1.19 + */ 1.20 + 1.21 +#ifndef NATIVEWINDOW_GONKNATIVEWINDOW_JB_H 1.22 +#define NATIVEWINDOW_GONKNATIVEWINDOW_JB_H 1.23 + 1.24 +#include <ui/GraphicBuffer.h> 1.25 +#include <utils/String8.h> 1.26 +#include <utils/Vector.h> 1.27 +#include <utils/threads.h> 1.28 + 1.29 +#include "CameraCommon.h" 1.30 +#include "GonkConsumerBaseJB.h" 1.31 +#include "GrallocImages.h" 1.32 +#include "mozilla/layers/LayersSurfaces.h" 1.33 + 1.34 +namespace mozilla { 1.35 +namespace layers { 1.36 + class PGrallocBufferChild; 1.37 +} 1.38 +} 1.39 + 1.40 +namespace android { 1.41 + 1.42 +// The user of GonkNativeWindow who wants to receive notification of 1.43 +// new frames should implement this interface. 1.44 +class GonkNativeWindowNewFrameCallback { 1.45 +public: 1.46 + virtual void OnNewFrame() = 0; 1.47 +}; 1.48 + 1.49 +/** 1.50 + * GonkNativeWindow is a GonkBufferQueue consumer endpoint that allows clients 1.51 + * access to the whole BufferItem entry from GonkBufferQueue. Multiple buffers may 1.52 + * be acquired at once, to be used concurrently by the client. This consumer can 1.53 + * operate either in synchronous or asynchronous mode. 1.54 + */ 1.55 +class GonkNativeWindow: public GonkConsumerBase 1.56 +{ 1.57 + typedef mozilla::layers::TextureClient TextureClient; 1.58 + public: 1.59 + typedef GonkConsumerBase::FrameAvailableListener FrameAvailableListener; 1.60 + 1.61 + typedef GonkBufferQueue::BufferItem BufferItem; 1.62 + 1.63 + enum { INVALID_BUFFER_SLOT = GonkBufferQueue::INVALID_BUFFER_SLOT }; 1.64 + enum { NO_BUFFER_AVAILABLE = GonkBufferQueue::NO_BUFFER_AVAILABLE }; 1.65 + 1.66 + // Create a new buffer item consumer. The consumerUsage parameter determines 1.67 + // the consumer usage flags passed to the graphics allocator. The 1.68 + // bufferCount parameter specifies how many buffers can be locked for user 1.69 + // access at the same time. 1.70 + GonkNativeWindow(); 1.71 + 1.72 + virtual ~GonkNativeWindow(); 1.73 + 1.74 + // set the name of the GonkNativeWindow that will be used to identify it in 1.75 + // log messages. 1.76 + void setName(const String8& name); 1.77 + 1.78 + // Gets the next graphics buffer from the producer, filling out the 1.79 + // passed-in BufferItem structure. Returns NO_BUFFER_AVAILABLE if the queue 1.80 + // of buffers is empty, and INVALID_OPERATION if the maximum number of 1.81 + // buffers is already acquired. 1.82 + // 1.83 + // Only a fixed number of buffers can be acquired at a time, determined by 1.84 + // the construction-time bufferCount parameter. If INVALID_OPERATION is 1.85 + // returned by acquireBuffer, then old buffers must be returned to the 1.86 + // queue by calling releaseBuffer before more buffers can be acquired. 1.87 + // 1.88 + // If waitForFence is true, and the acquired BufferItem has a valid fence object, 1.89 + // acquireBuffer will wait on the fence with no timeout before returning. 1.90 +#if ANDROID_VERSION >= 18 1.91 + status_t acquireBuffer(BufferItem *item, bool waitForFence = true); 1.92 +#endif 1.93 + // Returns an acquired buffer to the queue, allowing it to be reused. Since 1.94 + // only a fixed number of buffers may be acquired at a time, old buffers 1.95 + // must be released by calling releaseBuffer to ensure new buffers can be 1.96 + // acquired by acquireBuffer. Once a BufferItem is released, the caller must 1.97 + // not access any members of the BufferItem, and should immediately remove 1.98 + // all of its references to the BufferItem itself. 1.99 +#if ANDROID_VERSION >= 18 1.100 + status_t releaseBuffer(const BufferItem &item, 1.101 + const sp<Fence>& releaseFence = Fence::NO_FENCE); 1.102 +#endif 1.103 + 1.104 + sp<IGraphicBufferProducer> getProducerInterface() const { return getBufferQueue(); } 1.105 + 1.106 + // setDefaultBufferSize is used to set the size of buffers returned by 1.107 + // requestBuffers when a with and height of zero is requested. 1.108 + status_t setDefaultBufferSize(uint32_t w, uint32_t h); 1.109 + 1.110 + // setDefaultBufferFormat allows the BufferQueue to create 1.111 + // GraphicBuffers of a defaultFormat if no format is specified 1.112 + // in dequeueBuffer 1.113 + status_t setDefaultBufferFormat(uint32_t defaultFormat); 1.114 + 1.115 + // Get next frame from the queue, caller owns the returned buffer. 1.116 + mozilla::TemporaryRef<TextureClient> getCurrentBuffer(); 1.117 + 1.118 + // Return the buffer to the queue and mark it as FREE. After that 1.119 + // the buffer is useable again for the decoder. 1.120 + void returnBuffer(TextureClient* client); 1.121 + 1.122 + mozilla::TemporaryRef<TextureClient> getTextureClientFromBuffer(ANativeWindowBuffer* buffer); 1.123 + 1.124 + void setNewFrameCallback(GonkNativeWindowNewFrameCallback* callback); 1.125 + 1.126 + static void RecycleCallback(TextureClient* client, void* closure); 1.127 + 1.128 +protected: 1.129 + virtual void onFrameAvailable(); 1.130 + 1.131 +private: 1.132 + GonkNativeWindowNewFrameCallback* mNewFrameCallback; 1.133 +}; 1.134 + 1.135 +} // namespace android 1.136 + 1.137 +#endif // NATIVEWINDOW_GONKNATIVEWINDOW_JB_H