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

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

mercurial