Home | History | Annotate | Download | only in DisplayHardware
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef ANDROID_SF_FRAMEBUFFER_SURFACE_H
     18 #define ANDROID_SF_FRAMEBUFFER_SURFACE_H
     19 
     20 #include <stdint.h>
     21 #include <sys/types.h>
     22 
     23 #include <gui/ConsumerBase.h>
     24 
     25 #include "DisplaySurface.h"
     26 
     27 // ---------------------------------------------------------------------------
     28 namespace android {
     29 // ---------------------------------------------------------------------------
     30 
     31 class Rect;
     32 class String8;
     33 class HWComposer;
     34 
     35 // ---------------------------------------------------------------------------
     36 
     37 class FramebufferSurface : public ConsumerBase,
     38                            public DisplaySurface {
     39 public:
     40     FramebufferSurface(HWComposer& hwc, int disp, const sp<IGraphicBufferConsumer>& consumer);
     41 
     42     virtual status_t beginFrame(bool mustRecompose);
     43     virtual status_t prepareFrame(CompositionType compositionType);
     44     virtual status_t compositionComplete();
     45     virtual status_t advanceFrame();
     46     virtual void onFrameCommitted();
     47 
     48     // Implementation of DisplaySurface::dump(). Note that ConsumerBase also
     49     // has a non-virtual dump() with the same signature.
     50     virtual void dump(String8& result) const;
     51 
     52     // Cannot resize a buffers in a FramebufferSurface. Only works with virtual
     53     // displays.
     54     virtual void resizeBuffers(const uint32_t /*w*/, const uint32_t /*h*/) { };
     55 
     56 private:
     57     virtual ~FramebufferSurface() { }; // this class cannot be overloaded
     58 
     59     virtual void onFrameAvailable(const BufferItem& item);
     60     virtual void freeBufferLocked(int slotIndex);
     61 
     62     virtual void dumpLocked(String8& result, const char* prefix) const;
     63 
     64     // nextBuffer waits for and then latches the next buffer from the
     65     // BufferQueue and releases the previously latched buffer to the
     66     // BufferQueue.  The new buffer is returned in the 'buffer' argument.
     67     status_t nextBuffer(sp<GraphicBuffer>& outBuffer, sp<Fence>& outFence);
     68 
     69     // mDisplayType must match one of the HWC display types
     70     int mDisplayType;
     71 
     72     // mCurrentBufferIndex is the slot index of the current buffer or
     73     // INVALID_BUFFER_SLOT to indicate that either there is no current buffer
     74     // or the buffer is not associated with a slot.
     75     int mCurrentBufferSlot;
     76 
     77     // mCurrentBuffer is the current buffer or NULL to indicate that there is
     78     // no current buffer.
     79     sp<GraphicBuffer> mCurrentBuffer;
     80 
     81     // Hardware composer, owned by SurfaceFlinger.
     82     HWComposer& mHwc;
     83 };
     84 
     85 // ---------------------------------------------------------------------------
     86 }; // namespace android
     87 // ---------------------------------------------------------------------------
     88 
     89 #endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H
     90 
     91