widget/gonk/nativewindow/GonkNativeWindowClientKK.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/gonk/nativewindow/GonkNativeWindowClientKK.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,263 @@
     1.4 +/*
     1.5 + * Copyright (C) 2010 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_GONKNATIVEWINDOWCLIENT_KK_H
    1.22 +#define NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_KK_H
    1.23 +
    1.24 +#include <gui/IGraphicBufferProducer.h>
    1.25 +
    1.26 +#include <ui/ANativeObjectBase.h>
    1.27 +#include <ui/Region.h>
    1.28 +
    1.29 +#include <utils/RefBase.h>
    1.30 +#include <utils/threads.h>
    1.31 +#include <utils/KeyedVector.h>
    1.32 +
    1.33 +#include "GonkBufferQueue.h"
    1.34 +
    1.35 +struct ANativeWindow_Buffer;
    1.36 +
    1.37 +namespace android {
    1.38 +
    1.39 +/*
    1.40 + * An implementation of ANativeWindow that feeds graphics buffers into a
    1.41 + * BufferQueue.
    1.42 + *
    1.43 + * This is typically used by programs that want to render frames through
    1.44 + * some means (maybe OpenGL, a software renderer, or a hardware decoder)
    1.45 + * and have the frames they create forwarded to SurfaceFlinger for
    1.46 + * compositing.  For example, a video decoder could render a frame and call
    1.47 + * eglSwapBuffers(), which invokes ANativeWindow callbacks defined by
    1.48 + * GonkNativeWindowClient.  GonkNativeWindowClient then forwards the buffers through Binder IPC
    1.49 + * to the BufferQueue's producer interface, providing the new frame to a
    1.50 + * consumer such as GLConsumer.
    1.51 + */
    1.52 +class GonkNativeWindowClient
    1.53 +    : public ANativeObjectBase<ANativeWindow, GonkNativeWindowClient, RefBase>
    1.54 +{
    1.55 +public:
    1.56 +
    1.57 +    /*
    1.58 +     * creates a GonkNativeWindowClient from the given IGraphicBufferProducer (which concrete
    1.59 +     * implementation is a BufferQueue).
    1.60 +     *
    1.61 +     * GonkNativeWindowClient is mainly state-less while it's disconnected, it can be
    1.62 +     * viewed as a glorified IGraphicBufferProducer holder. It's therefore
    1.63 +     * safe to create other GonkNativeWindowClients from the same IGraphicBufferProducer.
    1.64 +     *
    1.65 +     * However, once a GonkNativeWindowClient is connected, it'll prevent other GonkNativeWindowClients
    1.66 +     * referring to the same IGraphicBufferProducer to become connected and
    1.67 +     * therefore prevent them to be used as actual producers of buffers.
    1.68 +     *
    1.69 +     * the controlledByApp flag indicates that this Surface (producer) is
    1.70 +     * controlled by the application. This flag is used at connect time.
    1.71 +     */
    1.72 +    GonkNativeWindowClient(const sp<IGraphicBufferProducer>& bufferProducer, bool controlledByApp = false);
    1.73 +
    1.74 +    /* getIGraphicBufferProducer() returns the IGraphicBufferProducer this
    1.75 +     * GonkNativeWindowClient was created with. Usually it's an error to use the
    1.76 +     * IGraphicBufferProducer while the GonkNativeWindowClient is connected.
    1.77 +     */
    1.78 +    sp<IGraphicBufferProducer> getIGraphicBufferProducer() const;
    1.79 +
    1.80 +    /* convenience function to check that the given surface is non NULL as
    1.81 +     * well as its IGraphicBufferProducer */
    1.82 +    static bool isValid(const sp<GonkNativeWindowClient>& surface) {
    1.83 +        return surface != NULL && surface->getIGraphicBufferProducer() != NULL;
    1.84 +    }
    1.85 +
    1.86 +protected:
    1.87 +    virtual ~GonkNativeWindowClient();
    1.88 +
    1.89 +private:
    1.90 +    // can't be copied
    1.91 +    GonkNativeWindowClient& operator = (const GonkNativeWindowClient& rhs);
    1.92 +    GonkNativeWindowClient(const GonkNativeWindowClient& rhs);
    1.93 +
    1.94 +    // ANativeWindow hooks
    1.95 +    static int hook_cancelBuffer(ANativeWindow* window,
    1.96 +            ANativeWindowBuffer* buffer, int fenceFd);
    1.97 +    static int hook_dequeueBuffer(ANativeWindow* window,
    1.98 +            ANativeWindowBuffer** buffer, int* fenceFd);
    1.99 +    static int hook_perform(ANativeWindow* window, int operation, ...);
   1.100 +    static int hook_query(const ANativeWindow* window, int what, int* value);
   1.101 +    static int hook_queueBuffer(ANativeWindow* window,
   1.102 +            ANativeWindowBuffer* buffer, int fenceFd);
   1.103 +    static int hook_setSwapInterval(ANativeWindow* window, int interval);
   1.104 +
   1.105 +    static int hook_cancelBuffer_DEPRECATED(ANativeWindow* window,
   1.106 +            ANativeWindowBuffer* buffer);
   1.107 +    static int hook_dequeueBuffer_DEPRECATED(ANativeWindow* window,
   1.108 +            ANativeWindowBuffer** buffer);
   1.109 +    static int hook_lockBuffer_DEPRECATED(ANativeWindow* window,
   1.110 +            ANativeWindowBuffer* buffer);
   1.111 +    static int hook_queueBuffer_DEPRECATED(ANativeWindow* window,
   1.112 +            ANativeWindowBuffer* buffer);
   1.113 +
   1.114 +    int dispatchConnect(va_list args);
   1.115 +    int dispatchDisconnect(va_list args);
   1.116 +    int dispatchSetBufferCount(va_list args);
   1.117 +    int dispatchSetBuffersGeometry(va_list args);
   1.118 +    int dispatchSetBuffersDimensions(va_list args);
   1.119 +    int dispatchSetBuffersUserDimensions(va_list args);
   1.120 +    int dispatchSetBuffersFormat(va_list args);
   1.121 +    int dispatchSetScalingMode(va_list args);
   1.122 +    int dispatchSetBuffersTransform(va_list args);
   1.123 +    int dispatchSetBuffersTimestamp(va_list args);
   1.124 +    int dispatchSetCrop(va_list args);
   1.125 +    int dispatchSetPostTransformCrop(va_list args);
   1.126 +    int dispatchSetUsage(va_list args);
   1.127 +    int dispatchLock(va_list args);
   1.128 +    int dispatchUnlockAndPost(va_list args);
   1.129 +
   1.130 +protected:
   1.131 +    virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd);
   1.132 +    virtual int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd);
   1.133 +    virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd);
   1.134 +    virtual int perform(int operation, va_list args);
   1.135 +    virtual int query(int what, int* value) const;
   1.136 +    virtual int setSwapInterval(int interval);
   1.137 +
   1.138 +    virtual int lockBuffer_DEPRECATED(ANativeWindowBuffer* buffer);
   1.139 +
   1.140 +    virtual int connect(int api);
   1.141 +    virtual int disconnect(int api);
   1.142 +    virtual int setBufferCount(int bufferCount);
   1.143 +    virtual int setBuffersDimensions(int w, int h);
   1.144 +    virtual int setBuffersUserDimensions(int w, int h);
   1.145 +    virtual int setBuffersFormat(int format);
   1.146 +    virtual int setScalingMode(int mode);
   1.147 +    virtual int setBuffersTransform(int transform);
   1.148 +    virtual int setBuffersTimestamp(int64_t timestamp);
   1.149 +    virtual int setCrop(Rect const* rect);
   1.150 +    virtual int setUsage(uint32_t reqUsage);
   1.151 +
   1.152 +public:
   1.153 +    virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds);
   1.154 +    virtual int unlockAndPost();
   1.155 +
   1.156 +protected:
   1.157 +    enum { NUM_BUFFER_SLOTS = GonkBufferQueue::NUM_BUFFER_SLOTS };
   1.158 +    enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
   1.159 +
   1.160 +private:
   1.161 +    void freeAllBuffers();
   1.162 +    int getSlotFromBufferLocked(android_native_buffer_t* buffer) const;
   1.163 +
   1.164 +    struct BufferSlot {
   1.165 +        sp<GraphicBuffer> buffer;
   1.166 +        Region dirtyRegion;
   1.167 +    };
   1.168 +
   1.169 +    // mSurfaceTexture is the interface to the surface texture server. All
   1.170 +    // operations on the surface texture client ultimately translate into
   1.171 +    // interactions with the server using this interface.
   1.172 +    // TODO: rename to mBufferProducer
   1.173 +    sp<IGraphicBufferProducer> mGraphicBufferProducer;
   1.174 +
   1.175 +    // mSlots stores the buffers that have been allocated for each buffer slot.
   1.176 +    // It is initialized to null pointers, and gets filled in with the result of
   1.177 +    // IGraphicBufferProducer::requestBuffer when the client dequeues a buffer from a
   1.178 +    // slot that has not yet been used. The buffer allocated to a slot will also
   1.179 +    // be replaced if the requested buffer usage or geometry differs from that
   1.180 +    // of the buffer allocated to a slot.
   1.181 +    BufferSlot mSlots[NUM_BUFFER_SLOTS];
   1.182 +
   1.183 +    // mReqWidth is the buffer width that will be requested at the next dequeue
   1.184 +    // operation. It is initialized to 1.
   1.185 +    uint32_t mReqWidth;
   1.186 +
   1.187 +    // mReqHeight is the buffer height that will be requested at the next
   1.188 +    // dequeue operation. It is initialized to 1.
   1.189 +    uint32_t mReqHeight;
   1.190 +
   1.191 +    // mReqFormat is the buffer pixel format that will be requested at the next
   1.192 +    // deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888.
   1.193 +    uint32_t mReqFormat;
   1.194 +
   1.195 +    // mReqUsage is the set of buffer usage flags that will be requested
   1.196 +    // at the next deuque operation. It is initialized to 0.
   1.197 +    uint32_t mReqUsage;
   1.198 +
   1.199 +    // mTimestamp is the timestamp that will be used for the next buffer queue
   1.200 +    // operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that
   1.201 +    // a timestamp is auto-generated when queueBuffer is called.
   1.202 +    int64_t mTimestamp;
   1.203 +
   1.204 +    // mCrop is the crop rectangle that will be used for the next buffer
   1.205 +    // that gets queued. It is set by calling setCrop.
   1.206 +    Rect mCrop;
   1.207 +
   1.208 +    // mScalingMode is the scaling mode that will be used for the next
   1.209 +    // buffers that get queued. It is set by calling setScalingMode.
   1.210 +    int mScalingMode;
   1.211 +
   1.212 +    // mTransform is the transform identifier that will be used for the next
   1.213 +    // buffer that gets queued. It is set by calling setTransform.
   1.214 +    uint32_t mTransform;
   1.215 +
   1.216 +     // mDefaultWidth is default width of the buffers, regardless of the
   1.217 +     // native_window_set_buffers_dimensions call.
   1.218 +     uint32_t mDefaultWidth;
   1.219 +
   1.220 +     // mDefaultHeight is default height of the buffers, regardless of the
   1.221 +     // native_window_set_buffers_dimensions call.
   1.222 +     uint32_t mDefaultHeight;
   1.223 +
   1.224 +     // mUserWidth, if non-zero, is an application-specified override
   1.225 +     // of mDefaultWidth.  This is lower priority than the width set by
   1.226 +     // native_window_set_buffers_dimensions.
   1.227 +     uint32_t mUserWidth;
   1.228 +
   1.229 +     // mUserHeight, if non-zero, is an application-specified override
   1.230 +     // of mDefaultHeight.  This is lower priority than the height set
   1.231 +     // by native_window_set_buffers_dimensions.
   1.232 +     uint32_t mUserHeight;
   1.233 +
   1.234 +    // mTransformHint is the transform probably applied to buffers of this
   1.235 +    // window. this is only a hint, actual transform may differ.
   1.236 +    uint32_t mTransformHint;
   1.237 +
   1.238 +    // mProducerControlledByApp whether this buffer producer is controlled
   1.239 +    // by the application
   1.240 +    bool mProducerControlledByApp;
   1.241 +
   1.242 +    // mSwapIntervalZero set if we should drop buffers at queue() time to
   1.243 +    // achieve an asynchronous swap interval
   1.244 +    bool mSwapIntervalZero;
   1.245 +
   1.246 +    // mConsumerRunningBehind whether the consumer is running more than
   1.247 +    // one buffer behind the producer.
   1.248 +    mutable bool mConsumerRunningBehind;
   1.249 +
   1.250 +    // mMutex is the mutex used to prevent concurrent access to the member
   1.251 +    // variables of GonkNativeWindowClient objects. It must be locked whenever the
   1.252 +    // member variables are accessed.
   1.253 +    mutable Mutex mMutex;
   1.254 +
   1.255 +    // must be used from the lock/unlock thread
   1.256 +    sp<GraphicBuffer>           mLockedBuffer;
   1.257 +    sp<GraphicBuffer>           mPostedBuffer;
   1.258 +    bool                        mConnectedToCpu;
   1.259 +
   1.260 +    // must be accessed from lock/unlock thread only
   1.261 +    Region mDirtyRegion;
   1.262 +};
   1.263 +
   1.264 +}; // namespace android
   1.265 +
   1.266 +#endif  // NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_JB_H

mercurial