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