Commit b3af6583 authored by Roman Sedaikin's avatar Roman Sedaikin

Set background color for DirectX swap chain buffers.

parent e73285de
...@@ -299,6 +299,9 @@ HRESULT D3DCompile( ...@@ -299,6 +299,9 @@ HRESULT D3DCompile(
gr_cp<IDXGISwapChain1> swapChain; gr_cp<IDXGISwapChain1> swapChain;
GR_D3D_CALL_ERRCHECK(swapChainFactory->CreateSwapChainForHwnd(d3dDevice->queue.get(), fWindow, &swapChainDesc, &swapChainFSDesc, nullptr, &swapChain)); GR_D3D_CALL_ERRCHECK(swapChainFactory->CreateSwapChainForHwnd(d3dDevice->queue.get(), fWindow, &swapChainDesc, &swapChainFSDesc, nullptr, &swapChain));
DXGI_RGBA background = {1.0f, 1.0f, 1.0f, 1.0f};
swapChain->SetBackgroundColor(&background);
GR_D3D_CALL_ERRCHECK(swapChain->QueryInterface(IID_PPV_ARGS(&d3dDevice->swapChain))); GR_D3D_CALL_ERRCHECK(swapChain->QueryInterface(IID_PPV_ARGS(&d3dDevice->swapChain)));
GR_D3D_CALL_ERRCHECK(d3dDevice->device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3dDevice->fence))); GR_D3D_CALL_ERRCHECK(d3dDevice->device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3dDevice->fence)));
d3dDevice->fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); d3dDevice->fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
......
...@@ -45,7 +45,7 @@ open class SkiaLayer( ...@@ -45,7 +45,7 @@ open class SkiaLayer(
contextHandler = createContextHandler(this, initialRenderApi) contextHandler = createContextHandler(this, initialRenderApi)
redrawer = platformOperations.createRedrawer(this, initialRenderApi, properties) redrawer = platformOperations.createRedrawer(this, initialRenderApi, properties)
redrawer?.syncSize() redrawer?.syncSize()
redrawer?.redrawImmediately() draw(isBlank = true)
} }
override fun dispose() { override fun dispose() {
...@@ -109,22 +109,26 @@ open class SkiaLayer( ...@@ -109,22 +109,26 @@ open class SkiaLayer(
} }
} }
override fun draw() { override fun draw() = draw(isBlank = false)
fun draw(isBlank: Boolean) {
check(!isDisposed) check(!isDisposed)
contextHandler?.apply { contextHandler?.apply {
if (!initContext()) { if (!initContext()) {
fallbackToNextApi() fallbackToNextApi()
return return
} }
initCanvas() if (!isBlank) {
clearCanvas() initCanvas()
synchronized(pictureLock) { clearCanvas()
val picture = picture synchronized(pictureLock) {
if (picture != null) { val picture = picture
drawOnCanvas(picture.instance) if (picture != null) {
drawOnCanvas(picture.instance)
}
} }
flush()
} }
flush()
} }
} }
...@@ -145,6 +149,7 @@ open class SkiaLayer( ...@@ -145,6 +149,7 @@ open class SkiaLayer(
private fun fallbackToNextApi() { private fun fallbackToNextApi() {
val nextApi = fallbackRenderApiQueue.removeAt(0) val nextApi = fallbackRenderApiQueue.removeAt(0)
println("Falling back to $nextApi rendering...") println("Falling back to $nextApi rendering...")
contextHandler?.dispose()
redrawer?.dispose() redrawer?.dispose()
contextHandler = createContextHandler(this, nextApi) contextHandler = createContextHandler(this, nextApi)
redrawer = platformOperations.createRedrawer(this, nextApi, properties) redrawer = platformOperations.createRedrawer(this, nextApi, properties)
......
...@@ -24,6 +24,10 @@ internal class Direct3DContextHandler(layer: SkiaLayer) : ContextHandler(layer) ...@@ -24,6 +24,10 @@ internal class Direct3DContextHandler(layer: SkiaLayer) : ContextHandler(layer)
if (device == 0L) { if (device == 0L) {
throw Exception("Failed to create DirectX12 device.") throw Exception("Failed to create DirectX12 device.")
} }
val scale = layer.contentScale
val w = (layer.width * scale).toInt().coerceAtLeast(0)
val h = (layer.height * scale).toInt().coerceAtLeast(0)
directXRedrawer.resizeBuffers(device, w, h)
context = directXRedrawer.makeContext(device) context = directXRedrawer.makeContext(device)
} }
} catch (e: Exception) { } catch (e: Exception) {
......
...@@ -66,6 +66,7 @@ internal class Direct3DRedrawer( ...@@ -66,6 +66,7 @@ internal class Direct3DRedrawer(
external fun createDirectXDevice(windowHandle: Long): Long external fun createDirectXDevice(windowHandle: Long): Long
external fun makeDirectXContext(device: Long): Long external fun makeDirectXContext(device: Long): Long
external fun makeDirectXRenderTarget(device: Long, width: Int, height: Int): Long external fun makeDirectXRenderTarget(device: Long, width: Int, height: Int): Long
external fun resizeBuffers(device: Long, width: Int, height: Int)
private external fun finishFrame(device: Long, context: Long, surface: Long, isVsyncEnabled: Boolean) private external fun finishFrame(device: Long, context: Long, surface: Long, isVsyncEnabled: Boolean)
external fun disposeDevice(device: Long) external fun disposeDevice(device: Long)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment