|
5 | 5 | using namespace LibretroRT_FrontendComponents_Renderer; |
6 | 6 |
|
7 | 7 | using namespace Windows::Graphics::DirectX::Direct3D11; |
| 8 | +using namespace Windows::Foundation::Numerics; |
8 | 9 |
|
9 | 10 | Renderer::Renderer(CanvasAnimatedControl^ canvas) : |
10 | 11 | Canvas(canvas), |
@@ -60,6 +61,11 @@ void Renderer::PixelFormatChanged(PixelFormats format) |
60 | 61 | PixelFormat = format; |
61 | 62 | } |
62 | 63 |
|
| 64 | +void Renderer::RotationChanged(Rotations rotation) |
| 65 | +{ |
| 66 | + Rotation = rotation; |
| 67 | +} |
| 68 | + |
63 | 69 | void Renderer::TimingChanged(SystemTiming^ timings) |
64 | 70 | { |
65 | 71 | TimeSpan newTargetDuration = { 10000000.0 / timings->FPS }; |
@@ -138,16 +144,40 @@ void Renderer::CanvasDraw(ICanvasAnimatedControl^ sender, CanvasAnimatedDrawEven |
138 | 144 | { |
139 | 145 | auto drawingSession = args->DrawingSession; |
140 | 146 | auto canvasSize = sender->Size; |
| 147 | + auto aspectRatio = Geometry->AspectRatio; |
141 | 148 |
|
142 | 149 | if (Win2DTexture == nullptr || RenderTargetViewport.Width <= 0 || RenderTargetViewport.Height <= 0) |
143 | 150 | { |
144 | 151 | return; |
145 | 152 | } |
146 | 153 |
|
147 | | - critical_section::scoped_lock lock(RenderTargetCriticalSection); |
| 154 | + static const float piValue = 3.14159265358979323846f; |
| 155 | + auto rotAngle = 0.0f; |
| 156 | + switch (Rotation) |
| 157 | + { |
| 158 | + case Rotations::CCW90: |
| 159 | + rotAngle = -0.5f * piValue; |
| 160 | + aspectRatio = 1.0f / aspectRatio; |
| 161 | + break; |
| 162 | + case Rotations::CCW180: |
| 163 | + rotAngle = -piValue; |
| 164 | + break; |
| 165 | + case Rotations::CCW270: |
| 166 | + rotAngle = -1.5f * piValue; |
| 167 | + aspectRatio = 1.0f / aspectRatio; |
| 168 | + break; |
| 169 | + } |
| 170 | + |
| 171 | + auto destinationSize = ComputeBestFittingSize(canvasSize, aspectRatio); |
| 172 | + auto scaleMatrix = make_float3x2_scale(destinationSize.Width, destinationSize.Height); |
| 173 | + auto rotMatrix = make_float3x2_rotation(rotAngle); |
| 174 | + auto transMatrix = make_float3x2_translation(0.5f * canvasSize.Width, 0.5f * canvasSize.Height); |
| 175 | + auto transformMatrix = rotMatrix * scaleMatrix * transMatrix; |
148 | 176 |
|
149 | | - auto destinationRect = ComputeBestFittingSize(canvasSize, Geometry->AspectRatio); |
150 | | - drawingSession->DrawImage(Win2DTexture, destinationRect, RenderTargetViewport); |
| 177 | + critical_section::scoped_lock lock(RenderTargetCriticalSection); |
| 178 | + drawingSession->Transform = transformMatrix; |
| 179 | + drawingSession->DrawImage(Win2DTexture, Rect(-0.5f, -0.5f, 1.0f, 1.0f), RenderTargetViewport); |
| 180 | + drawingSession->Transform = float3x2::identity(); |
151 | 181 | } |
152 | 182 |
|
153 | 183 | void Renderer::CreateRenderTargets(CanvasAnimatedControl^ canvas, unsigned int width, unsigned int height) |
@@ -198,22 +228,17 @@ void Renderer::DestroyRenderTargets() |
198 | 228 | } |
199 | 229 | } |
200 | 230 |
|
201 | | -Rect Renderer::ComputeBestFittingSize(Size viewportSize, float aspectRatio) |
| 231 | +Size Renderer::ComputeBestFittingSize(Size viewportSize, float aspectRatio) |
202 | 232 | { |
203 | 233 | auto candidateWidth = std::floor(viewportSize.Height * aspectRatio); |
204 | | - if (viewportSize.Width >= candidateWidth) |
205 | | - { |
206 | | - Size size(candidateWidth, viewportSize.Height); |
207 | | - Rect output(Point((viewportSize.Width - candidateWidth) / 2, 0), size); |
208 | | - return output; |
209 | | - } |
210 | | - else |
| 234 | + Size size(candidateWidth, viewportSize.Height); |
| 235 | + if (viewportSize.Width < candidateWidth) |
211 | 236 | { |
212 | 237 | auto height = viewportSize.Width / aspectRatio; |
213 | | - Size size(viewportSize.Width, height); |
214 | | - Rect output(Point(0, (viewportSize.Height - height) / 2), size); |
215 | | - return output; |
| 238 | + size = Size(viewportSize.Width, height); |
216 | 239 | } |
| 240 | + |
| 241 | + return size; |
217 | 242 | } |
218 | 243 |
|
219 | 244 | unsigned int Renderer::ClosestGreaterPowerTwo(unsigned int value) |
|
0 commit comments