video中 Palette中 用GCHandle的方式代替频繁fixed | 交换大部分颜色通道,考虑PSVita
This commit is contained in:
parent
945ff6b319
commit
86b352c1f2
@ -1,5 +1,6 @@
|
||||
using MAME.Core;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MAME.Core
|
||||
{
|
||||
@ -17,8 +18,90 @@ namespace MAME.Core
|
||||
motion_update_callback();
|
||||
motion_handler_callback();
|
||||
}
|
||||
public static void ui_updateC()
|
||||
//public static void ui_updateC()
|
||||
//{
|
||||
// //不再填充完整画布
|
||||
// //{
|
||||
// // int i;
|
||||
// // int red, green, blue;
|
||||
// // if (single_step || Mame.paused)
|
||||
// // {
|
||||
// // byte bright = 0xa7;
|
||||
// // for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
|
||||
// // {
|
||||
// // red = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff0000) >> 16) * bright / 0xff);
|
||||
// // green = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff00) >> 8) * bright / 0xff);
|
||||
// // blue = (int)((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff) * bright / 0xff);
|
||||
// // Video.bitmapcolor[i] = (int)Palette.make_argb(0xff, red, green, blue);
|
||||
// // }
|
||||
// // }
|
||||
// // else
|
||||
// // {
|
||||
// // for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
|
||||
// // {
|
||||
// // Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
|
||||
// // }
|
||||
// // }
|
||||
// //}
|
||||
|
||||
// {
|
||||
// int i;
|
||||
// int target_i = 0;
|
||||
// int x, y;
|
||||
// int red, green, blue;
|
||||
|
||||
// int startX = Video.offsetx;
|
||||
// int endX = Video.offsetx + Video.width;
|
||||
// int startY = Video.offsety;
|
||||
// int endY = Video.offsety + Video.height;
|
||||
|
||||
// if (single_step || Mame.paused)
|
||||
// {
|
||||
// byte bright = 0xa7;
|
||||
// for (y = startY; y < endY; y++)
|
||||
// {
|
||||
// int stepIndex = y * Video.fullwidth;
|
||||
// for (x = startX; x < endX; x++, target_i++)
|
||||
// {
|
||||
// //i = y * Video.fullwidth + x;
|
||||
// i = stepIndex + x;
|
||||
// red = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff0000) >> 16) * bright / 0xff);
|
||||
// green = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff00) >> 8) * bright / 0xff);
|
||||
// blue = (int)((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff) * bright / 0xff);
|
||||
// Video.bitmapcolorRect[target_i] = (int)Palette.make_argb(0xff, red, green, blue);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
|
||||
// for (y = startY; y < endY; y++)
|
||||
// {
|
||||
// int stepIndex = y * Video.fullwidth;
|
||||
// for (x = startX; x < endX; x++, target_i++)
|
||||
// {
|
||||
// //i = y * Video.fullwidth + x;
|
||||
// i = stepIndex + x;
|
||||
// Video.bitmapcolorRect[target_i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
public unsafe static void ui_updateC()
|
||||
{
|
||||
//fixed (ushort* curbitmapPtr = &Video.bitmapbase[Video.curbitmap][0])
|
||||
//fixed (uint* entry_colorPtr = &Palette.entry_color[0])
|
||||
//fixed (int* bitmapcolorRectPtr = &Video.bitmapcolorRect[0])
|
||||
{
|
||||
//ushort* curbitmap = curbitmapPtr;
|
||||
ushort* curbitmap = (ushort*)Video.bitmapbase_Ptrs[Video.curbitmap];
|
||||
//uint* entry_color = entry_colorPtr;
|
||||
uint* entry_color = (uint*)Palette.entry_color_Ptr;
|
||||
//int* bitmapcolorRect = bitmapcolorRectPtr;
|
||||
int* bitmapcolorRect = (int*)Video.bitmapcolorRect_Ptr;
|
||||
|
||||
/*
|
||||
//不再填充完整画布
|
||||
//{
|
||||
// int i;
|
||||
@ -42,46 +125,45 @@ namespace MAME.Core
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
{
|
||||
int i;
|
||||
int target_i = 0;
|
||||
int x, y;
|
||||
int red, green, blue;
|
||||
|
||||
int startX = Video.offsetx;
|
||||
int endX = Video.offsetx + Video.width;
|
||||
int startY = Video.offsety;
|
||||
int endY = Video.offsety + Video.height;
|
||||
|
||||
if (single_step || Mame.paused)
|
||||
*/
|
||||
{
|
||||
byte bright = 0xa7;
|
||||
for (y = startY; y < endY; y++)
|
||||
int i;
|
||||
int target_i = 0;
|
||||
int x, y;
|
||||
int red, green, blue;
|
||||
|
||||
int startX = Video.offsetx;
|
||||
int endX = Video.offsetx + Video.width;
|
||||
int startY = Video.offsety;
|
||||
int endY = Video.offsety + Video.height;
|
||||
|
||||
if (single_step || Mame.paused)
|
||||
{
|
||||
int stepIndex = y * Video.fullwidth;
|
||||
for (x = startX; x < endX; x++, target_i++)
|
||||
byte bright = 0xa7;
|
||||
for (y = startY; y < endY; y++)
|
||||
{
|
||||
//i = y * Video.fullwidth + x;
|
||||
i = stepIndex + x;
|
||||
red = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff0000) >> 16) * bright / 0xff);
|
||||
green = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff00) >> 8) * bright / 0xff);
|
||||
blue = (int)((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff) * bright / 0xff);
|
||||
Video.bitmapcolorRect[target_i] = (int)Palette.make_argb(0xff, red, green, blue);
|
||||
int stepIndex = y * Video.fullwidth;
|
||||
for (x = startX; x < endX; x++, target_i++)
|
||||
{
|
||||
i = stepIndex + x;
|
||||
red = (int)(((entry_color[curbitmap[i]] & 0xff0000) >> 16) * bright / 0xff);
|
||||
green = (int)(((entry_color[curbitmap[i]] & 0xff00) >> 8) * bright / 0xff);
|
||||
blue = (int)((entry_color[curbitmap[i]] & 0xff) * bright / 0xff);
|
||||
bitmapcolorRect[target_i] = (int)Palette.make_argb(0xff, red, green, blue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
for (y = startY; y < endY; y++)
|
||||
else
|
||||
{
|
||||
int stepIndex = y * Video.fullwidth;
|
||||
for (x = startX; x < endX; x++, target_i++)
|
||||
|
||||
for (y = startY; y < endY; y++)
|
||||
{
|
||||
//i = y * Video.fullwidth + x;
|
||||
i = stepIndex + x;
|
||||
Video.bitmapcolorRect[target_i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
|
||||
int stepIndex = y * Video.fullwidth;
|
||||
for (x = startX; x < endX; x++, target_i++)
|
||||
{
|
||||
i = stepIndex + x;
|
||||
bitmapcolorRect[target_i] = (int)entry_color[curbitmap[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using MAME.Core.AxiBitmap;
|
||||
using System.Runtime.InteropServices;
|
||||
using System;
|
||||
using Color = MAME.Core.AxiBitmap.AxiColor;
|
||||
|
||||
namespace MAME.Core
|
||||
@ -6,6 +8,11 @@ namespace MAME.Core
|
||||
public class Palette
|
||||
{
|
||||
public static uint[] entry_color;
|
||||
/** entry_color的指针管理 **/
|
||||
static GCHandle entry_color_handle;
|
||||
public static IntPtr entry_color_Ptr;
|
||||
/** end **/
|
||||
|
||||
public static float[] entry_contrast;
|
||||
private static uint trans_uint;
|
||||
private static int numcolors, numgroups;
|
||||
@ -165,8 +172,29 @@ namespace MAME.Core
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//entry_color = new uint[numcolors];
|
||||
|
||||
|
||||
/** entry_color的指针管理 **/
|
||||
// 释放句柄
|
||||
if (entry_color != null && entry_color_handle.IsAllocated)
|
||||
entry_color_handle.Free();
|
||||
|
||||
entry_color = new uint[numcolors];
|
||||
// 固定数组,防止垃圾回收器移动它
|
||||
entry_color_handle = GCHandle.Alloc(entry_color, GCHandleType.Pinned);
|
||||
// 获取数组的指针
|
||||
entry_color_Ptr = entry_color_handle.AddrOfPinnedObject();
|
||||
/** end **/
|
||||
|
||||
|
||||
|
||||
entry_contrast = new float[numcolors];
|
||||
|
||||
|
||||
|
||||
for (index = 0; index < numcolors; index++)
|
||||
{
|
||||
palette_set_callback(index, make_argb(0xff, pal1bit((byte)(index >> 0)), pal1bit((byte)(index >> 1)), pal1bit((byte)(index >> 2))));
|
||||
|
@ -36,16 +36,23 @@ namespace MAME.Core
|
||||
private static double speed_percent;
|
||||
private static uint throttle_history, overall_valid_counter, overall_real_seconds;
|
||||
private static int[] popcount;
|
||||
public static ushort[][] bitmapbase;
|
||||
//public static ushort[][] bitmapbase;
|
||||
public static int[][] bitmapbaseN;
|
||||
//public static int[] bitmapcolor;
|
||||
|
||||
/** bitmapcolor的指针管理 **/
|
||||
public static ushort[][] bitmapbase;
|
||||
static GCHandle[] bitmapbase_handles;
|
||||
public static IntPtr[] bitmapbase_Ptrs;
|
||||
/** end **/
|
||||
|
||||
/** bitmapcolor的指针管理 **/
|
||||
//不再拷贝完整画布
|
||||
//public static int[] bitmapcolor;
|
||||
//static GCHandle bitmapcolor_handle;
|
||||
//public static IntPtr bitmapcolor_Ptr;
|
||||
|
||||
|
||||
public static int[] bitmapcolorRect;
|
||||
static GCHandle bitmapcolorRect_handle;
|
||||
public static IntPtr bitmapcolorRect_Ptr;
|
||||
@ -611,6 +618,29 @@ namespace MAME.Core
|
||||
screenstate.frame_number = 0;
|
||||
|
||||
|
||||
/** bitmapbase的指针管理 **/
|
||||
// 释放句柄
|
||||
if (bitmapbase_handles != null)
|
||||
{
|
||||
for (int i = 0; i < bitmapbase_handles.Length; i++)
|
||||
{
|
||||
if (bitmapbase_handles[i].IsAllocated)
|
||||
bitmapbase_handles[i].Free();
|
||||
}
|
||||
bitmapbase_handles = null;
|
||||
bitmapbase_Ptrs = null;
|
||||
}
|
||||
|
||||
bitmapbase_handles = new GCHandle[bitmapbase.Length];
|
||||
bitmapbase_Ptrs = new IntPtr[bitmapbase.Length];
|
||||
for (int i = 0; i < bitmapbase.Length; i++)
|
||||
{
|
||||
bitmapbase_handles[i] = GCHandle.Alloc(bitmapbase[i], GCHandleType.Pinned);
|
||||
bitmapbase_Ptrs[i] = bitmapbase_handles[i].AddrOfPinnedObject();
|
||||
}
|
||||
|
||||
/** end **/
|
||||
|
||||
//bitmapcolor = new int[Video.fullwidth * Video.fullheight];
|
||||
/** bitmapcolor的指针管理 **/
|
||||
//不再拷贝完整画布
|
||||
@ -631,20 +661,15 @@ namespace MAME.Core
|
||||
|
||||
|
||||
|
||||
if (bitmapcolorRect != null)
|
||||
{
|
||||
// 释放句柄
|
||||
if (bitmapcolorRect_handle.IsAllocated)
|
||||
{
|
||||
bitmapcolorRect_handle.Free();
|
||||
}
|
||||
}
|
||||
// 释放句柄
|
||||
if (bitmapcolorRect != null && bitmapcolorRect_handle.IsAllocated)
|
||||
bitmapcolorRect_handle.Free();
|
||||
|
||||
bitmapcolorRect = new int[width * height];
|
||||
// 固定数组,防止垃圾回收器移动它
|
||||
bitmapcolorRect_handle = GCHandle.Alloc(bitmapcolorRect, GCHandleType.Pinned);
|
||||
// 获取数组的指针
|
||||
bitmapcolorRect_Ptr = bitmapcolorRect_handle.AddrOfPinnedObject();
|
||||
|
||||
/** end **/
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user