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