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(
gr_cp<IDXGISwapChain1> 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(d3dDevice->device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3dDevice->fence)));
d3dDevice->fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
......
......@@ -45,7 +45,7 @@ open class SkiaLayer(
contextHandler = createContextHandler(this, initialRenderApi)
redrawer = platformOperations.createRedrawer(this, initialRenderApi, properties)
redrawer?.syncSize()
redrawer?.redrawImmediately()
draw(isBlank = true)
}
override fun dispose() {
......@@ -109,22 +109,26 @@ open class SkiaLayer(
}
}
override fun draw() {
override fun draw() = draw(isBlank = false)
fun draw(isBlank: Boolean) {
check(!isDisposed)
contextHandler?.apply {
if (!initContext()) {
fallbackToNextApi()
return
}
initCanvas()
clearCanvas()
synchronized(pictureLock) {
val picture = picture
if (picture != null) {
drawOnCanvas(picture.instance)
if (!isBlank) {
initCanvas()
clearCanvas()
synchronized(pictureLock) {
val picture = picture
if (picture != null) {
drawOnCanvas(picture.instance)
}
}
flush()
}
flush()
}
}
......@@ -145,6 +149,7 @@ open class SkiaLayer(
private fun fallbackToNextApi() {
val nextApi = fallbackRenderApiQueue.removeAt(0)
println("Falling back to $nextApi rendering...")
contextHandler?.dispose()
redrawer?.dispose()
contextHandler = createContextHandler(this, nextApi)
redrawer = platformOperations.createRedrawer(this, nextApi, properties)
......
......@@ -24,6 +24,10 @@ internal class Direct3DContextHandler(layer: SkiaLayer) : ContextHandler(layer)
if (device == 0L) {
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)
}
} catch (e: Exception) {
......
......@@ -66,6 +66,7 @@ internal class Direct3DRedrawer(
external fun createDirectXDevice(windowHandle: Long): Long
external fun makeDirectXContext(device: Long): 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)
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