Path: blob/master/src/java.desktop/windows/native/libawt/java2d/d3d/D3DPipelineManager.h
41159 views
/*1* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24#pragma once2526#include "D3DPipeline.h"27#include "D3DContext.h"28#include "awt_Toolkit.h"2930typedef class D3DPipelineManager *LPD3DPIPELINEMANAGER;3132typedef struct D3DAdapter33{34D3DContext *pd3dContext;35DWORD state;36HWND fsFocusWindow;37} D3DAdapter;3839class D3DPIPELINE_API D3DPipelineManager40{41friend class D3DInitializer;42private:43// creates and initializes instance of D3DPipelineManager, may return NULL44static D3DPipelineManager* CreateInstance(void);4546// deletes the single instance of the manager47static void DeleteInstance();4849public:50// returns the single instance of the manager, may return NULL51static D3DPipelineManager* GetInstance(void);5253HRESULT GetD3DContext(UINT adapterOrdinal, D3DContext **ppd3dContext);5455HRESULT HandleLostDevices();56// Checks if adapters were added or removed, or if the order had changed57// (which may happen with primary display is changed). If that's the case58// releases current adapters and d3d9 instance, reinitializes the pipeline.59// @param *monHds list of monitor handles retrieved from GDI60// @param monNum number of gdi monitors61static62HRESULT HandleAdaptersChange(HMONITOR *monHds, UINT monNum);63// returns depth stencil buffer format matching adapterFormat and render target64// format for the device specified by adapterOrdinal/devType65D3DFORMAT GetMatchingDepthStencilFormat(UINT adapterOrdinal,66D3DFORMAT adapterFormat,67D3DFORMAT renderTargetFormat);6869HWND GetCurrentFocusWindow();70// returns previous fs window71HWND SetFSFocusWindow(UINT, HWND);7273LPDIRECT3D9 GetD3DObject() { return pd3d9; }74D3DDEVTYPE GetDeviceType() { return devType; }7576// returns the d3d adapter ordinal given GDI screen number:77// these may differ depending on which display is primary78UINT GetAdapterOrdinalForScreen(jint gdiScreen);7980private:81D3DPipelineManager(void);82~D3DPipelineManager(void);8384// Creates a Direct3D9 object and initializes adapters.85HRESULT InitD3D(void);86// Releases adapters, Direct3D9 object and the d3d9 library.87HRESULT ReleaseD3D();8889// selects the device type based on user input and available90// device types91D3DDEVTYPE SelectDeviceType();9293// creates array of adapters (releases the old one first)94HRESULT InitAdapters();95// releases each adapter's context, and then releases the array96HRESULT ReleaseAdapters();9798HWND CreateDefaultFocusWindow();99// returns S_OK if the adapter is capable of running the Direct3D100// pipeline101HRESULT D3DEnabledOnAdapter(UINT Adapter);102// returns adapterOrdinal given a HMONITOR handle103UINT GetAdapterOrdinalByHmon(HMONITOR hMon);104HRESULT CheckAdaptersInfo();105HRESULT CheckDeviceCaps(UINT Adapter);106// Check the OS, succeeds if the OS is XP or newer client-class OS107static HRESULT CheckOSVersion();108// used to check attached adapters using GDI against known bad hw database109// prior to the instantiation of the pipeline manager110static HRESULT GDICheckForBadHardware();111// given VendorId, DeviceId and driver version, checks against a database112// of known bad hardware/driver combinations.113// If the driver version is not known MAX_VERSION can be used114// which is guaranteed to satisfy the check115static HRESULT CheckForBadHardware(DWORD vId, DWORD dId, LONGLONG version);116117private:118119// current adapter count120UINT adapterCount;121// Pointer to Direct3D9 Object mainained by the pipeline manager122LPDIRECT3D9 pd3d9;123// d3d9.dll lib124HINSTANCE hLibD3D9;125126int currentFSFocusAdapter;127HWND defaultFocusWindow;128129D3DDEVTYPE devType;130131D3DAdapter *pAdapters;132// instance of this object133static LPD3DPIPELINEMANAGER pMgr;134};135136#define OS_UNDEFINED (0 << 0)137#define OS_VISTA (1 << 0)138#define OS_WINSERV_2008 (1 << 1)139#define OS_WINXP (1 << 2)140#define OS_WINXP_64 (1 << 3)141#define OS_WINSERV_2003 (1 << 4)142#define OS_WINDOWS7 (1 << 5)143#define OS_WINSERV_2008R2 (1 << 6)144#define OS_ALL (OS_VISTA|OS_WINSERV_2008|OS_WINXP|OS_WINXP_64|OS_WINSERV_2003|\145OS_WINDOWS7|OS_WINSERV_2008R2)146#define OS_UNKNOWN (~OS_ALL)147BOOL D3DPPLM_OsVersionMatches(USHORT osInfo);148149150class D3DInitializer : public AwtToolkit::PreloadAction {151private:152D3DInitializer();153~D3DInitializer();154155protected:156// PreloadAction overrides157virtual void InitImpl();158virtual void CleanImpl(bool reInit);159160public:161static D3DInitializer& GetInstance() { return theInstance; }162163private:164// single instance165static D3DInitializer theInstance;166167// adapter initializer class168class D3DAdapterInitializer : public AwtToolkit::PreloadAction {169public:170void setAdapter(UINT adapter) { this->adapter = adapter; }171protected:172// PreloadAction overrides173virtual void InitImpl();174virtual void CleanImpl(bool reInit);175private:176UINT adapter;177};178179// the flag indicates success of COM initialization180bool bComInitialized;181D3DAdapterInitializer *pAdapterIniters;182183};184185186187