430N/A/*
3261N/A * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
430N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
430N/A *
430N/A * This code is free software; you can redistribute it and/or modify it
430N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
430N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
430N/A *
430N/A * This code is distributed in the hope that it will be useful, but WITHOUT
430N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
430N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
430N/A * version 2 for more details (a copy is included in the LICENSE file that
430N/A * accompanied this code).
430N/A *
430N/A * You should have received a copy of the GNU General Public License version
430N/A * 2 along with this work; if not, write to the Free Software Foundation,
430N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
430N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
430N/A */
430N/A#pragma once
430N/A
430N/A#include "D3DPipeline.h"
430N/A#include "D3DContext.h"
2963N/A#include "awt_Toolkit.h"
430N/A
430N/Atypedef class D3DPipelineManager *LPD3DPIPELINEMANAGER;
430N/A
430N/Atypedef struct D3DAdapter
430N/A{
430N/A D3DContext *pd3dContext;
430N/A DWORD state;
430N/A HWND fsFocusWindow;
430N/A} D3DAdapter;
430N/A
430N/Aclass D3DPIPELINE_API D3DPipelineManager
430N/A{
2963N/A friend class D3DInitializer;
2963N/Aprivate:
430N/A // creates and initializes instance of D3DPipelineManager, may return NULL
430N/A static D3DPipelineManager* CreateInstance(void);
2963N/A
430N/A // deletes the single instance of the manager
430N/A static void DeleteInstance();
2963N/A
2963N/Apublic:
430N/A // returns the single instance of the manager, may return NULL
430N/A static D3DPipelineManager* GetInstance(void);
430N/A
430N/A HRESULT GetD3DContext(UINT adapterOrdinal, D3DContext **ppd3dContext);
430N/A
430N/A HRESULT HandleLostDevices();
430N/A // Checks if adapters were added or removed, or if the order had changed
430N/A // (which may happen with primary display is changed). If that's the case
430N/A // releases current adapters and d3d9 instance, reinitializes the pipeline.
430N/A // @param *monHds list of monitor handles retrieved from GDI
430N/A // @param monNum number of gdi monitors
430N/A static
430N/A HRESULT HandleAdaptersChange(HMONITOR *monHds, UINT monNum);
430N/A // returns depth stencil buffer format matching adapterFormat and render target
430N/A // format for the device specified by adapterOrdinal/devType
430N/A D3DFORMAT GetMatchingDepthStencilFormat(UINT adapterOrdinal,
430N/A D3DFORMAT adapterFormat,
430N/A D3DFORMAT renderTargetFormat);
430N/A
430N/A HWND GetCurrentFocusWindow();
430N/A // returns previous fs window
430N/A HWND SetFSFocusWindow(UINT, HWND);
430N/A
430N/A LPDIRECT3D9 GetD3DObject() { return pd3d9; }
430N/A D3DDEVTYPE GetDeviceType() { return devType; }
430N/A
430N/A // returns the d3d adapter ordinal given GDI screen number:
430N/A // these may differ depending on which display is primary
430N/A UINT GetAdapterOrdinalForScreen(jint gdiScreen);
430N/A
430N/A // notifies adapter event listeners by calling
430N/A // AccelDeviceEventNotifier.eventOccured()
430N/A static
430N/A void NotifyAdapterEventListeners(UINT adapter, jint eventType);
430N/A
430N/Aprivate:
430N/A D3DPipelineManager(void);
430N/A ~D3DPipelineManager(void);
430N/A
430N/A // Creates a Direct3D9 object and initializes adapters.
430N/A HRESULT InitD3D(void);
430N/A // Releases adapters, Direct3D9 object and the d3d9 library.
430N/A HRESULT ReleaseD3D();
430N/A
430N/A // selects the device type based on user input and available
430N/A // device types
430N/A D3DDEVTYPE SelectDeviceType();
430N/A
430N/A // creates array of adapters (releases the old one first)
430N/A HRESULT InitAdapters();
430N/A // releases each adapter's context, and then releases the array
430N/A HRESULT ReleaseAdapters();
430N/A
430N/A HWND CreateDefaultFocusWindow();
430N/A // returns S_OK if the adapter is capable of running the Direct3D
430N/A // pipeline
430N/A HRESULT D3DEnabledOnAdapter(UINT Adapter);
430N/A // returns adapterOrdinal given a HMONITOR handle
430N/A UINT GetAdapterOrdinalByHmon(HMONITOR hMon);
430N/A HRESULT CheckAdaptersInfo();
430N/A HRESULT CheckDeviceCaps(UINT Adapter);
430N/A // Check the OS, succeeds if the OS is XP or newer client-class OS
430N/Astatic HRESULT CheckOSVersion();
430N/A // used to check attached adapters using GDI against known bad hw database
430N/A // prior to the instantiation of the pipeline manager
430N/Astatic HRESULT GDICheckForBadHardware();
430N/A // given VendorId, DeviceId and driver version, checks against a database
430N/A // of known bad hardware/driver combinations.
430N/A // If the driver version is not known MAX_VERSION can be used
430N/A // which is guaranteed to satisfy the check
430N/Astatic HRESULT CheckForBadHardware(DWORD vId, DWORD dId, LONGLONG version);
430N/A
430N/Aprivate:
430N/A
430N/A // current adapter count
430N/A UINT adapterCount;
430N/A // Pointer to Direct3D9 Object mainained by the pipeline manager
430N/A LPDIRECT3D9 pd3d9;
430N/A // d3d9.dll lib
430N/A HINSTANCE hLibD3D9;
430N/A
430N/A int currentFSFocusAdapter;
430N/A HWND defaultFocusWindow;
430N/A
430N/A D3DDEVTYPE devType;
430N/A
430N/A D3DAdapter *pAdapters;
430N/A // instance of this object
430N/A static LPD3DPIPELINEMANAGER pMgr;
430N/A};
430N/A
430N/A#define OS_UNDEFINED (0 << 0)
430N/A#define OS_VISTA (1 << 0)
430N/A#define OS_WINSERV_2008 (1 << 1)
430N/A#define OS_WINXP (1 << 2)
430N/A#define OS_WINXP_64 (1 << 3)
430N/A#define OS_WINSERV_2003 (1 << 4)
3176N/A#define OS_WINDOWS7 (1 << 5)
3176N/A#define OS_WINSERV_2008R2 (1 << 6)
3176N/A#define OS_ALL (OS_VISTA|OS_WINSERV_2008|OS_WINXP|OS_WINXP_64|OS_WINSERV_2003|\
3176N/A OS_WINDOWS7|OS_WINSERV_2008R2)
430N/A#define OS_UNKNOWN (~OS_ALL)
430N/ABOOL D3DPPLM_OsVersionMatches(USHORT osInfo);
2963N/A
2963N/A
2963N/Aclass D3DInitializer : public AwtToolkit::PreloadAction {
2963N/Aprivate:
2963N/A D3DInitializer();
2963N/A ~D3DInitializer();
2963N/A
2963N/Aprotected:
2963N/A // PreloadAction overrides
2963N/A virtual void InitImpl();
2963N/A virtual void CleanImpl(bool reInit);
2963N/A
2963N/Apublic:
2963N/A static D3DInitializer& GetInstance() { return theInstance; }
2963N/A
2963N/Aprivate:
2963N/A // single instance
2963N/A static D3DInitializer theInstance;
2963N/A
2963N/A // adapter initializer class
2963N/A class D3DAdapterInitializer : public AwtToolkit::PreloadAction {
2963N/A public:
2963N/A void setAdapter(UINT adapter) { this->adapter = adapter; }
2963N/A protected:
2963N/A // PreloadAction overrides
2963N/A virtual void InitImpl();
2963N/A virtual void CleanImpl(bool reInit);
2963N/A private:
2963N/A UINT adapter;
2963N/A };
2963N/A
2963N/A // the flag indicates success of COM initialization
2963N/A bool bComInitialized;
2963N/A D3DAdapterInitializer *pAdapterIniters;
2963N/A
2963N/A};
2963N/A