widget/gonk/nativewindow/GonkNativeWindowKK.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
-rw-r--r--

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_KK_H
michael@0 19 #define NATIVEWINDOW_GONKNATIVEWINDOW_KK_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 "GonkConsumerBaseKK.h"
michael@0 28 #include "GrallocImages.h"
michael@0 29 #include "IGonkGraphicBufferConsumer.h"
michael@0 30 #include "mozilla/layers/ImageBridgeChild.h"
michael@0 31 #include "mozilla/layers/LayersSurfaces.h"
michael@0 32
michael@0 33 namespace mozilla {
michael@0 34 namespace layers {
michael@0 35 class PGrallocBufferChild;
michael@0 36 }
michael@0 37 }
michael@0 38
michael@0 39 namespace android {
michael@0 40
michael@0 41 // The user of GonkNativeWindow who wants to receive notification of
michael@0 42 // new frames should implement this interface.
michael@0 43 class GonkNativeWindowNewFrameCallback {
michael@0 44 public:
michael@0 45 virtual void OnNewFrame() = 0;
michael@0 46 };
michael@0 47
michael@0 48 /**
michael@0 49 * GonkNativeWindow is a GonkBufferQueue consumer endpoint that allows clients
michael@0 50 * access to the whole BufferItem entry from GonkBufferQueue. Multiple buffers may
michael@0 51 * be acquired at once, to be used concurrently by the client. This consumer can
michael@0 52 * operate either in synchronous or asynchronous mode.
michael@0 53 */
michael@0 54 class GonkNativeWindow: public GonkConsumerBase
michael@0 55 {
michael@0 56 typedef mozilla::layers::TextureClient TextureClient;
michael@0 57 public:
michael@0 58 typedef GonkConsumerBase::FrameAvailableListener FrameAvailableListener;
michael@0 59 typedef IGonkGraphicBufferConsumer::BufferItem BufferItem;
michael@0 60
michael@0 61 enum { INVALID_BUFFER_SLOT = GonkBufferQueue::INVALID_BUFFER_SLOT };
michael@0 62 enum { NO_BUFFER_AVAILABLE = GonkBufferQueue::NO_BUFFER_AVAILABLE };
michael@0 63
michael@0 64 // Create a new buffer item consumer. The consumerUsage parameter determines
michael@0 65 // the consumer usage flags passed to the graphics allocator. The
michael@0 66 // bufferCount parameter specifies how many buffers can be locked for user
michael@0 67 // access at the same time.
michael@0 68 // controlledByApp tells whether this consumer is controlled by the
michael@0 69 // application.
michael@0 70 GonkNativeWindow();
michael@0 71 GonkNativeWindow(const sp<GonkBufferQueue>& bq, uint32_t consumerUsage,
michael@0 72 int bufferCount = GonkBufferQueue::MIN_UNDEQUEUED_BUFFERS,
michael@0 73 bool controlledByApp = false);
michael@0 74
michael@0 75 virtual ~GonkNativeWindow();
michael@0 76
michael@0 77 // set the name of the GonkNativeWindow that will be used to identify it in
michael@0 78 // log messages.
michael@0 79 void setName(const String8& name);
michael@0 80
michael@0 81 // Gets the next graphics buffer from the producer, filling out the
michael@0 82 // passed-in BufferItem structure. Returns NO_BUFFER_AVAILABLE if the queue
michael@0 83 // of buffers is empty, and INVALID_OPERATION if the maximum number of
michael@0 84 // buffers is already acquired.
michael@0 85 //
michael@0 86 // Only a fixed number of buffers can be acquired at a time, determined by
michael@0 87 // the construction-time bufferCount parameter. If INVALID_OPERATION is
michael@0 88 // returned by acquireBuffer, then old buffers must be returned to the
michael@0 89 // queue by calling releaseBuffer before more buffers can be acquired.
michael@0 90 //
michael@0 91 // If waitForFence is true, and the acquired BufferItem has a valid fence object,
michael@0 92 // acquireBuffer will wait on the fence with no timeout before returning.
michael@0 93 status_t acquireBuffer(BufferItem *item, nsecs_t presentWhen,
michael@0 94 bool waitForFence = true);
michael@0 95
michael@0 96 // Returns an acquired buffer to the queue, allowing it to be reused. Since
michael@0 97 // only a fixed number of buffers may be acquired at a time, old buffers
michael@0 98 // must be released by calling releaseBuffer to ensure new buffers can be
michael@0 99 // acquired by acquireBuffer. Once a BufferItem is released, the caller must
michael@0 100 // not access any members of the BufferItem, and should immediately remove
michael@0 101 // all of its references to the BufferItem itself.
michael@0 102 status_t releaseBuffer(const BufferItem &item,
michael@0 103 const sp<Fence>& releaseFence = Fence::NO_FENCE);
michael@0 104
michael@0 105 // setDefaultBufferSize is used to set the size of buffers returned by
michael@0 106 // requestBuffers when a with and height of zero is requested.
michael@0 107 status_t setDefaultBufferSize(uint32_t w, uint32_t h);
michael@0 108
michael@0 109 // setDefaultBufferFormat allows the BufferQueue to create
michael@0 110 // GraphicBuffers of a defaultFormat if no format is specified
michael@0 111 // in dequeueBuffer
michael@0 112 status_t setDefaultBufferFormat(uint32_t defaultFormat);
michael@0 113
michael@0 114 // Get next frame from the queue, caller owns the returned buffer.
michael@0 115 mozilla::TemporaryRef<TextureClient> getCurrentBuffer();
michael@0 116
michael@0 117 // Return the buffer to the queue and mark it as FREE. After that
michael@0 118 // the buffer is useable again for the decoder.
michael@0 119 void returnBuffer(TextureClient* client);
michael@0 120
michael@0 121 mozilla::TemporaryRef<TextureClient> getTextureClientFromBuffer(ANativeWindowBuffer* buffer);
michael@0 122
michael@0 123 void setNewFrameCallback(GonkNativeWindowNewFrameCallback* callback);
michael@0 124
michael@0 125 static void RecycleCallback(TextureClient* client, void* closure);
michael@0 126
michael@0 127 protected:
michael@0 128 virtual void onFrameAvailable();
michael@0 129
michael@0 130 private:
michael@0 131 GonkNativeWindowNewFrameCallback* mNewFrameCallback;
michael@0 132 };
michael@0 133
michael@0 134 } // namespace android
michael@0 135
michael@0 136 #endif // NATIVEWINDOW_GONKNATIVEWINDOW_JB_H

mercurial