1 /* 2 * Copyright 2013 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 #pragma once 18 19 #include <cinttypes> 20 21 #include <ui/Size.h> 22 #include <utils/Errors.h> 23 #include <utils/RefBase.h> 24 #include <utils/StrongPointer.h> 25 26 namespace android { 27 28 class Fence; 29 class IGraphicBufferProducer; 30 class String8; 31 32 namespace compositionengine { 33 34 /** 35 * An abstraction for working with a display surface (buffer queue) 36 */ 37 class DisplaySurface : public virtual RefBase { 38 public: 39 virtual ~DisplaySurface(); 40 41 // beginFrame is called at the beginning of the composition loop, before 42 // the configuration is known. The DisplaySurface should do anything it 43 // needs to do to enable HWComposer to decide how to compose the frame. 44 // We pass in mustRecompose so we can keep VirtualDisplaySurface's state 45 // machine happy without actually queueing a buffer if nothing has changed. 46 virtual status_t beginFrame(bool mustRecompose) = 0; 47 48 // prepareFrame is called after the composition configuration is known but 49 // before composition takes place. The DisplaySurface can use the 50 // composition type to decide how to manage the flow of buffers between 51 // GPU and HWC for this frame. 52 enum class CompositionType : uint8_t { Unknown = 0, Gpu = 0b1, Hwc = 0b10, Mixed = Gpu | Hwc }; 53 virtual status_t prepareFrame(CompositionType) = 0; 54 55 // Inform the surface that GPU composition is complete for this frame, and 56 // the surface should make sure that HWComposer has the correct buffer for 57 // this frame. Some implementations may only push a new buffer to 58 // HWComposer if GPU composition took place, others need to push a new 59 // buffer on every frame. 60 // 61 // advanceFrame must be followed by a call to onFrameCommitted before 62 // advanceFrame may be called again. 63 virtual status_t advanceFrame(float hdrSdrRatio) = 0; 64 65 // onFrameCommitted is called after the frame has been committed to the 66 // hardware composer. The surface collects the release fence for this 67 // frame's buffer. 68 virtual void onFrameCommitted() = 0; 69 70 virtual void dumpAsString(String8& result) const = 0; 71 72 virtual void resizeBuffers(const ui::Size&) = 0; 73 74 virtual const sp<Fence>& getClientTargetAcquireFence() const = 0; 75 76 // Returns true if the render surface supports client composition prediction. 77 virtual bool supportsCompositionStrategyPrediction() const; 78 }; 79 80 } // namespace compositionengine 81 } // namespace android 82