widget/gonk/nativewindow/GonkNativeWindowKK.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial