1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // Surface.cpp: Implements the egl::Surface class, representing a drawing surface
16 // such as the client area of a window, including any back buffers.
17 // Implements EGLSurface and related functionality. [EGL 1.4] section 2.2 page 3.
18 
19 #ifndef sw_FrameBufferX11_hpp
20 #define sw_FrameBufferX11_hpp
21 
22 #include "Main/FrameBuffer.hpp"
23 #include "Common/Debug.hpp"
24 
25 #include <X11/Xlib.h>
26 #include <X11/Xutil.h>
27 #include <X11/extensions/XShm.h>
28 
29 namespace sw
30 {
31 	class FrameBufferX11 : public FrameBuffer
32 	{
33 	public:
34 		FrameBufferX11(Display *display, Window window, int width, int height);
35 
36 		~FrameBufferX11();
37 
flip(void * source,Format sourceFormat,size_t sourceStride)38 		void flip(void *source, Format sourceFormat, size_t sourceStride) override {blit(source, 0, 0, sourceFormat, sourceStride);};
39 		void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override;
40 
41 		void *lock() override;
42 		void unlock() override;
43 
44 	private:
45 		bool ownX11;
46 		Display *x_display;
47 		Window x_window;
48 		XImage *x_image;
49 		GC x_gc;
50 		XVisualInfo x_visual;
51 
52 		bool mit_shm;
53 		XShmSegmentInfo shminfo;
54 
55 		char *buffer;
56 	};
57 }
58 
59 #endif   // sw_FrameBufferX11_hpp
60