Skip to content

Commit

Permalink
Merge pull request #607 from gree/feature/set_margins_cache
Browse files Browse the repository at this point in the history
modified to perform SetMargins() only if its arguments change.
  • Loading branch information
KojiNakamaru authored Oct 19, 2020
2 parents 903b55d + 79e0afa commit 6f39615
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions plugins/WebViewObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public class WebViewObject : MonoBehaviour
Callback onLoaded;
Callback onHooked;
bool visibility;
bool alertDialogEnabled = true;
bool scrollBounceEnabled = true;
bool alertDialogEnabled;
bool scrollBounceEnabled;
int mMarginLeft;
int mMarginTop;
int mMarginRight;
Expand Down Expand Up @@ -93,6 +93,12 @@ void OnApplicationPause(bool paused)
webView.Call("OnApplicationPause", paused);
}

void Awake()
{
alertDialogEnabled = true;
scrollBounceEnabled = true;
}

void Update()
{
if (webView == null)
Expand Down Expand Up @@ -289,18 +295,18 @@ private static extern void _CWebViewPlugin_Reload(
[DllImport("__Internal")]
private static extern void _CWebViewPlugin_SetBasicAuthInfo(IntPtr instance, string userName, string password);
#elif UNITY_WEBGL
[DllImport("__Internal")]
private static extern void _gree_unity_webview_init(string name);
[DllImport("__Internal")]
private static extern void _gree_unity_webview_setMargins(string name, int left, int top, int right, int bottom);
[DllImport("__Internal")]
private static extern void _gree_unity_webview_setVisibility(string name, bool visible);
[DllImport("__Internal")]
private static extern void _gree_unity_webview_loadURL(string name, string url);
[DllImport("__Internal")]
private static extern void _gree_unity_webview_evaluateJS(string name, string js);
[DllImport("__Internal")]
private static extern void _gree_unity_webview_destroy(string name);
[DllImport("__Internal")]
private static extern void _gree_unity_webview_init(string name);
[DllImport("__Internal")]
private static extern void _gree_unity_webview_setMargins(string name, int left, int top, int right, int bottom);
[DllImport("__Internal")]
private static extern void _gree_unity_webview_setVisibility(string name, bool visible);
[DllImport("__Internal")]
private static extern void _gree_unity_webview_loadURL(string name, string url);
[DllImport("__Internal")]
private static extern void _gree_unity_webview_evaluateJS(string name, string js);
[DllImport("__Internal")]
private static extern void _gree_unity_webview_destroy(string name);
#endif

public static bool IsWebViewAvailable()
Expand Down Expand Up @@ -458,6 +464,13 @@ public void SetMargins(int left, int top, int right, int bottom, bool relative =
if (webView == null)
return;
#endif
if (mMarginLeft == left
&& mMarginTop == top
&& mMarginRight == right
&& mMarginBottom == bottom)
{
return;
}
mMarginLeft = left;
mMarginTop = top;
mMarginRight = right;
Expand Down Expand Up @@ -1023,11 +1036,13 @@ void Update()
textureDataBuffer = new byte[w * h * 4];
}
}
var gch = GCHandle.Alloc(textureDataBuffer, GCHandleType.Pinned);
_CWebViewPlugin_Render(webView, gch.AddrOfPinnedObject());
gch.Free();
texture.LoadRawTextureData(textureDataBuffer);
texture.Apply();
if (textureDataBuffer.Length > 0) {
var gch = GCHandle.Alloc(textureDataBuffer, GCHandleType.Pinned);
_CWebViewPlugin_Render(webView, gch.AddrOfPinnedObject());
gch.Free();
texture.LoadRawTextureData(textureDataBuffer);
texture.Apply();
}
}
}

Expand Down

0 comments on commit 6f39615

Please sign in to comment.