Steve Kondik | 6f9ab85 | 2017-07-09 21:30:20 -0700 | [diff] [blame] | 1 | // |
| 2 | // vncflinger - Copyright (C) 2017 Steve Kondik |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | // |
| 17 | |
| 18 | #ifndef ANDROID_PIXEL_BUFFER_H |
| 19 | #define ANDROID_PIXEL_BUFFER_H |
| 20 | |
| 21 | #include <utils/Mutex.h> |
| 22 | #include <utils/RefBase.h> |
| 23 | |
maxwen | ad0a922 | 2020-09-20 14:40:41 +0200 | [diff] [blame^] | 24 | #include <ui/DisplayConfig.h> |
Steve Kondik | 6f9ab85 | 2017-07-09 21:30:20 -0700 | [diff] [blame] | 25 | #include <ui/DisplayInfo.h> |
maxwen | ad0a922 | 2020-09-20 14:40:41 +0200 | [diff] [blame^] | 26 | #include <ui/DisplayState.h> |
Steve Kondik | 6f9ab85 | 2017-07-09 21:30:20 -0700 | [diff] [blame] | 27 | #include <ui/Rect.h> |
| 28 | |
| 29 | #include <rfb/PixelBuffer.h> |
| 30 | #include <rfb/PixelFormat.h> |
| 31 | |
| 32 | using namespace android; |
| 33 | |
| 34 | namespace vncflinger { |
| 35 | |
| 36 | class AndroidPixelBuffer : public RefBase, public rfb::ManagedPixelBuffer { |
| 37 | public: |
| 38 | AndroidPixelBuffer(); |
| 39 | |
maxwen | ad0a922 | 2020-09-20 14:40:41 +0200 | [diff] [blame^] | 40 | virtual void setDisplayInfo(DisplayConfig* config, ui::DisplayState* state); |
Steve Kondik | 6f9ab85 | 2017-07-09 21:30:20 -0700 | [diff] [blame] | 41 | |
| 42 | virtual void setWindowSize(uint32_t width, uint32_t height); |
| 43 | |
| 44 | virtual ~AndroidPixelBuffer(); |
| 45 | |
| 46 | class BufferDimensionsListener { |
| 47 | public: |
| 48 | virtual void onBufferDimensionsChanged(uint32_t width, uint32_t height) = 0; |
| 49 | virtual ~BufferDimensionsListener() { |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | void setDimensionsChangedListener(BufferDimensionsListener* listener) { |
| 54 | mListener = listener; |
| 55 | } |
| 56 | |
| 57 | bool isRotated() { |
| 58 | return mRotated; |
| 59 | } |
| 60 | |
| 61 | Rect getSourceRect(); |
| 62 | |
maxwen | 95dceef | 2019-12-07 12:00:17 +0100 | [diff] [blame] | 63 | void reset(); |
| 64 | |
Steve Kondik | 6f9ab85 | 2017-07-09 21:30:20 -0700 | [diff] [blame] | 65 | private: |
maxwen | ad0a922 | 2020-09-20 14:40:41 +0200 | [diff] [blame^] | 66 | static bool isDisplayRotated(ui::Rotation orientation); |
Steve Kondik | 6f9ab85 | 2017-07-09 21:30:20 -0700 | [diff] [blame] | 67 | |
| 68 | virtual void setBufferRotation(bool rotated); |
| 69 | |
| 70 | virtual void updateBufferSize(bool fromDisplay = false); |
| 71 | |
| 72 | Mutex mLock; |
| 73 | |
| 74 | // width/height is swapped due to display orientation |
| 75 | bool mRotated; |
| 76 | |
| 77 | // preferred size of the client's window |
| 78 | uint32_t mClientWidth, mClientHeight; |
| 79 | |
| 80 | // size of the display |
| 81 | uint32_t mSourceWidth, mSourceHeight; |
| 82 | |
| 83 | // current ratio between server and client |
| 84 | float mScaleX, mScaleY; |
| 85 | |
| 86 | // callback when buffer size changes |
| 87 | BufferDimensionsListener* mListener; |
| 88 | |
| 89 | // Android virtual display is always 32-bit |
| 90 | static const rfb::PixelFormat sRGBX; |
| 91 | }; |
| 92 | }; |
| 93 | |
| 94 | #endif |