service/vi: Factor out scaling mode conversions from the IPC function itself
Avoids entangling the IPC buffer appending with the actual operation of converting the scaling values over. This also inserts the proper error handling for invalid scaling values.
This commit is contained in:
parent
40aa1ea9f9
commit
56e51da1d9
|
@ -1003,7 +1003,7 @@ private:
|
||||||
const u64 unknown = rp.Pop<u64>();
|
const u64 unknown = rp.Pop<u64>();
|
||||||
|
|
||||||
LOG_DEBUG(Service_VI, "called. scaling_mode=0x{:08X}, unknown=0x{:016X}",
|
LOG_DEBUG(Service_VI, "called. scaling_mode=0x{:08X}, unknown=0x{:016X}",
|
||||||
static_cast<u32>(scaling_mode), unknown);
|
static_cast<u32>(scaling_mode), unknown);
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
|
||||||
|
@ -1102,31 +1102,35 @@ private:
|
||||||
|
|
||||||
void ConvertScalingMode(Kernel::HLERequestContext& ctx) {
|
void ConvertScalingMode(Kernel::HLERequestContext& ctx) {
|
||||||
IPC::RequestParser rp{ctx};
|
IPC::RequestParser rp{ctx};
|
||||||
auto mode = rp.PopEnum<NintendoScaleMode>();
|
const auto mode = rp.PopEnum<NintendoScaleMode>();
|
||||||
LOG_DEBUG(Service_VI, "called mode={}", static_cast<u32>(mode));
|
LOG_DEBUG(Service_VI, "called mode={}", static_cast<u32>(mode));
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 4};
|
const auto converted_mode = ConvertScalingModeImpl(mode);
|
||||||
rb.Push(RESULT_SUCCESS);
|
|
||||||
|
if (converted_mode.Succeeded()) {
|
||||||
|
IPC::ResponseBuilder rb{ctx, 4};
|
||||||
|
rb.Push(RESULT_SUCCESS);
|
||||||
|
rb.PushEnum(*converted_mode);
|
||||||
|
} else {
|
||||||
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
rb.Push(converted_mode.Code());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static ResultVal<ConvertedScaleMode> ConvertScalingModeImpl(NintendoScaleMode mode) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case NintendoScaleMode::None:
|
case NintendoScaleMode::None:
|
||||||
rb.PushEnum(ConvertedScaleMode::None);
|
return MakeResult(ConvertedScaleMode::None);
|
||||||
break;
|
|
||||||
case NintendoScaleMode::Freeze:
|
case NintendoScaleMode::Freeze:
|
||||||
rb.PushEnum(ConvertedScaleMode::Freeze);
|
return MakeResult(ConvertedScaleMode::Freeze);
|
||||||
break;
|
|
||||||
case NintendoScaleMode::ScaleToWindow:
|
case NintendoScaleMode::ScaleToWindow:
|
||||||
rb.PushEnum(ConvertedScaleMode::ScaleToWindow);
|
return MakeResult(ConvertedScaleMode::ScaleToWindow);
|
||||||
break;
|
|
||||||
case NintendoScaleMode::Crop:
|
case NintendoScaleMode::Crop:
|
||||||
rb.PushEnum(ConvertedScaleMode::Crop);
|
return MakeResult(ConvertedScaleMode::Crop);
|
||||||
break;
|
|
||||||
case NintendoScaleMode::NoCrop:
|
case NintendoScaleMode::NoCrop:
|
||||||
rb.PushEnum(ConvertedScaleMode::NoCrop);
|
return MakeResult(ConvertedScaleMode::NoCrop);
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
UNIMPLEMENTED_MSG("Unknown scaling mode {}", static_cast<u32>(mode));
|
return ERR_OPERATION_FAILED;
|
||||||
rb.PushEnum(ConvertedScaleMode::None);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue