mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-14 02:38:29 +12:00
46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
#include "Cafe/HW/Latte/Renderer/Metal/MetalLayerHandle.h"
|
|
#include "Cafe/HW/Latte/Renderer/Metal/MetalLayer.h"
|
|
|
|
#include "gui/guiWrapper.h"
|
|
|
|
MetalLayerHandle::MetalLayerHandle(MTL::Device* device, const Vector2i& size, bool mainWindow)
|
|
{
|
|
const auto& windowInfo = (mainWindow ? gui_getWindowInfo().window_main : gui_getWindowInfo().window_pad);
|
|
|
|
m_layer = (CA::MetalLayer*)CreateMetalLayer(windowInfo.handle, m_layerScaleX, m_layerScaleY);
|
|
m_layer->setDevice(device);
|
|
m_layer->setDrawableSize(CGSize{(float)size.x * m_layerScaleX, (float)size.y * m_layerScaleY});
|
|
m_layer->setFramebufferOnly(true);
|
|
}
|
|
|
|
MetalLayerHandle::~MetalLayerHandle()
|
|
{
|
|
if (m_layer)
|
|
m_layer->release();
|
|
}
|
|
|
|
void MetalLayerHandle::Resize(const Vector2i& size)
|
|
{
|
|
m_layer->setDrawableSize(CGSize{(float)size.x * m_layerScaleX, (float)size.y * m_layerScaleY});
|
|
}
|
|
|
|
bool MetalLayerHandle::AcquireDrawable()
|
|
{
|
|
if (m_drawable)
|
|
return true;
|
|
|
|
m_drawable = m_layer->nextDrawable();
|
|
if (!m_drawable)
|
|
{
|
|
cemuLog_log(LogType::Force, "layer {} failed to acquire next drawable", (void*)this);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void MetalLayerHandle::PresentDrawable(MTL::CommandBuffer* commandBuffer)
|
|
{
|
|
commandBuffer->presentDrawable(m_drawable);
|
|
m_drawable = nullptr;
|
|
}
|