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