2020-04-19 23:04:05 +02:00
// SPDX-License-Identifier: MPL-2.0
2020-03-27 20:36:02 +01:00
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
2020-09-25 16:35:10 +02:00
# include <gpu.h>
2020-03-24 21:17:31 +01:00
# include <kernel/types/KProcess.h>
# include "IHOSBinderDriver.h"
2020-09-14 16:13:36 +02:00
# include "GraphicBufferProducer.h"
2020-03-24 21:17:31 +01:00
namespace skyline : : service : : hosbinder {
2020-09-21 12:04:26 +02:00
IHOSBinderDriver : : IHOSBinderDriver ( const DeviceState & state , ServiceManager & manager ) : producer ( hosbinder : : producer . expired ( ) ? std : : make_shared < GraphicBufferProducer > ( state ) : hosbinder : : producer . lock ( ) ) , BaseService ( state , manager ) {
2020-09-14 16:13:36 +02:00
if ( hosbinder : : producer . expired ( ) )
hosbinder : : producer = producer ;
2020-03-24 21:17:31 +01:00
}
2020-09-03 20:43:52 +02:00
Result IHOSBinderDriver : : TransactParcel ( type : : KSession & session , ipc : : IpcRequest & request , ipc : : IpcResponse & response ) {
2020-09-26 07:17:57 +02:00
auto layerId { request . Pop < u32 > ( ) } ;
auto code { request . Pop < GraphicBufferProducer : : TransactionCode > ( ) } ;
2020-03-24 21:17:31 +01:00
2020-03-25 18:59:37 +01:00
Parcel in ( request . inputBuf . at ( 0 ) , state , true ) ;
2020-03-24 21:17:31 +01:00
Parcel out ( state ) ;
2020-09-28 12:05:17 +02:00
// We opted for just supporting a single layer and display as it's what basically all games use and wasting cycles on it is pointless
2021-03-04 14:30:14 +01:00
// If this was not done then we would need to maintain an array of GraphicBufferProducer objects for each layer and send the request for it specifically
2020-09-28 12:05:17 +02:00
// There would also need to be an external compositor which composites all the graphics buffers submitted to every GraphicBufferProducer
2021-03-18 10:03:50 +01:00
state . logger - > Debug ( " Layer ID: {}, Code: {} " , layerId , code ) ;
2020-09-14 16:13:36 +02:00
producer - > OnTransact ( code , in , out ) ;
2020-03-24 21:17:31 +01:00
out . WriteParcel ( request . outputBuf . at ( 0 ) ) ;
2020-09-03 20:43:52 +02:00
return { } ;
2020-03-24 21:17:31 +01:00
}
2020-09-03 20:43:52 +02:00
Result IHOSBinderDriver : : AdjustRefcount ( type : : KSession & session , ipc : : IpcRequest & request , ipc : : IpcResponse & response ) {
2020-03-24 21:17:31 +01:00
request . Skip < u32 > ( ) ;
2020-09-26 07:17:57 +02:00
auto addVal { request . Pop < i32 > ( ) } ;
auto type { request . Pop < i32 > ( ) } ;
2020-03-24 21:17:31 +01:00
state . logger - > Debug ( " Reference Change: {} {} reference " , addVal , type ? " strong " : " weak " ) ;
2020-09-03 20:43:52 +02:00
return { } ;
2020-03-24 21:17:31 +01:00
}
2020-09-03 20:43:52 +02:00
Result IHOSBinderDriver : : GetNativeHandle ( type : : KSession & session , ipc : : IpcRequest & request , ipc : : IpcResponse & response ) {
2021-06-18 12:55:19 +02:00
KHandle handle { state . process - > InsertItem ( producer - > bufferEvent ) } ;
2020-03-24 21:17:31 +01:00
state . logger - > Debug ( " Display Buffer Event Handle: 0x{:X} " , handle ) ;
response . copyHandles . push_back ( handle ) ;
2020-09-03 20:43:52 +02:00
return { } ;
2020-03-24 21:17:31 +01:00
}
}