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_FrameBufferDD_hpp
16 #define	sw_FrameBufferDD_hpp
17 
18 #include "FrameBufferWin.hpp"
19 
20 #include <ddraw.h>
21 
22 namespace sw
23 {
24 	class FrameBufferDD : public FrameBufferWin
25 	{
26 	public:
27 		FrameBufferDD(HWND windowHandle, int width, int height, bool fullscreen, bool topLeftOrigin);
28 
29 		~FrameBufferDD() override;
30 
31 		void flip(sw::Surface *source) override;
32 		void blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) override;
33 
34 		void flip(HWND windowOverride, sw::Surface *source) override;
35 		void blit(HWND windowOverride, sw::Surface *source, const Rect *sourceRect, const Rect *destRect) override;
36 
37 		void *lock() override;
38 		void unlock() override;
39 
40 		void setGammaRamp(GammaRamp *gammaRamp, bool calibrate) override;
41 		void getGammaRamp(GammaRamp *gammaRamp) override;
42 
43 		void screenshot(void *destBuffer) override;
44 		bool getScanline(bool &inVerticalBlank, unsigned int &scanline) override;
45 
46 		void drawText(int x, int y, const char *string, ...);
47 
48 	private:
49 		void initFullscreen();
50 		void initWindowed();
51 		void createSurfaces();
52 		bool readySurfaces();
53 		void updateClipper(HWND windowOverride);
54 		void restoreSurfaces();
55 		void releaseAll();
56 
57 		HMODULE ddraw;
58 		typedef HRESULT (WINAPI *DIRECTDRAWCREATE)( GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter );
59 		HRESULT (WINAPI *DirectDrawCreate)( GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter );
60 		typedef HRESULT (WINAPI *DIRECTDRAWENUMERATEEXA)( LPDDENUMCALLBACKEXA lpCallback, LPVOID lpContext, DWORD dwFlags);
61 		HRESULT (WINAPI *DirectDrawEnumerateExA)( LPDDENUMCALLBACKEXA lpCallback, LPVOID lpContext, DWORD dwFlags);
62 
63 		IDirectDraw *directDraw;
64 		IDirectDrawSurface *frontBuffer;
65 		IDirectDrawSurface *backBuffer;
66 	};
67 }
68 
69 #endif	 //	sw_FrameBufferDD_hpp
70