Exemplo n.º 1
0
        private DoubleTexture CreateDoubleTexture(Device device)
        {
            int w = Math.Max(this.doubleBuffer.Width, 2);
            int h = Math.Max(this.doubleBuffer.Height, 2);
            //Log( LogType.Debug, "CreateDoubleTexture(" + " device " + device.ComPointer.ToInt64( ) + ", " + w + "x" + h + " ) called " );



            //doSharedTextureTests( device );



            DoubleTexture t2 = null;

            try {
                //if not null we found an existing texture created on another device
                DoubleTexture t2Base = null;
                if (device is DeviceEx)
                {
                    //try to find an already existing shared texture with the right dimensions
                    foreach (DoubleTexture t2Temp in device2DoubleTexture.Values)
                    {
                        if (t2Temp.Width == w && t2Temp.Height == h && !t2Temp.Disposed && t2Temp.BaseDoubleTexture == null)
                        {
                            //Log( LogType.Debug, "[CreateDoubleTexture] Found an existing shared DoubleTexture created on another device " + t2Temp.Device.ComPointer.ToInt64() );
                            t2Base = t2Temp;
                            break;
                        }
                    }
                    if (t2Base == null)
                    {
                        //Log( LogType.Debug, "[CreateDoubleTexture] Need to create new DoubleTexture ..." + ( device is DeviceEx ? " (dx9ex shared is ON)" : " (dx9ex shared is OFF)" ) );
                    }
                }

                //only create a new one if necessary
                t2 = t2Base != null && t2Base.Device == device ? t2Base : new DoubleTexture(device, w, h, t2Base);
                Log(LogType.Debug, "[CreateDoubleTexture] Created new DoubleTexture (" + t2.Width + "x" + t2.Height + " pitch/4=" + (t2.Pitch / 4) + ") for device " + device.ComPointer + " created" + (t2Base != null ? " based on sharedTexture on device " + t2Base.Device.ComPointer : "") + (device is DeviceEx ? " (dx9ex shared is ON)" : " (dx9ex shared is OFF)"));

                if (t2 != null && t2 != t2Base)
                {
                    DoubleTexture t2Temp;
                    if (device2DoubleTexture.TryGetValue(device, out t2Temp))
                    {
                        try {
                            //Log( LogType.Debug, "\tTrying to dispose old DoubleTexture (device  " + device.ComPointer.ToInt64( ) + ", " + t2Temp.Width + "x" + t2Temp.Height + ")" );
                            //if ( t2.BaseDoubleTexture != t2Temp ) {
                            t2Temp.Dispose( );
                            //}
                        }
                        catch {
                            Log(LogType.Debug, "Disposing old DoubleTexture (device  " + device.ComPointer.ToInt64( ) + ", " + t2Temp.Width + "x" + t2Temp.Height + ") failed");
                        }
                    }

                    device2DoubleTexture[device] = t2;
                    //Log( LogType.Debug, "Added new DoubleTexture to device2DoubleTexture..." );
                }

                //Log( LogType.Debug , (this == parent.mediaRendererA ? "A " : "B ") + (active ? "(FRONT) " + parent.FFileNameIn[GetMediaRendererIndex()] : "(BACK) " + parent.FNextFileNameIn[GetMediaRendererIndex()] ) + " Created new texture (" + w + "x" + h + ") for device " + device.ComPointer.ToInt64() + ". " );
            }
            catch (Exception e) {
                Log(LogType.Error, "[CreateDoubleTexture Exception] " + e.Message);
                //t2 = new DoubleTexture(device, 2, 2);
            }

            return(t2);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns>true if completely successful</returns>
        private bool FillTextureUsingLockRectangle( )
        {
            bool success = true;

            if (doubleBuffer.LockFrontBufferForReading(500))
            {
                try {
                    //if device already updated, don't do it again, this should only happen in case we're using dx9ex shared textures
                    List <Device> devicesDone = new List <Device>( );

                    //foreach ( Device d in device2DoubleTexture.Keys ) {
                    //	Log( LogType.Debug, "[FillTextureUsingLockRectangle] " + "TEXTURE on device " + d.ComPointer.ToInt64() + " SHOULD BE updated..." );
                    //}

                    bool firstTextureFilled = false;
                    foreach (Device d in device2DoubleTexture.Keys)
                    {
                        //Log( LogType.Debug, " fill doubletexture " + t2.BackTexture.ComPointer.ToInt64() + "\n" );
                        try {
                            DoubleTexture t2 = device2DoubleTexture[d];

                            PluginInterfaces.V2.EX9.TextureDeviceData textureDeviceData;

                            if (t2 == null || t2.Disposed)
                            {
                                success = false;
                                Log(LogType.Error, "[FillTextureUsingLockRectangle ERROR] t2 == null or disposed on device " + d.ComPointer + " Does this mean we need to create a texture ourselves for device " + d.ComPointer + " ?");
                            }
                            else if (parent.DeviceData == null)
                            {
                                success = false;
                                Log(LogType.Error, "[FillTextureUsingLockRectangle ERROR] parent.DeviceData == null");
                            }
                            else if (t2.Device == null)
                            {
                                success = false;
                                Log(LogType.Error, "[FillTextureUsingLockRectangle ERROR] t2.Device == null");
                            }
                            //THIS DOESN'T SEEM TO BE A PROBLEM !!!
                            else if (!parent.DeviceData.TryGetValue(d, out textureDeviceData))
                            {
                                //success = false;
                                //Log( LogType.Warning, "[FillTextureUsingLockRectangle WARNING] parent.DeviceData.TryGetValue(" + d.ComPointer + ", out textureDeviceData) = FALSE" );
                            }

                            if (success)
                            {
                                //Log( LogType.Debug, "[FillTextureUsingLockRectangle] " + "TEXTURE on device " + d.ComPointer + " SHOULD BE updated..." );

                                //string errDescription = "";


                                // if dx9ex, only fill the first texture as the others are the same texture
                                // we COULD d this by checking if baseDoubleTexture is null?
                                // Don't care about that, just fill the first texture you get, and don't do the other ones
                                if (firstTextureFilled && t2.Device is DeviceEx)                                     //t2.BaseDoubleTexture != null ) { //
                                //Log( LogType.Debug, "[FillTextureUsingLockRectangle DEBUG] We will not fill texture on device " + d.ComPointer + " because we already filled another texture with the same shared handle..." );
                                {
                                }
                                else if (!t2.LockBackTextureForWriting(100))
                                {
                                    success = false;
                                    Log(LogType.Error, "[FillTextureUsingLockRectangle ERROR] " + "t2.LockBackTextureForWriting( 100 ) FAILED (timeout?) !!!");
                                }
                                else
                                {
                                    //TEXTURE SUCCESSFULLY LOCKED for writing

                                    if (t2.Width != doubleBuffer.Width || t2.Height != doubleBuffer.Height)
                                    {
                                        success = false;
                                        textureNeedsResizingOnEvaluate = true;
                                        Log(LogType.Debug, "[FillTextureUsingLockRectangle WARNING] " + "TEXTURE size wrong !");
                                    }
                                    else if (t2.BackTexture == null)
                                    {
                                        success = false;
                                        Log(LogType.Error, "[FillTextureUsingLockRectangle ERROR] " + "TEXTURE == null !!!");
                                    }
                                    else if (t2.BackTexture != null && t2.BackTexture.Disposed)
                                    {
                                        success = false;
                                        Log(LogType.Error, "[FillTextureUsingLockRectangle ERROR] " + "TEXTURE disposed !!!");
                                    }
                                    else if (devicesDone.Contains(t2.Device))
                                    {
                                        //Log( LogType.Debug, "[FillTextureUsingLockRectangle] " + "TEXTURE on device " + d.ComPointer + " already updated, don't do it again..." );
                                    }
                                    else if (t2.BackTexture.Device.ComPointer.ToInt64() != d.ComPointer.ToInt64())
                                    {
                                        //Log( LogType.Debug, "[FillTextureUsingLockRectangle] " + "t2.BackTexture.Device=" + t2.BackTexture.Device.ComPointer.ToInt64( ) + " t2.Device=" + d.ComPointer + " don't match. So we will not try to update this texture, but the one where the devices do match." );
                                    }
                                    else
                                    {
                                        //DataRectangle rDst = t2.BackTexture.LockRectangle(0, LockFlags.Discard);
                                        //rDst.Data.WriteRange( GetReadPixelPlane(), t2.GetPitch() * t2.GetHeight() );
                                        //t2.BackTexture.UnlockRectangle(0);

                                        DataRectangle rDst = null;
                                        try {
                                            //Log( LogType.Debug, "[FillTextureUsingLockRectangle] " + "Trying to t2.BackTexture.LockRectangle(...) TEXTURE on device " + d.ComPointer + "" );

                                            rDst = t2.BackTexture.LockRectangle(0, LockFlags.Discard);

                                            //Log( LogType.Debug, "[FillTextureUsingLockRectangle] " + "Done t2.BackTexture.LockRectangle(...) TEXTURE on device " + d.ComPointer + "" );

                                            try {
                                                if (t2.Pitch == t2.Width * 4)
                                                {
                                                    //Log( LogType.Debug, "[FillTextureUsingLockRectangle] " + "Trying to WriteRange TEXTURE on device " + d.ComPointer + "" );
                                                    rDst.Data.WriteRange(doubleBuffer.FrontBuffer, t2.Pitch * t2.Height);
                                                }
                                                else
                                                {
                                                    //Log( LogType.Debug, "[FillTextureUsingLockRectangle] " + "Trying to Write LINE PER LINE TEXTURE on device " + d.ComPointer + "" );
                                                    //writing line per line
                                                    IntPtr fb        = doubleBuffer.FrontBuffer;
                                                    int    width     = doubleBuffer.Width * 4;
                                                    int    remainder = t2.Pitch - width;
                                                    for (int line = 0; line < t2.Height; line++)
                                                    {
                                                        rDst.Data.WriteRange(IntPtr.Add(fb, line * width), width);
                                                        rDst.Data.Position += remainder;
                                                    }
                                                }
                                                //Log( LogType.Debug, "[FillTextureUsingLockRectangle] " + "Done writing TEXTURE on device " + d.ComPointer + "" );
                                            }
                                            catch {
                                                success = false;
                                                Log(LogType.Error, "[FillTextureUsingLockRectangle ERROR] writerange failed");
                                            }

                                            try {
                                                t2.BackTexture.UnlockRectangle(0);

                                                if (!t2.ToggleFrontBack( ))
                                                {
                                                    success = false;
                                                    Log(LogType.Error, "[FillTextureUsingLockRectangle ERROR] t2.ToggleFrontBack( ) failed");
                                                }
                                            }
                                            catch {
                                                success = false;
                                                Log(LogType.Error, "[FillTextureUsingLockRectangle ERROR] UNlockrectangle failed");
                                            }
                                        }
                                        catch {
                                            success = false;
                                            Log(LogType.Error, "[FillTextureUsingLockRectangle ERROR] lockrectangle failed " + t2.BackTexture.ComPointer.ToInt64( ) + " ?= " + d.ComPointer);
                                        }
                                    }

                                    t2.UnlockBackTexture( );


                                    if (success)
                                    {
                                        deviceDataNeedsUpdatingOnEvaluate = true;
                                        devicesDone.Add(t2.Device);
                                        firstTextureFilled = true;

                                        //Log( LogType.Debug, "[FillTextureUsingLockRectangle] Updated texture on device " + d.ComPointer + "\n" );
                                    }
                                    else
                                    {
                                        deviceDataNeedsUpdatingOnEvaluate = true;
                                    }
                                }
                            }
                        }
                        catch (Exception e) {
                            success = false;
                            Log(LogType.Error, "[FillTextureUsingLockRectangle ERROR] " + e.Message + "\n" + e.StackTrace);
                        }
                    }
                }
                catch (Exception e) {
                    success = false;
                    Log(LogType.Error, "[FillTextureUsingLockRectangle ERROR] (source) " + e.Message);
                }

                doubleBuffer.UnlockFrontBuffer( );
            }
            else
            {
                success = false;
            }

            return(success);
        }
Exemplo n.º 3
0
        private DoubleTexture CreateDoubleTexture(Device device /*, Device parentDeviceForDx9ExShared */)
        {
            int w = Math.Max(this.doubleBuffer.GetWidth(), 2);
            int h = Math.Max(this.doubleBuffer.GetHeight(), 2);

            Log(LogType.Debug, "CreateDoubleTexture(" + " device " + device.ComPointer.ToInt64() + ", " + w + "x" + h + " ) called ");



            //doSharedTextureTests( device );



            DoubleTexture t2 = null;

            try {
/*
 *                              if ( device is DeviceEx ) {
 *                                      //try to find an already existing shared texture with the right dimensions
 *                                      foreach ( DoubleTexture t2Temp in device2DoubleTexture.Values ) {
 *                                              if ( t2Temp.GetWidth() == w && t2Temp.GetHeight() == h ) {
 *                                                      Log( LogType.Debug, "[CreateDoubleTexture] Found an existing shared DoubleTexture created on another device" );
 *                                                      t2 = t2Temp;
 *                                                      break;
 *                                              }
 *                                      }
 *                                      if ( t2 == null ) {
 *                                              Log( LogType.Debug , "[CreateDoubleTexture] Need to create new DoubleTexture ..." + ( device is DeviceEx ? " (dx9ex shared is ON)" : " (dx9ex shared is OFF)" ) );
 *                                      }
 *                              }
 */
//				if ( t2 == null ) {
                //create a new one
                t2 = new DoubleTexture(device, w, h, device is DeviceEx);
                Log(LogType.Debug, "[CreateDoubleTexture] Created new DoubleTexture (" + t2.GetWidth() + "x" + t2.GetHeight() + " pitch/4=" + (t2.GetPitch() / 4) + ") for device " + device.ComPointer.ToInt64() + " created..." + (device is DeviceEx ? " (dx9ex shared is ON)" : " (dx9ex shared is OFF)"));

                if (t2 != null)
                {
                    try {
                        DoubleTexture t2Temp;
                        if (device2DoubleTexture.TryGetValue(device, out t2Temp))
                        {
                            Log(LogType.Debug, "\tTrying to dispose old DoubleTexture (device  " + device.ComPointer.ToInt64() + ", " + t2Temp.GetWidth() + "x" + t2Temp.GetHeight() + ")");
                            t2Temp.Dispose();
                        }
                    } catch {
                        Log(LogType.Debug, "\tfailed");
                    }

                    device2DoubleTexture[device] = t2;
                    Log(LogType.Debug, "Added new DoubleTexture to device2DoubleTexture...");
                }
//				}


                //Log( LogType.Debug , (this == parent.mediaRendererA ? "A " : "B ") + (active ? "(FRONT) " + parent.FFileNameIn[GetMediaRendererIndex()] : "(BACK) " + parent.FNextFileNameIn[GetMediaRendererIndex()] ) + " Created new texture (" + w + "x" + h + ") for device " + device.ComPointer.ToInt64() + ". " );
            } catch (Exception e) {
                Log(LogType.Error, "[CreateDoubleTexture Exception] " + e.Message);
                //t2 = new DoubleTexture(device, 2, 2);
            }

            return(t2);
        }