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 <compositionengine/DisplaySurface.h>
     24 #include <compositionengine/impl/HwcBufferCache.h>
     25 #include <gui/ConsumerBase.h>
     26 
     27 #include "DisplayIdentification.h"
     28 
     29 // ---------------------------------------------------------------------------
     30 namespace android {
     31 // ---------------------------------------------------------------------------
     32 
     33 class Rect;
     34 class String8;
     35 class HWComposer;
     36 
     37 // ---------------------------------------------------------------------------
     38 
     39 class FramebufferSurface : public ConsumerBase, public compositionengine::DisplaySurface {
     40 public:
     41     FramebufferSurface(HWComposer& hwc, DisplayId displayId,
     42                        const sp<IGraphicBufferConsumer>& consumer);
     43 
     44     virtual status_t beginFrame(bool mustRecompose);
     45     virtual status_t prepareFrame(CompositionType compositionType);
     46     virtual status_t advanceFrame();
     47     virtual void onFrameCommitted();
     48     virtual void dumpAsString(String8& result) const;
     49 
     50     virtual void resizeBuffers(const uint32_t width, const uint32_t height);
     51 
     52     virtual const sp<Fence>& getClientTargetAcquireFence() const override;
     53 
     54 private:
     55     virtual ~FramebufferSurface() { }; // this class cannot be overloaded
     56 
     57     virtual void freeBufferLocked(int slotIndex);
     58 
     59     virtual void dumpLocked(String8& result, const char* prefix) const;
     60 
     61     // nextBuffer waits for and then latches the next buffer from the
     62     // BufferQueue and releases the previously latched buffer to the
     63     // BufferQueue.  The new buffer is returned in the 'buffer' argument.
     64     status_t nextBuffer(uint32_t& outSlot, sp<GraphicBuffer>& outBuffer,
     65             sp<Fence>& outFence, ui::Dataspace& outDataspace);
     66 
     67     const DisplayId mDisplayId;
     68 
     69     // mCurrentBufferIndex is the slot index of the current buffer or
     70     // INVALID_BUFFER_SLOT to indicate that either there is no current buffer
     71     // or the buffer is not associated with a slot.
     72     int mCurrentBufferSlot;
     73 
     74     // mDataSpace is the dataspace of the current composition buffer for
     75     // this FramebufferSurface. It will be 0 when HWC is doing the
     76     // compositing. Otherwise it will display the dataspace of the buffer
     77     // use for compositing which can change as wide-color content is
     78     // on/off.
     79     ui::Dataspace mDataSpace;
     80 
     81     // mCurrentBuffer is the current buffer or nullptr to indicate that there is
     82     // no current buffer.
     83     sp<GraphicBuffer> mCurrentBuffer;
     84 
     85     // mCurrentFence is the current buffer's acquire fence
     86     sp<Fence> mCurrentFence;
     87 
     88     // Hardware composer, owned by SurfaceFlinger.
     89     HWComposer& mHwc;
     90 
     91     compositionengine::impl::HwcBufferCache mHwcBufferCache;
     92 
     93     // Previous buffer to release after getting an updated retire fence
     94     bool mHasPendingRelease;
     95     int mPreviousBufferSlot;
     96     sp<GraphicBuffer> mPreviousBuffer;
     97 };
     98 
     99 // ---------------------------------------------------------------------------
    100 }; // namespace android
    101 // ---------------------------------------------------------------------------
    102 
    103 #endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H
    104 
    105