• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef	sw_FrameBuffer_hpp
16 #define	sw_FrameBuffer_hpp
17 
18 #include "Reactor/Reactor.hpp"
19 #include "Renderer/Surface.hpp"
20 #include "Common/Thread.hpp"
21 
22 namespace sw
23 {
24 	class Surface;
25 
26 	struct BlitState
27 	{
28 		int width;
29 		int height;
30 		Format destFormat;
31 		Format sourceFormat;
32 		int stride;
33 		int cursorWidth;
34 		int cursorHeight;
35 	};
36 
37 	class [[clang::lto_visibility_public]] FrameBuffer
38 	{
39 	public:
40 		FrameBuffer(int width, int height, bool fullscreen, bool topLeftOrigin);
41 
42 		virtual ~FrameBuffer() = 0;
43 
44 		int getWidth() const;
45 		int getHeight() const;
46 		int getStride() const;
47 
48 		virtual void flip(void *source, Format sourceFormat, size_t sourceStride) = 0;
49 		virtual void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) = 0;
50 
51 		virtual void *lock() = 0;
52 		virtual void unlock() = 0;
53 
54 		static void setCursorImage(sw::Surface *cursor);
55 		static void setCursorOrigin(int x0, int y0);
56 		static void setCursorPosition(int x, int y);
57 
58 		static Routine *copyRoutine(const BlitState &state);
59 
60 	protected:
61 		void copy(void *source, Format format, size_t stride);
62 		int width;
63 		int height;
64 		Format sourceFormat;
65 		Format destFormat;
66 		int stride;
67 		bool windowed;
68 
69 		void *locked;   // Video memory back buffer
70 
71 	private:
72 		void copyLocked();
73 
74 		static void threadFunction(void *parameters);
75 
76 		void *target;   // Render target buffer
77 
78 		struct Cursor
79 		{
80 			void *image;
81 			int x;
82 			int y;
83 			int width;
84 			int height;
85 			int hotspotX;
86 			int hotspotY;
87 			int positionX;
88 			int positionY;
89 		};
90 
91 		static Cursor cursor;
92 
93 		void (*blitFunction)(void *dst, void *src, Cursor *cursor);
94 		Routine *blitRoutine;
95 		BlitState blitState;
96 
97 		static void blend(const BlitState &state, const Pointer<Byte> &d, const Pointer<Byte> &s, const Pointer<Byte> &c);
98 
99 		Thread *blitThread;
100 		Event syncEvent;
101 		Event blitEvent;
102 		volatile bool terminate;
103 
104 		static bool topLeftOrigin;
105 	};
106 }
107 
108 #endif	 //	sw_FrameBuffer_hpp
109