Skip to content

Commit

Permalink
EP-141 Optimize texture uploading #close
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksey Fomkin committed Apr 18, 2019
1 parent 9580547 commit 0f76e2d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
14 changes: 9 additions & 5 deletions Assets/Resources/Expload/OffscreenCEF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ namespace Expload
public class OffscreenCEF : MonoBehaviour
{
[SerializeField]
private string url = "https://fomkin.org/select.html";
//private string url = "http://localhost:8087/ui/overlay/";
private string url = "http://localhost:8087/ui/overlay/";

[Space]
[SerializeField]
Expand Down Expand Up @@ -48,6 +47,7 @@ private void Start()
{
var ev = new CefKeyEvent();
ev.WindowsKeyCode = charCode;
ev.Character = charCode;
ev.EventType = CefKeyEventType.KeyDown;
cefClient.SendKey(ev);
ev.EventType = CefKeyEventType.Char;
Expand Down Expand Up @@ -106,7 +106,12 @@ private void StartCef()
Debug.Log("Start with window: " + this.windowWidth + ", " + this.windowHeight);

// Initialize some of the custom interactions with the browser process.
this.cefClient = new OffscreenCEFClient(this.windowWidth, this.windowHeight, this.hideScrollbars);
this.cefClient = new OffscreenCEFClient(
this.windowWidth,
this.windowHeight,
this.hideScrollbars,
this.BrowserTexture
);

// Start up the browser instance.
CefBrowserHost.CreateBrowser(cefWindowInfo, this.cefClient, cefBrowserSettings, string.IsNullOrEmpty(this.url) ? "http://www.google.com" : this.url);
Expand Down Expand Up @@ -134,7 +139,6 @@ void FixedUpdate()
if (!this.shouldQuit)
{
CefRuntime.DoMessageLoopWork();
this.cefClient.UpdateTexture(this.BrowserTexture);
}
}

Expand Down Expand Up @@ -186,6 +190,6 @@ void Update()
//}
}

#endif
#endif
}
}
13 changes: 8 additions & 5 deletions Assets/Resources/Expload/OffscreenCEFClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ internal class OffscreenCEFClient : CefClient
private byte[] sPopupPixelBufer;
private CefRectangle _popupSize;
private bool _popupShow;
private Texture2D _texture;

private CefBrowserHost sHost;

public OffscreenCEFClient(int windowWidth, int windowHeight, bool hideScrollbars = false)
public OffscreenCEFClient(int windowWidth, int windowHeight, bool hideScrollbars, Texture2D texture)
{
this._texture = texture;
this._windowWidth = windowWidth;
this._windowHeight = windowHeight;
this._loadHandler = new OffscreenLoadHandler(this, hideScrollbars);
Expand All @@ -34,7 +36,7 @@ public OffscreenCEFClient(int windowWidth, int windowHeight, bool hideScrollbars
Debug.Log("Constructed Offscreen Client");
}

public void UpdateTexture(Texture2D pTexture)
private void UpdateTexture()
{
if (this.sHost == null)
return;
Expand All @@ -54,8 +56,8 @@ public void UpdateTexture(Texture2D pTexture)
}
}

pTexture.LoadRawTextureData(buffer);
pTexture.Apply(false);
_texture.LoadRawTextureData(buffer);
_texture.Apply(false);
}

public void SendMouseMove(CefMouseEvent e)
Expand Down Expand Up @@ -195,6 +197,7 @@ protected override bool GetViewRect(CefBrowser browser, ref CefRectangle rect)
protected override void OnPopupShow(CefBrowser browser, bool show)
{
client._popupShow = show;
client.UpdateTexture();
}

protected override void OnPopupSize(CefBrowser browser, CefRectangle rect)
Expand All @@ -216,8 +219,8 @@ protected override void OnPaint(CefBrowser browser, CefPaintElementType type, Ce
targetBuffer = client.sPopupPixelBufer;
}


Marshal.Copy(buffer, targetBuffer, 0, targetBuffer.Length);
client.UpdateTexture();
}

protected override bool GetScreenInfo(CefBrowser browser, CefScreenInfo screenInfo)
Expand Down

0 comments on commit 0f76e2d

Please sign in to comment.