Browse Source

WebView resizing

Josh Engebretson 10 years ago
parent
commit
c6ee19427b

+ 1 - 0
Source/AtomicWebView/UIWebView.cpp

@@ -20,6 +20,7 @@
 // THE SOFTWARE.
 //
 
+#include <Atomic/IO/Log.h>
 #include <Atomic/UI/UIRenderer.h>
 
 #include "WebClient.h"

+ 1 - 1
Source/AtomicWebView/WebClient.cpp

@@ -78,7 +78,7 @@ public:
             windowInfo.SetAsWindowless(view, false);
 
             CefRefPtr<CefBrowser> browser = CefBrowserHost::CreateBrowserSync(windowInfo, this,
-                                                                              "https://html5test.com/", browserSettings, nullptr);
+                                                                              "https://youtube.com/", browserSettings, nullptr);
 
             if (!browser.get())
                 return false;

+ 22 - 20
Source/AtomicWebView/WebTexture2D.cpp

@@ -1,11 +1,15 @@
 #include <ThirdParty/CEF/include/cef_render_handler.h>
 
+#include <Atomic/IO/Log.h>
+
 #include <Atomic/Resource/ResourceCache.h>
 #include <Atomic/Graphics/Graphics.h>
 #include <Atomic/Graphics/Technique.h>
 
+#include "WebClient.h"
 #include "WebTexture2D.h"
 
+
 namespace Atomic
 {
 
@@ -37,22 +41,6 @@ public:
             webTexture2D_->texture_->SetData(0, 0, 0, width, height, buffer);
         }
 
-
-        /*
-        if (dirtyRects.size() == 1 && width == )
-            return;
-
-        int vwidth = width;
-        int vheight = height;
-
-        if (vwidth > webTexture2D_->texture_->GetWidth())
-            vwidth = webTexture2D_->texture_->GetWidth();
-
-        if (vheight > webTexture2D_->texture_->GetHeight())
-            vheight = webTexture2D_->texture_->GetHeight();
-
-
-        */
     }
 
 private:
@@ -91,26 +79,40 @@ CefRenderHandler* WebTexture2D::GetCEFRenderHandler()
 
 void WebTexture2D::SetCurrentSize(unsigned width, unsigned height)
 {
+    if (currentWidth_ == width && currentHeight_ == height)
+        return;
+
     currentWidth_ = width;
     currentHeight_ = height;
 
     unsigned newMaxWidth = NextPowerOfTwo(width);
     unsigned newMaxHeight = NextPowerOfTwo(height);
 
-    if (newMaxWidth != maxWidth_ || newMaxHeight != maxHeight_)
-    {
-        SetMaxSize(newMaxWidth, newMaxHeight);
-    }
+    SetMaxSize(newMaxWidth, newMaxHeight);
+
+    if (webClient_.NotNull())
+        webClient_->WasResized();
 
 }
 
 void WebTexture2D::SetMaxSize(unsigned width, unsigned height)
 {
+    if (maxWidth_ == width && height == maxHeight_)
+        return;
+
+    if (!IsPowerOfTwo(width) || !IsPowerOfTwo(height))
+    {
+        LOGERRORF("WebTexture2D::SetMaxSize - attempted to set size to %ux%u (must be a power of two)", width, height );
+        return;
+    }
+
     maxWidth_ = width;
     maxHeight_ = height;
 
     texture_->SetSize(maxWidth_, maxHeight_, Graphics::GetBGRAFormat(), TEXTURE_DYNAMIC);
 
+    LOGDEBUGF("WebTexture2D max size set: %u %u", maxWidth_, maxHeight_);
+
 }
 
 }