blob: 5cd314cc6b147845c9c72d4a4cb8aec5bcc6a6a9 [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
24#include <ui/DisplayInfo.h>
25#include <ui/Rect.h>
26
27#include <rfb/PixelBuffer.h>
28#include <rfb/PixelFormat.h>
29
30using namespace android;
31
32namespace vncflinger {
33
34class AndroidPixelBuffer : public RefBase, public rfb::ManagedPixelBuffer {
35 public:
36 AndroidPixelBuffer();
37
38 virtual void setDisplayInfo(DisplayInfo* info);
39
40 virtual void setWindowSize(uint32_t width, uint32_t height);
41
42 virtual ~AndroidPixelBuffer();
43
44 class BufferDimensionsListener {
45 public:
46 virtual void onBufferDimensionsChanged(uint32_t width, uint32_t height) = 0;
47 virtual ~BufferDimensionsListener() {
48 }
49 };
50
51 void setDimensionsChangedListener(BufferDimensionsListener* listener) {
52 mListener = listener;
53 }
54
55 bool isRotated() {
56 return mRotated;
57 }
58
59 Rect getSourceRect();
60
61 private:
62 static bool isDisplayRotated(uint8_t orientation);
63
64 virtual void setBufferRotation(bool rotated);
65
66 virtual void updateBufferSize(bool fromDisplay = false);
67
68 Mutex mLock;
69
70 // width/height is swapped due to display orientation
71 bool mRotated;
72
73 // preferred size of the client's window
74 uint32_t mClientWidth, mClientHeight;
75
76 // size of the display
77 uint32_t mSourceWidth, mSourceHeight;
78
79 // current ratio between server and client
80 float mScaleX, mScaleY;
81
82 // callback when buffer size changes
83 BufferDimensionsListener* mListener;
84
85 // Android virtual display is always 32-bit
86 static const rfb::PixelFormat sRGBX;
87};
88};
89
90#endif