blob: 5d06d8e9d638a7f22755249f7182196c87ade515 [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
maxwen80ee9662021-10-05 21:08:06 +020024#include <ui/DisplayMode.h>
maxwenad0a9222020-09-20 14:40:41 +020025#include <ui/DisplayState.h>
Steve Kondik6f9ab852017-07-09 21:30:20 -070026#include <ui/Rect.h>
27
28#include <rfb/PixelBuffer.h>
29#include <rfb/PixelFormat.h>
30
31using namespace android;
32
33namespace vncflinger {
34
35class AndroidPixelBuffer : public RefBase, public rfb::ManagedPixelBuffer {
36 public:
37 AndroidPixelBuffer();
38
maxwen80ee9662021-10-05 21:08:06 +020039 virtual void setDisplayInfo(ui::DisplayMode* mode, ui::DisplayState* state);
Steve Kondik6f9ab852017-07-09 21:30:20 -070040
41 virtual void setWindowSize(uint32_t width, uint32_t height);
42
43 virtual ~AndroidPixelBuffer();
44
45 class BufferDimensionsListener {
46 public:
47 virtual void onBufferDimensionsChanged(uint32_t width, uint32_t height) = 0;
48 virtual ~BufferDimensionsListener() {
49 }
50 };
51
52 void setDimensionsChangedListener(BufferDimensionsListener* listener) {
53 mListener = listener;
54 }
55
56 bool isRotated() {
57 return mRotated;
58 }
59
60 Rect getSourceRect();
61
maxwen95dceef2019-12-07 12:00:17 +010062 void reset();
63
Steve Kondik6f9ab852017-07-09 21:30:20 -070064 private:
maxwenad0a9222020-09-20 14:40:41 +020065 static bool isDisplayRotated(ui::Rotation orientation);
Steve Kondik6f9ab852017-07-09 21:30:20 -070066
67 virtual void setBufferRotation(bool rotated);
68
69 virtual void updateBufferSize(bool fromDisplay = false);
70
71 Mutex mLock;
72
73 // width/height is swapped due to display orientation
74 bool mRotated;
75
76 // preferred size of the client's window
77 uint32_t mClientWidth, mClientHeight;
78
79 // size of the display
80 uint32_t mSourceWidth, mSourceHeight;
81
82 // current ratio between server and client
83 float mScaleX, mScaleY;
84
85 // callback when buffer size changes
86 BufferDimensionsListener* mListener;
87
88 // Android virtual display is always 32-bit
89 static const rfb::PixelFormat sRGBX;
90};
91};
92
93#endif