Home | History | Annotate | Download | only in WSI
      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 "Device/Surface.hpp"
     20 #include "System/Thread.hpp"
     21 
     22 namespace sw
     23 {
     24 	using namespace rr;
     25 
     26 	class Surface;
     27 
     28 	struct BlitState
     29 	{
     30 		int width;
     31 		int height;
     32 		VkFormat destFormat;
     33 		VkFormat sourceFormat;
     34 		int destStride;
     35 		int sourceStride;
     36 		int cursorWidth;
     37 		int cursorHeight;
     38 	};
     39 
     40 	class FrameBuffer
     41 	{
     42 	public:
     43 		FrameBuffer(int width, int height, bool fullscreen, bool topLeftOrigin);
     44 
     45 		virtual ~FrameBuffer() = 0;
     46 
     47 		virtual void flip(sw::Surface *source) = 0;
     48 		virtual void blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) = 0;
     49 
     50 		virtual void *lock() = 0;
     51 		virtual void unlock() = 0;
     52 
     53 		static void setCursorImage(sw::Surface *cursor);
     54 		static void setCursorOrigin(int x0, int y0);
     55 		static void setCursorPosition(int x, int y);
     56 
     57 		static Routine *copyRoutine(const BlitState &state);
     58 
     59 	protected:
     60 		void copy(sw::Surface *source);
     61 
     62 		bool windowed;
     63 
     64 		void *framebuffer;   // Native window buffer.
     65 		int width;
     66 		int height;
     67 		int stride;
     68 		VkFormat format;
     69 
     70 	private:
     71 		void copyLocked();
     72 
     73 		static void threadFunction(void *parameters);
     74 
     75 		void *renderbuffer;   // Render target buffer.
     76 
     77 		struct Cursor
     78 		{
     79 			void *image;
     80 			int x;
     81 			int y;
     82 			int width;
     83 			int height;
     84 			int hotspotX;
     85 			int hotspotY;
     86 			int positionX;
     87 			int positionY;
     88 		};
     89 
     90 		static Cursor cursor;
     91 
     92 		void (*blitFunction)(void *dst, void *src, Cursor *cursor);
     93 		Routine *blitRoutine;
     94 		BlitState blitState;     // State of the current blitRoutine.
     95 		BlitState updateState;   // State of the routine to be generated.
     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