blob: 174665fe66b95caa1551d17eb322599907a563f1 [file] [log] [blame]
Steve Kondik6f9ab852017-07-09 21:30:20 -07001//
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
maxwenad0a9222020-09-20 14:40:41 +020024#include <ui/DisplayConfig.h>
Steve Kondik6f9ab852017-07-09 21:30:20 -070025#include <ui/DisplayInfo.h>
maxwenad0a9222020-09-20 14:40:41 +020026#include <ui/DisplayState.h>
Steve Kondik6f9ab852017-07-09 21:30:20 -070027#include <ui/Rect.h>
28
29#include <rfb/PixelBuffer.h>
30#include <rfb/PixelFormat.h>
31
32using namespace android;
33
34namespace vncflinger {
35
36class AndroidPixelBuffer : public RefBase, public rfb::ManagedPixelBuffer {
37 public:
38 AndroidPixelBuffer();
39
maxwenad0a9222020-09-20 14:40:41 +020040 virtual void setDisplayInfo(DisplayConfig* config, ui::DisplayState* state);
Steve Kondik6f9ab852017-07-09 21:30:20 -070041
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
maxwen95dceef2019-12-07 12:00:17 +010063 void reset();
64
Steve Kondik6f9ab852017-07-09 21:30:20 -070065 private:
maxwenad0a9222020-09-20 14:40:41 +020066 static bool isDisplayRotated(ui::Rotation orientation);
Steve Kondik6f9ab852017-07-09 21:30:20 -070067
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