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 #ifndef ANDROID_SF_DISPLAY_SURFACE_H 18 #define ANDROID_SF_DISPLAY_SURFACE_H 19 20 #include <gui/ConsumerBase.h> 21 #include <system/window.h> 22 #include <utils/Errors.h> 23 #include <utils/RefBase.h> 24 #include <utils/StrongPointer.h> 25 26 // --------------------------------------------------------------------------- 27 namespace android { 28 // --------------------------------------------------------------------------- 29 30 class IGraphicBufferProducer; 31 class String8; 32 33 #if ANDROID_VERSION >= 21 34 typedef IGraphicBufferConsumer StreamConsumer; 35 #else 36 typedef BufferQueue StreamConsumer; 37 #endif 38 39 class DisplaySurface : public ConsumerBase { 40 public: 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 // GLES and HWC for this frame. 52 enum CompositionType { 53 COMPOSITION_UNKNOWN = 0, 54 COMPOSITION_GLES = 1, 55 COMPOSITION_HWC = 2, 56 COMPOSITION_MIXED = COMPOSITION_GLES | COMPOSITION_HWC 57 }; 58 virtual status_t prepareFrame(CompositionType compositionType) = 0; 59 60 // Should be called when composition rendering is complete for a frame (but 61 // eglSwapBuffers hasn't necessarily been called). Required by certain 62 // older drivers for synchronization. 63 // TODO: Remove this when we drop support for HWC 1.0. 64 virtual status_t compositionComplete() = 0; 65 66 // Inform the surface that GLES composition is complete for this frame, and 67 // the surface should make sure that HWComposer has the correct buffer for 68 // this frame. Some implementations may only push a new buffer to 69 // HWComposer if GLES composition took place, others need to push a new 70 // buffer on every frame. 71 // 72 // advanceFrame must be followed by a call to onFrameCommitted before 73 // advanceFrame may be called again. 74 virtual status_t advanceFrame() = 0; 75 76 // onFrameCommitted is called after the frame has been committed to the 77 // hardware composer. The surface collects the release fence for this 78 // frame's buffer. 79 virtual void onFrameCommitted() = 0; 80 81 virtual void resizeBuffers(const uint32_t w, const uint32_t h) = 0; 82 83 // setReleaseFenceFd stores a fence file descriptor that will signal when the 84 // current buffer is no longer being read. This fence will be returned to 85 // the producer when the current buffer is released by updateTexImage(). 86 // Multiple fences can be set for a given buffer; they will be merged into 87 // a single union fence. The SurfaceTexture will close the file descriptor 88 // when finished with it. 89 virtual status_t setReleaseFenceFd(int fenceFd) = 0; 90 91 virtual int GetPrevDispAcquireFd() = 0; 92 93 buffer_handle_t lastHandle; 94 95 protected: DisplaySurface(const sp<StreamConsumer> & sc)96 DisplaySurface(const sp<StreamConsumer>& sc) 97 #if ANDROID_VERSION >= 19 98 : ConsumerBase(sc, true) 99 #else 100 : ConsumerBase(sc) 101 #endif 102 , lastHandle(0) 103 { } ~DisplaySurface()104 virtual ~DisplaySurface() {} 105 }; 106 107 // --------------------------------------------------------------------------- 108 } // namespace android 109 // --------------------------------------------------------------------------- 110 111 #endif // ANDROID_SF_DISPLAY_SURFACE_H 112 113