Fungsi DCompositionCreateDevice (dcomp.h)
Membuat objek perangkat baru yang dapat digunakan untuk membuat objek Microsoft DirectComposition lainnya.
Sintaks
HRESULT DCompositionCreateDevice(
[in] IDXGIDevice *dxgiDevice,
[in] REFIID iid,
[out] void **dcompositionDevice
);
Parameter
[in] dxgiDevice
Jenis: IDXGIDevice*
Perangkat DXGI yang digunakan untuk membuat objek permukaan DirectComposition.
[in] iid
Jenis: REFIID
Pengidentifikasi antarmuka yang akan diambil.
[out] dcompositionDevice
Jenis: void**
Menerima penunjuk antarmuka ke objek perangkat yang baru dibuat. Penunjuk adalah jenis yang ditentukan oleh parameter iid . Parameter ini tidak boleh NULL.
Nilai kembali
Jenis: HRESULT
Jika fungsi berhasil, fungsi akan mengembalikan S_OK. Jika tidak, kode kesalahan HRESULT akan dikembalikan. Lihat Kode Kesalahan DirectComposition untuk daftar kode kesalahan.
Keterangan
Objek perangkat berfungsi sebagai pabrik untuk semua objek DirectComposition lainnya. Ini juga mengontrol komposisi transaksional melalui metode IDCompositionDevice::Commit .
Perangkat DXGI yang ditentukan oleh dxgiDevice digunakan untuk membuat semua objek permukaan DirectComposition. Secara khusus, metode IDCompositionSurface::BeginDraw mengembalikan penunjuk antarmuka ke permukaan DXGI milik perangkat yang ditentukan oleh parameter dxgiDevice .
Saat membuat perangkat DXGI, pengembang harus menentukan bendera D3D11_CREATE_DEVICE BGRA_SUPPORT atau D3D10_CREATE_DEVICE_BGRA_SUPPORT untuk interoperabilitas Direct2D dengan sumber daya Microsoft Direct3D.
Parameter iid harus __uuidof(IDCompositionDevice)
, dan parameter dcompositionDevice menerima pointer ke antarmuka IDCompositionDevice .
Contoh
Contoh berikut menunjukkan cara membuat objek perangkat sebagai bagian dari inisialisasi objek DirectComposition.
#include <dcomp.h>
#include <d3d11.h>
HRESULT InitializeDirectCompositionDevice(HWND hwndTarget,
ID3D11Device **ppD3D11Device, IDCompositionDevice **ppDevice,
IDCompositionTarget **ppCompTarget)
{
HRESULT hr = S_OK;
D3D_FEATURE_LEVEL featureLevelSupported;
IDXGIDevice *pDXGIDevice = nullptr;
// Verify that the arguments are valid.
if (hwndTarget == NULL || ppD3D11Device == nullptr || ppDevice == nullptr ||
ppCompTarget == nullptr)
{
return E_INVALIDARG;
}
// Create the D3D device object. Note that the
// D3D11_CREATE_DEVICE_BGRA_SUPPORT flag is needed for rendering
// on surfaces using Direct2D.
hr = D3D11CreateDevice(
nullptr,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
D3D11_CREATE_DEVICE_BGRA_SUPPORT, // needed for rendering on surfaces using Direct2D
NULL,
0,
D3D11_SDK_VERSION,
ppD3D11Device,
&featureLevelSupported,
NULL);
if (SUCCEEDED(hr))
{
// Create the DXGI device used to create bitmap surfaces.
hr = (*ppD3D11Device)->QueryInterface(&pDXGIDevice);
}
if (SUCCEEDED(hr))
{
// Create the DirectComposition device object.
hr = DCompositionCreateDevice(pDXGIDevice, __uuidof(IDCompositionDevice),
reinterpret_cast<void **>(ppDevice));
}
if (SUCCEEDED(hr))
{
// Bind the DirectComposition device to the target window.
hr = (*ppDevice)->CreateTargetForHwnd(hwndTarget, TRUE, ppCompTarget);
}
return hr;
}
Persyaratan
Klien minimum yang didukung | Windows 8 [hanya aplikasi desktop] |
Server minimum yang didukung | Windows Server 2012 [hanya aplikasi desktop] |
Target Platform | Windows |
Header | dcomp.h |
Pustaka | Dcomp.lib |
DLL | Dcomp.dll |
Lihat juga
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk