1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/gonk/nativewindow/GonkNativeWindowKK.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,136 @@ 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_KK_H 1.22 +#define NATIVEWINDOW_GONKNATIVEWINDOW_KK_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 "GonkConsumerBaseKK.h" 1.31 +#include "GrallocImages.h" 1.32 +#include "IGonkGraphicBufferConsumer.h" 1.33 +#include "mozilla/layers/ImageBridgeChild.h" 1.34 +#include "mozilla/layers/LayersSurfaces.h" 1.35 + 1.36 +namespace mozilla { 1.37 +namespace layers { 1.38 + class PGrallocBufferChild; 1.39 +} 1.40 +} 1.41 + 1.42 +namespace android { 1.43 + 1.44 +// The user of GonkNativeWindow who wants to receive notification of 1.45 +// new frames should implement this interface. 1.46 +class GonkNativeWindowNewFrameCallback { 1.47 +public: 1.48 + virtual void OnNewFrame() = 0; 1.49 +}; 1.50 + 1.51 +/** 1.52 + * GonkNativeWindow is a GonkBufferQueue consumer endpoint that allows clients 1.53 + * access to the whole BufferItem entry from GonkBufferQueue. Multiple buffers may 1.54 + * be acquired at once, to be used concurrently by the client. This consumer can 1.55 + * operate either in synchronous or asynchronous mode. 1.56 + */ 1.57 +class GonkNativeWindow: public GonkConsumerBase 1.58 +{ 1.59 + typedef mozilla::layers::TextureClient TextureClient; 1.60 + public: 1.61 + typedef GonkConsumerBase::FrameAvailableListener FrameAvailableListener; 1.62 + typedef IGonkGraphicBufferConsumer::BufferItem BufferItem; 1.63 + 1.64 + enum { INVALID_BUFFER_SLOT = GonkBufferQueue::INVALID_BUFFER_SLOT }; 1.65 + enum { NO_BUFFER_AVAILABLE = GonkBufferQueue::NO_BUFFER_AVAILABLE }; 1.66 + 1.67 + // Create a new buffer item consumer. The consumerUsage parameter determines 1.68 + // the consumer usage flags passed to the graphics allocator. The 1.69 + // bufferCount parameter specifies how many buffers can be locked for user 1.70 + // access at the same time. 1.71 + // controlledByApp tells whether this consumer is controlled by the 1.72 + // application. 1.73 + GonkNativeWindow(); 1.74 + GonkNativeWindow(const sp<GonkBufferQueue>& bq, uint32_t consumerUsage, 1.75 + int bufferCount = GonkBufferQueue::MIN_UNDEQUEUED_BUFFERS, 1.76 + bool controlledByApp = false); 1.77 + 1.78 + virtual ~GonkNativeWindow(); 1.79 + 1.80 + // set the name of the GonkNativeWindow that will be used to identify it in 1.81 + // log messages. 1.82 + void setName(const String8& name); 1.83 + 1.84 + // Gets the next graphics buffer from the producer, filling out the 1.85 + // passed-in BufferItem structure. Returns NO_BUFFER_AVAILABLE if the queue 1.86 + // of buffers is empty, and INVALID_OPERATION if the maximum number of 1.87 + // buffers is already acquired. 1.88 + // 1.89 + // Only a fixed number of buffers can be acquired at a time, determined by 1.90 + // the construction-time bufferCount parameter. If INVALID_OPERATION is 1.91 + // returned by acquireBuffer, then old buffers must be returned to the 1.92 + // queue by calling releaseBuffer before more buffers can be acquired. 1.93 + // 1.94 + // If waitForFence is true, and the acquired BufferItem has a valid fence object, 1.95 + // acquireBuffer will wait on the fence with no timeout before returning. 1.96 + status_t acquireBuffer(BufferItem *item, nsecs_t presentWhen, 1.97 + bool waitForFence = true); 1.98 + 1.99 + // Returns an acquired buffer to the queue, allowing it to be reused. Since 1.100 + // only a fixed number of buffers may be acquired at a time, old buffers 1.101 + // must be released by calling releaseBuffer to ensure new buffers can be 1.102 + // acquired by acquireBuffer. Once a BufferItem is released, the caller must 1.103 + // not access any members of the BufferItem, and should immediately remove 1.104 + // all of its references to the BufferItem itself. 1.105 + status_t releaseBuffer(const BufferItem &item, 1.106 + const sp<Fence>& releaseFence = Fence::NO_FENCE); 1.107 + 1.108 + // setDefaultBufferSize is used to set the size of buffers returned by 1.109 + // requestBuffers when a with and height of zero is requested. 1.110 + status_t setDefaultBufferSize(uint32_t w, uint32_t h); 1.111 + 1.112 + // setDefaultBufferFormat allows the BufferQueue to create 1.113 + // GraphicBuffers of a defaultFormat if no format is specified 1.114 + // in dequeueBuffer 1.115 + status_t setDefaultBufferFormat(uint32_t defaultFormat); 1.116 + 1.117 + // Get next frame from the queue, caller owns the returned buffer. 1.118 + mozilla::TemporaryRef<TextureClient> getCurrentBuffer(); 1.119 + 1.120 + // Return the buffer to the queue and mark it as FREE. After that 1.121 + // the buffer is useable again for the decoder. 1.122 + void returnBuffer(TextureClient* client); 1.123 + 1.124 + mozilla::TemporaryRef<TextureClient> getTextureClientFromBuffer(ANativeWindowBuffer* buffer); 1.125 + 1.126 + void setNewFrameCallback(GonkNativeWindowNewFrameCallback* callback); 1.127 + 1.128 + static void RecycleCallback(TextureClient* client, void* closure); 1.129 + 1.130 +protected: 1.131 + virtual void onFrameAvailable(); 1.132 + 1.133 +private: 1.134 + GonkNativeWindowNewFrameCallback* mNewFrameCallback; 1.135 +}; 1.136 + 1.137 +} // namespace android 1.138 + 1.139 +#endif // NATIVEWINDOW_GONKNATIVEWINDOW_JB_H