Exemple #1
0
        // GetIndirectLayerImageMap(s64 width, s64 height, u64 handle, nn::applet::AppletResourceUserId, pid) -> (s64, s64, buffer<bytes, 0x46>)
        public ResultCode GetIndirectLayerImageMap(ServiceCtx context)
        {
            // The size of the layer buffer should be an aligned multiple of width * height
            // because it was created using GetIndirectLayerImageRequiredMemoryInfo as a guide.

            long  layerWidth        = context.RequestData.ReadInt64();
            long  layerHeight       = context.RequestData.ReadInt64();
            long  layerHandle       = context.RequestData.ReadInt64();
            ulong layerBuffPosition = context.Request.ReceiveBuff[0].Position;
            ulong layerBuffSize     = context.Request.ReceiveBuff[0].Size;

            // Get the pitch of the layer that is necessary to render correctly.
            ulong size = GetA8B8G8R8LayerSize((int)layerWidth, (int)layerHeight, out int pitch, out _);

            Debug.Assert(layerBuffSize == size);

            // Get the applet associated with the handle.
            object appletObject = context.Device.System.AppletState.IndirectLayerHandles.GetData((int)layerHandle);

            if (appletObject == null)
            {
                Logger.Error?.Print(LogClass.ServiceVi, $"Indirect layer handle {layerHandle} does not match any applet");

                return(ResultCode.Success);
            }

            Debug.Assert(appletObject is IApplet);

            IApplet applet = appletObject as IApplet;

            Span <byte> graphics = applet.GetGraphicsA8B8G8R8((int)layerWidth, (int)layerHeight, pitch, (int)layerBuffSize);

            if (graphics == null)
            {
                Logger.Error?.Print(LogClass.ServiceVi, $"Applet returned no graphics for indirect layer handle {layerHandle}");

                return(ResultCode.Success);
            }

            context.Memory.Write((ulong)layerBuffPosition, graphics);

            context.ResponseData.Write(layerWidth);
            context.ResponseData.Write(layerHeight);

            return(ResultCode.Success);
        }