Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code for CEF 124 #24

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ find_package(CEF REQUIRED)
# we only bother with UNICODE builds on Windows
if(MSVC)
add_definitions(-DUNICODE -D_UNICODE)
add_compile_options("/std:c++latest")
endif()

set(
Expand Down
20 changes: 6 additions & 14 deletions cmake/cef_variables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,15 @@ if(OS_LINUX)
set(CEF_BINARY_FILES
chrome-sandbox
libcef.so
natives_blob.bin
snapshot_blob.bin
v8_context_snapshot.bin
)

# List of CEF resource files.
set(CEF_RESOURCE_FILES
cef.pak
cef_100_percent.pak
cef_200_percent.pak
cef_extensions.pak
devtools_resources.pak
chrome_100_percent.pak
chrome_200_percent.pak
resources.pak
icudtl.dat
locales
)
Expand Down Expand Up @@ -419,24 +416,19 @@ if(OS_WINDOWS)
# List of CEF binary files.
set(CEF_BINARY_FILES
chrome_elf.dll
d3dcompiler_43.dll
d3dcompiler_47.dll
libcef.dll
libEGL.dll
libGLESv2.dll
natives_blob.bin
snapshot_blob.bin
v8_context_snapshot.bin
swiftshader
)

# List of CEF resource files.
set(CEF_RESOURCE_FILES
cef.pak
cef_100_percent.pak
cef_200_percent.pak
cef_extensions.pak
devtools_resources.pak
chrome_100_percent.pak
chrome_200_percent.pak
resources.pak
icudtl.dat
locales
)
Expand Down
15 changes: 15 additions & 0 deletions gen_vs2022.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@echo off

rem set CEF_ROOT=c:\cef\cef_binary_3.3325.1742.g5caccda_windows64

set BASE_DIR=%~dp0
rem echo %BASE_DIR%

mkdir "%BASE_DIR%\build"

cd "%BASE_DIR%\build"

rem Visual Studio 2022
cmake -G "Visual Studio 17" -A x64 "%BASE_DIR%"

cd %BASE_DIR%
60 changes: 42 additions & 18 deletions src/d3d11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ namespace d3d11 {
, swapchain_(to_com_ptr(swapchain))
, rtv_(to_com_ptr(rtv))
{
IDXGIOutput* pOutput = NULL;
swapchain_->GetContainingOutput(&pOutput);
output_ = shared_ptr<IDXGIOutput>(to_com_ptr(pOutput));
}

void SwapChain::bind(shared_ptr<Context> const& ctx)
Expand Down Expand Up @@ -76,6 +79,10 @@ namespace d3d11 {

void SwapChain::present(int sync_interval)
{
// Workaround for jerky animation when vsynced/fullscreen
if (sync_interval > 0)
output_->WaitForVBlank();

swapchain_->Present(sync_interval, 0);
}

Expand Down Expand Up @@ -202,18 +209,21 @@ namespace d3d11 {

Texture2D::Texture2D(
ID3D11Texture2D* tex,
ID3D11ShaderResourceView* srv)
ID3D11ShaderResourceView* srv, HANDLE share_handle)
: texture_(to_com_ptr(tex))
, srv_(to_com_ptr(srv))
{
share_handle_ = nullptr;

IDXGIResource* res = nullptr;
if (SUCCEEDED(texture_->QueryInterface(
__uuidof(IDXGIResource), reinterpret_cast<void**>(&res))))
if (share_handle != nullptr)
share_handle_ = share_handle;
else
{
res->GetSharedHandle(&share_handle_);
res->Release();
IDXGIResource* res = nullptr;
if (SUCCEEDED(texture_->QueryInterface(
__uuidof(IDXGIResource), reinterpret_cast<void**>(&res))))
{
res->GetSharedHandle(&share_handle_);
res->Release();
}
}

// are we using a keyed mutex?
Expand Down Expand Up @@ -280,7 +290,7 @@ namespace d3d11 {
{
}

void* Texture2D::share_handle() const
HANDLE Texture2D::share_handle() const
{
return share_handle_;
}
Expand Down Expand Up @@ -329,7 +339,7 @@ namespace d3d11 {
}
}

Device::Device(ID3D11Device* pdev, ID3D11DeviceContext* pctx)
Device::Device(ID3D11Device1* pdev, ID3D11DeviceContext* pctx)
: device_(to_com_ptr(pdev))
, ctx_(make_shared<Context>(pctx))
{
Expand Down Expand Up @@ -359,12 +369,12 @@ namespace d3d11 {
return "n/a";
}

shared_ptr<Context> Device::immedidate_context()
shared_ptr<Context> Device::immediate_context()
{
return ctx_;
}

shared_ptr<SwapChain> Device::create_swapchain(HWND window, int width, int height)
shared_ptr<SwapChain> Device::create_swapchain(HWND window, int width, int height, bool fullscreen)
{
HRESULT hr;
IDXGIFactory1* dxgi_factory = nullptr;
Expand Down Expand Up @@ -419,9 +429,17 @@ namespace d3d11 {
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferCount = 1;

DXGI_SWAP_CHAIN_FULLSCREEN_DESC fsd = { 0 };
if (fullscreen)
{
fsd.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE;
fsd.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
fsd.Windowed = false;
}

IDXGISwapChain1* swapchain1 = nullptr;
hr = dxgi_factory2->CreateSwapChainForHwnd(
device_.get(), window, &sd, nullptr, nullptr, &swapchain1);
device_.get(), window, &sd, fullscreen ? &fsd : nullptr, nullptr, &swapchain1);
if (SUCCEEDED(hr))
{
hr = swapchain1->QueryInterface(__uuidof(IDXGISwapChain), reinterpret_cast<void**>(&swapchain));
Expand All @@ -445,7 +463,7 @@ namespace d3d11 {
sd.OutputWindow = window;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
sd.Windowed = !fullscreen;

hr = dxgi_factory->CreateSwapChain(device_.get(), &sd, &swapchain);
}
Expand Down Expand Up @@ -573,10 +591,10 @@ namespace d3d11 {
return nullptr;
}

shared_ptr<Texture2D> Device::open_shared_texture(void* handle)
shared_ptr<Texture2D> Device::open_shared_texture(HANDLE handle)
{
ID3D11Texture2D* tex = nullptr;
auto hr = device_->OpenSharedResource(
auto hr = device_->OpenSharedResource1(
handle, __uuidof(ID3D11Texture2D), (void**)(&tex));
if (FAILED(hr)) {
return nullptr;
Expand All @@ -603,7 +621,7 @@ namespace d3d11 {
}
}

return make_shared<Texture2D>(tex, srv);
return make_shared<Texture2D>(tex, srv, handle);
}

shared_ptr<Texture2D> Device::create_texture(
Expand Down Expand Up @@ -839,6 +857,7 @@ float4 main(VS_OUTPUT input) : SV_Target


ID3D11Device* pdev = nullptr;
ID3D11Device1* pdev1 = nullptr;
ID3D11DeviceContext* pctx = nullptr;

D3D_FEATURE_LEVEL selected_level;
Expand Down Expand Up @@ -871,8 +890,13 @@ float4 main(VS_OUTPUT input) : SV_Target
}

if (SUCCEEDED(hr))
hr = pdev->QueryInterface<ID3D11Device1>(&pdev1);

pdev->Release();

if (SUCCEEDED(hr))
{
auto const dev = make_shared<Device>(pdev, pctx);
auto const dev = make_shared<Device>(pdev1, pctx);

log_message("d3d11: selected adapter: %s\n", dev->adapter_name().c_str());

Expand Down
18 changes: 10 additions & 8 deletions src/d3d11.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ namespace d3d11 {
class Device
{
public:
Device(ID3D11Device*, ID3D11DeviceContext*);
Device(ID3D11Device1*, ID3D11DeviceContext*);

std::string adapter_name() const;

operator ID3D11Device*() {
operator ID3D11Device1*() {
return device_.get();
}

std::shared_ptr<Context> immedidate_context();
std::shared_ptr<Context> immediate_context();

std::shared_ptr<SwapChain> create_swapchain(HWND, int width=0, int height=0);
std::shared_ptr<SwapChain> create_swapchain(HWND, int width=0, int height=0, bool fullscreen=false);

std::shared_ptr<Geometry> create_quad(
float x, float y, float width, float height, bool flip=false);
Expand All @@ -72,7 +72,7 @@ namespace d3d11 {
const void* data,
size_t row_stride);

std::shared_ptr<Texture2D> open_shared_texture(void*);
std::shared_ptr<Texture2D> open_shared_texture(HANDLE);

std::shared_ptr<Effect> create_default_effect();

Expand All @@ -93,7 +93,7 @@ namespace d3d11 {

HMODULE _lib_compiler;

std::shared_ptr<ID3D11Device> const device_;
std::shared_ptr<ID3D11Device1> const device_;
std::shared_ptr<Context> const ctx_;
};

Expand Down Expand Up @@ -122,6 +122,7 @@ namespace d3d11 {
std::shared_ptr<ID3D11SamplerState> const sampler_;
std::shared_ptr<ID3D11BlendState> const blender_;
std::shared_ptr<IDXGISwapChain> const swapchain_;
std::shared_ptr<IDXGIOutput> output_;
std::shared_ptr<ID3D11RenderTargetView> rtv_;
std::shared_ptr<Context> ctx_;
};
Expand All @@ -131,7 +132,8 @@ namespace d3d11 {
public:
Texture2D(
ID3D11Texture2D* tex,
ID3D11ShaderResourceView* srv);
ID3D11ShaderResourceView* srv,
HANDLE share_handle = nullptr);

void bind(std::shared_ptr<Context> const& ctx);
void unbind();
Expand All @@ -145,7 +147,7 @@ namespace d3d11 {
bool lock_key(uint64_t key, uint32_t timeout_ms);
void unlock_key(uint64_t key);

void* share_handle() const;
HANDLE share_handle() const;

void copy_from(std::shared_ptr<Texture2D> const&);

Expand Down
10 changes: 7 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <fstream>
#include <sstream>

#define FULLSCREEN true

//
// if we're running on a system with hybrid graphics ...
// try to force the selection of the high-performance gpu
Expand Down Expand Up @@ -148,7 +150,7 @@ class Window

void render()
{
auto ctx = device_->immedidate_context();
auto ctx = device_->immediate_context();
if (!ctx || !swapchain_) {
return;
}
Expand Down Expand Up @@ -285,7 +287,7 @@ class Window
void on_create()
{
// create a D3D11 swapchain for the window
swapchain_ = device_->create_swapchain(hwnd());
swapchain_ = device_->create_swapchain(hwnd(), 0, 0, FULLSCREEN);
}

void on_new_window()
Expand Down Expand Up @@ -405,7 +407,9 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, LPWSTR, int)

// default to webgl aquarium demo
if (url.empty()) {
url = "https://webglsamples.org/aquarium/aquarium.html";
//url = "https://webglsamples.org/aquarium/aquarium.html";
//url = "https://webglsamples.org/blob/blob.html";
url = "https://www.youtube.com/watch?v=7oAjnqu_wxE";
}
if (width <= 0) {
width = 1280;
Expand Down
Loading