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 <gui/BufferQueue.h> 25 #include <gui/ConsumerBase.h> 26 #include <ui/DisplayId.h> 27 #include <ui/Size.h> 28 29 #include <ui/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(float hdrSdrRatio); 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 const PhysicalDisplayId mDisplayId; 73 74 // Framebuffer size has a dimension limitation in pixels based on the graphics capabilities of 75 // the device. 76 const ui::Size mMaxSize; 77 78 // mCurrentBufferIndex is the slot index of the current buffer or 79 // INVALID_BUFFER_SLOT to indicate that either there is no current buffer 80 // or the buffer is not associated with a slot. 81 int mCurrentBufferSlot; 82 83 // mDataSpace is the dataspace of the current composition buffer for 84 // this FramebufferSurface. It will be 0 when HWC is doing the 85 // compositing. Otherwise it will display the dataspace of the buffer 86 // use for compositing which can change as wide-color content is 87 // on/off. 88 ui::Dataspace mDataspace; 89 90 // mCurrentBuffer is the current buffer or nullptr to indicate that there is 91 // no current buffer. 92 sp<GraphicBuffer> mCurrentBuffer; 93 94 // mCurrentFence is the current buffer's acquire fence 95 sp<Fence> mCurrentFence; 96 97 // Hardware composer, owned by SurfaceFlinger. 98 HWComposer& mHwc; 99 100 // Buffers that HWC has seen before, indexed by slot number. 101 // NOTE: The BufferQueue slot number is the same as the HWC slot number. 102 uint64_t mHwcBufferIds[BufferQueue::NUM_BUFFER_SLOTS]; 103 104 // Previous buffer to release after getting an updated retire fence 105 bool mHasPendingRelease; 106 int mPreviousBufferSlot; 107 sp<GraphicBuffer> mPreviousBuffer; 108 }; 109 110 // --------------------------------------------------------------------------- 111 }; // namespace android 112 // --------------------------------------------------------------------------- 113 114 #endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H 115 116