widget/gonk/nativewindow/GonkNativeWindowJB.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rwxr-xr-x

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 * Copyright (C) 2012 The Android Open Source Project
michael@0 3 * Copyright (C) 2013 Mozilla Foundation
michael@0 4 *
michael@0 5 * Licensed under the Apache License, Version 2.0 (the "License");
michael@0 6 * you may not use this file except in compliance with the License.
michael@0 7 * You may obtain a copy of the License at
michael@0 8 *
michael@0 9 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 10 *
michael@0 11 * Unless required by applicable law or agreed to in writing, software
michael@0 12 * distributed under the License is distributed on an "AS IS" BASIS,
michael@0 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
michael@0 14 * See the License for the specific language governing permissions and
michael@0 15 * limitations under the License.
michael@0 16 */
michael@0 17
michael@0 18 #ifndef NATIVEWINDOW_GONKNATIVEWINDOW_JB_H
michael@0 19 #define NATIVEWINDOW_GONKNATIVEWINDOW_JB_H
michael@0 20
michael@0 21 #include <ui/GraphicBuffer.h>
michael@0 22 #include <utils/String8.h>
michael@0 23 #include <utils/Vector.h>
michael@0 24 #include <utils/threads.h>
michael@0 25
michael@0 26 #include "CameraCommon.h"
michael@0 27 #include "GonkConsumerBaseJB.h"
michael@0 28 #include "GrallocImages.h"
michael@0 29 #include "mozilla/layers/LayersSurfaces.h"
michael@0 30
michael@0 31 namespace mozilla {
michael@0 32 namespace layers {
michael@0 33 class PGrallocBufferChild;
michael@0 34 }
michael@0 35 }
michael@0 36
michael@0 37 namespace android {
michael@0 38
michael@0 39 // The user of GonkNativeWindow who wants to receive notification of
michael@0 40 // new frames should implement this interface.
michael@0 41 class GonkNativeWindowNewFrameCallback {
michael@0 42 public:
michael@0 43 virtual void OnNewFrame() = 0;
michael@0 44 };
michael@0 45
michael@0 46 /**
michael@0 47 * GonkNativeWindow is a GonkBufferQueue consumer endpoint that allows clients
michael@0 48 * access to the whole BufferItem entry from GonkBufferQueue. Multiple buffers may
michael@0 49 * be acquired at once, to be used concurrently by the client. This consumer can
michael@0 50 * operate either in synchronous or asynchronous mode.
michael@0 51 */
michael@0 52 class GonkNativeWindow: public GonkConsumerBase
michael@0 53 {
michael@0 54 typedef mozilla::layers::TextureClient TextureClient;
michael@0 55 public:
michael@0 56 typedef GonkConsumerBase::FrameAvailableListener FrameAvailableListener;
michael@0 57
michael@0 58 typedef GonkBufferQueue::BufferItem BufferItem;
michael@0 59
michael@0 60 enum { INVALID_BUFFER_SLOT = GonkBufferQueue::INVALID_BUFFER_SLOT };
michael@0 61 enum { NO_BUFFER_AVAILABLE = GonkBufferQueue::NO_BUFFER_AVAILABLE };
michael@0 62
michael@0 63 // Create a new buffer item consumer. The consumerUsage parameter determines
michael@0 64 // the consumer usage flags passed to the graphics allocator. The
michael@0 65 // bufferCount parameter specifies how many buffers can be locked for user
michael@0 66 // access at the same time.
michael@0 67 GonkNativeWindow();
michael@0 68
michael@0 69 virtual ~GonkNativeWindow();
michael@0 70
michael@0 71 // set the name of the GonkNativeWindow that will be used to identify it in
michael@0 72 // log messages.
michael@0 73 void setName(const String8& name);
michael@0 74
michael@0 75 // Gets the next graphics buffer from the producer, filling out the
michael@0 76 // passed-in BufferItem structure. Returns NO_BUFFER_AVAILABLE if the queue
michael@0 77 // of buffers is empty, and INVALID_OPERATION if the maximum number of
michael@0 78 // buffers is already acquired.
michael@0 79 //
michael@0 80 // Only a fixed number of buffers can be acquired at a time, determined by
michael@0 81 // the construction-time bufferCount parameter. If INVALID_OPERATION is
michael@0 82 // returned by acquireBuffer, then old buffers must be returned to the
michael@0 83 // queue by calling releaseBuffer before more buffers can be acquired.
michael@0 84 //
michael@0 85 // If waitForFence is true, and the acquired BufferItem has a valid fence object,
michael@0 86 // acquireBuffer will wait on the fence with no timeout before returning.
michael@0 87 #if ANDROID_VERSION >= 18
michael@0 88 status_t acquireBuffer(BufferItem *item, bool waitForFence = true);
michael@0 89 #endif
michael@0 90 // Returns an acquired buffer to the queue, allowing it to be reused. Since
michael@0 91 // only a fixed number of buffers may be acquired at a time, old buffers
michael@0 92 // must be released by calling releaseBuffer to ensure new buffers can be
michael@0 93 // acquired by acquireBuffer. Once a BufferItem is released, the caller must
michael@0 94 // not access any members of the BufferItem, and should immediately remove
michael@0 95 // all of its references to the BufferItem itself.
michael@0 96 #if ANDROID_VERSION >= 18
michael@0 97 status_t releaseBuffer(const BufferItem &item,
michael@0 98 const sp<Fence>& releaseFence = Fence::NO_FENCE);
michael@0 99 #endif
michael@0 100
michael@0 101 sp<IGraphicBufferProducer> getProducerInterface() const { return getBufferQueue(); }
michael@0 102
michael@0 103 // setDefaultBufferSize is used to set the size of buffers returned by
michael@0 104 // requestBuffers when a with and height of zero is requested.
michael@0 105 status_t setDefaultBufferSize(uint32_t w, uint32_t h);
michael@0 106
michael@0 107 // setDefaultBufferFormat allows the BufferQueue to create
michael@0 108 // GraphicBuffers of a defaultFormat if no format is specified
michael@0 109 // in dequeueBuffer
michael@0 110 status_t setDefaultBufferFormat(uint32_t defaultFormat);
michael@0 111
michael@0 112 // Get next frame from the queue, caller owns the returned buffer.
michael@0 113 mozilla::TemporaryRef<TextureClient> getCurrentBuffer();
michael@0 114
michael@0 115 // Return the buffer to the queue and mark it as FREE. After that
michael@0 116 // the buffer is useable again for the decoder.
michael@0 117 void returnBuffer(TextureClient* client);
michael@0 118
michael@0 119 mozilla::TemporaryRef<TextureClient> getTextureClientFromBuffer(ANativeWindowBuffer* buffer);
michael@0 120
michael@0 121 void setNewFrameCallback(GonkNativeWindowNewFrameCallback* callback);
michael@0 122
michael@0 123 static void RecycleCallback(TextureClient* client, void* closure);
michael@0 124
michael@0 125 protected:
michael@0 126 virtual void onFrameAvailable();
michael@0 127
michael@0 128 private:
michael@0 129 GonkNativeWindowNewFrameCallback* mNewFrameCallback;
michael@0 130 };
michael@0 131
michael@0 132 } // namespace android
michael@0 133
michael@0 134 #endif // NATIVEWINDOW_GONKNATIVEWINDOW_JB_H

mercurial