Exemplo n.º 1
0
 internal void UpdateResources(Device device)
 {
     lock (FTextures)
     {
         var size = Size;
         // Create new textures for valid sizes only
         if (size.Width > 0 && size.Height > 0)
         {
             if (!FTextures.Any(t => t.Device == device))
             {
                 var texture = new DoubleBufferedTexture(device, size);
                 FTextures.Add(texture);
                 // Trigger a redraw
                 FBrowserHost.Invalidate(CefPaintElementType.View);
             }
         }
         // Tell all textures to update - in case the size is not valid
         // the texture will stick to the old one
         for (int i = 0; i < FTextures.Count; i++)
         {
             var texture = FTextures[i];
             if (texture.Device == device)
             {
                 var newTexture = texture.Update(size);
                 // If the "new" texture is in a degraded state trigger a redraw
                 if (newTexture != texture && newTexture.IsDegraded)
                 {
                     FBrowserHost.Invalidate(CefPaintElementType.View);
                 }
                 FTextures[i] = newTexture;
             }
         }
     }
 }
Exemplo n.º 2
0
 public DoubleBufferedTexture Update(Size newSize)
 {
     // Should the size be invalid stick with the old one
     if (newSize.Width <= 0 || newSize.Height <= 0)
     {
         UpdateTexture();
         return(this);
     }
     // Should the size change switch to the degraded state
     if (newSize != Size)
     {
         IncompleteTexture.Dispose();
         return(new DoubleBufferedTexture(Device, newSize, true, CreateTexture(Device, newSize, Pool.SystemMemory), LastCompleteTexture));
     }
     // Size is the same
     if (IsDegraded)
     {
         // We're degraded (sizes of textures differ)
         if (IsDirty)
         {
             // We can switch to the non-degraded state
             LastCompleteTexture.Dispose();
             var result = new DoubleBufferedTexture(Device, Size, false, IncompleteTexture, CreateTexture(Device, Size, Pool.Default));
             // And since we already have a result upload the texture immediately
             result.UpdateTexture();
             return(result);
         }
         else
         {
             // Write hasn't been called yet - stay in the degraded state
             return(this);
         }
     }
     else
     {
         // Juhu, we're not degraded
         UpdateTexture();
         return(this);
     }
 }