| Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 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 |  | 
| Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 20 | #include "DisplaySurface.h" | 
| Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 21 | #include "HWComposerBufferCache.h" | 
| Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 22 |  | 
| Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 23 | #include <stdint.h> | 
|  | 24 | #include <sys/types.h> | 
|  | 25 |  | 
| Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 26 | #include <gui/ConsumerBase.h> | 
| Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 27 |  | 
| Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 28 | // --------------------------------------------------------------------------- | 
|  | 29 | namespace android { | 
|  | 30 | // --------------------------------------------------------------------------- | 
|  | 31 |  | 
|  | 32 | class Rect; | 
|  | 33 | class String8; | 
| Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 34 | class HWComposer; | 
| Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 35 |  | 
|  | 36 | // --------------------------------------------------------------------------- | 
|  | 37 |  | 
| Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 38 | class FramebufferSurface : public ConsumerBase, | 
|  | 39 | public DisplaySurface { | 
| Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 40 | public: | 
| Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 41 | FramebufferSurface(HWComposer& hwc, int disp, const sp<IGraphicBufferConsumer>& consumer); | 
| Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 42 |  | 
| Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 43 | virtual status_t beginFrame(bool mustRecompose); | 
| Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 44 | virtual status_t prepareFrame(CompositionType compositionType); | 
| Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 45 | #ifndef USE_HWC2 | 
|  | 46 | virtual status_t compositionComplete(); | 
|  | 47 | #endif | 
| Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 48 | virtual status_t advanceFrame(); | 
| Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 49 | virtual void onFrameCommitted(); | 
| Dan Stoza | f10c46e | 2014-11-11 10:32:31 -0800 | [diff] [blame] | 50 | virtual void dumpAsString(String8& result) const; | 
| Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 51 |  | 
| Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 52 | // Cannot resize a buffers in a FramebufferSurface. Only works with virtual | 
|  | 53 | // displays. | 
|  | 54 | virtual void resizeBuffers(const uint32_t /*w*/, const uint32_t /*h*/) { }; | 
|  | 55 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 56 | virtual const sp<Fence>& getClientTargetAcquireFence() const override; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 57 |  | 
| Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 58 | private: | 
| Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 59 | virtual ~FramebufferSurface() { }; // this class cannot be overloaded | 
| Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 60 |  | 
| Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 61 | #ifndef USE_HWC2 | 
|  | 62 | virtual void onFrameAvailable(const BufferItem& item); | 
|  | 63 | #endif | 
| Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 64 | virtual void freeBufferLocked(int slotIndex); | 
| Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 65 |  | 
| Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 66 | virtual void dumpLocked(String8& result, const char* prefix) const; | 
| Jesse Hall | 7adb0f8 | 2013-03-06 16:13:49 -0800 | [diff] [blame] | 67 |  | 
| Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 68 | // nextBuffer waits for and then latches the next buffer from the | 
|  | 69 | // BufferQueue and releases the previously latched buffer to the | 
|  | 70 | // BufferQueue.  The new buffer is returned in the 'buffer' argument. | 
| Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 71 | #ifdef USE_HWC2 | 
| Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 72 | status_t nextBuffer(uint32_t& outSlot, sp<GraphicBuffer>& outBuffer, | 
|  | 73 | sp<Fence>& outFence, android_dataspace_t& outDataspace); | 
| Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 74 | #else | 
|  | 75 | status_t nextBuffer(sp<GraphicBuffer>& outBuffer, sp<Fence>& outFence); | 
|  | 76 | #endif | 
| Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 77 |  | 
| Mathias Agopian | f5a3392 | 2012-09-19 18:16:22 -0700 | [diff] [blame] | 78 | // mDisplayType must match one of the HWC display types | 
|  | 79 | int mDisplayType; | 
|  | 80 |  | 
| Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 81 | // mCurrentBufferIndex is the slot index of the current buffer or | 
|  | 82 | // INVALID_BUFFER_SLOT to indicate that either there is no current buffer | 
|  | 83 | // or the buffer is not associated with a slot. | 
|  | 84 | int mCurrentBufferSlot; | 
| Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 85 |  | 
| Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 86 | // mCurrentBuffer is the current buffer or NULL to indicate that there is | 
|  | 87 | // no current buffer. | 
|  | 88 | sp<GraphicBuffer> mCurrentBuffer; | 
| Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 89 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 90 | // mCurrentFence is the current buffer's acquire fence | 
|  | 91 | sp<Fence> mCurrentFence; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 92 |  | 
| Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 93 | // Hardware composer, owned by SurfaceFlinger. | 
|  | 94 | HWComposer& mHwc; | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 95 |  | 
| Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 96 | #ifdef USE_HWC2 | 
| Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 97 | HWComposerBufferCache mHwcBufferCache; | 
| Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 98 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 99 | // Previous buffer to release after getting an updated retire fence | 
|  | 100 | bool mHasPendingRelease; | 
|  | 101 | int mPreviousBufferSlot; | 
|  | 102 | sp<GraphicBuffer> mPreviousBuffer; | 
| Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 103 | #endif | 
| Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 104 | }; | 
|  | 105 |  | 
|  | 106 | // --------------------------------------------------------------------------- | 
|  | 107 | }; // namespace android | 
|  | 108 | // --------------------------------------------------------------------------- | 
|  | 109 |  | 
|  | 110 | #endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H | 
|  | 111 |  |