• 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 destStride;
33 		int sourceStride;
34 		int cursorWidth;
35 		int cursorHeight;
36 	};
37 
38 	class [[clang::lto_visibility_public]] FrameBuffer
39 	{
40 	public:
41 		FrameBuffer(int width, int height, bool fullscreen, bool topLeftOrigin);
42 
43 		virtual ~FrameBuffer() = 0;
44 
45 		virtual void flip(sw::Surface *source) = 0;
46 		virtual void blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) = 0;
47 
48 		virtual void *lock() = 0;
49 		virtual void unlock() = 0;
50 
51 		static void setCursorImage(sw::Surface *cursor);
52 		static void setCursorOrigin(int x0, int y0);
53 		static void setCursorPosition(int x, int y);
54 
55 		static Routine *copyRoutine(const BlitState &state);
56 
57 	protected:
58 		void copy(sw::Surface *source);
59 
60 		bool windowed;
61 
62 		void *framebuffer;   // Native window buffer.
63 		int width;
64 		int height;
65 		int stride;
66 		Format format;
67 
68 	private:
69 		void copyLocked();
70 
71 		static void threadFunction(void *parameters);
72 
73 		void *renderbuffer;   // Render target buffer.
74 
75 		struct Cursor
76 		{
77 			void *image;
78 			int x;
79 			int y;
80 			int width;
81 			int height;
82 			int hotspotX;
83 			int hotspotY;
84 			int positionX;
85 			int positionY;
86 		};
87 
88 		static Cursor cursor;
89 
90 		void (*blitFunction)(void *dst, void *src, Cursor *cursor);
91 		Routine *blitRoutine;
92 		BlitState blitState;     // State of the current blitRoutine.
93 		BlitState updateState;   // State of the routine to be generated.
94 
95 		static void blend(const BlitState &state, const Pointer<Byte> &d, const Pointer<Byte> &s, const Pointer<Byte> &c);
96 
97 		Thread *blitThread;
98 		Event syncEvent;
99 		Event blitEvent;
100 		volatile bool terminate;
101 
102 		static bool topLeftOrigin;
103 	};
104 }
105 
106 #endif	 //	sw_FrameBuffer_hpp
107