Browse Source

More web view refactoring

Josh Engebretson 10 years ago
parent
commit
54ec595739

+ 0 - 7
Source/Atomic/UI/UISceneView.cpp

@@ -70,13 +70,6 @@ UISceneView::UISceneView(Context* context, bool createWidget) : UIWidget(context
 
 
 UISceneView::~UISceneView()
 UISceneView::~UISceneView()
 {
 {
-    // FIXME: need to refactor Light2D viewport handling
-    if (viewport_.NotNull())
-    {
-        RenderPath* renderpath = viewport_->GetRenderPath();
-        if (renderpath)
-            renderpath->RemoveCommands("Light2D");
-    }
 
 
 }
 }
 
 

+ 49 - 16
Source/AtomicWebView/UIWebView.cpp

@@ -22,6 +22,10 @@
 
 
 #include <Atomic/UI/UIRenderer.h>
 #include <Atomic/UI/UIRenderer.h>
 
 
+#include "WebClient.h"
+#include "WebTexture2D.h"
+#include "WebBrowserHost.h"
+
 #include "UIWebView.h"
 #include "UIWebView.h"
 
 
 using namespace tb;
 using namespace tb;
@@ -61,23 +65,20 @@ public:
         TBRect rect = GetRect();
         TBRect rect = GetRect();
         rect.x = rect.y = 0;
         rect.x = rect.y = 0;
         ConvertToRoot(rect.x, rect.y);
         ConvertToRoot(rect.x, rect.y);
-        IntVector2 size; /* = webView_->GetSize();*/
-
-        if (size.x_ != rect.w || size.y_ != rect.h)
-        {
-            size.x_ = rect.w;
-            size.y_ = rect.h;
 
 
-            webView_->SetResizeRequired();
-            // early out here, responsible for flicker
-            // https://github.com/AtomicGameEngine/AtomicGameEngine/issues/115
-            return;
-        }
+        IntRect size = webView_->GetRect();
 
 
         float* data = &vertexData_[0];
         float* data = &vertexData_[0];
 
 
         UI* ui = webView_->GetSubsystem<UI>();
         UI* ui = webView_->GetSubsystem<UI>();
 
 
+        WebTexture2D* tex = webView_->GetWebTexture2D();
+
+        tex->SetCurrentSize(rect.w, rect.h);
+
+        float umax = (float)tex->GetCurrentWidth()/(float)tex->GetMaxWidth();
+        float vmax = (float)tex->GetCurrentHeight()/(float)tex->GetMaxHeight();
+
         float color;
         float color;
         float fopacity = GetOpacity() * ui->GetRenderer()->GetOpacity();
         float fopacity = GetOpacity() * ui->GetRenderer()->GetOpacity();
         unsigned char opacity = (unsigned char) (fopacity* 255.0f);
         unsigned char opacity = (unsigned char) (fopacity* 255.0f);
@@ -90,6 +91,15 @@ public:
         data[27] = color;
         data[27] = color;
         data[33] = color;
         data[33] = color;
 
 
+        // UV
+        data[4] = 0; data[5] = 0;
+        data[10] = umax; data[11] = 0;
+        data[16] = umax; data[17] = vmax;
+        data[22] = 0; data[23] = 0;
+        data[28] = umax; data[29] = vmax;
+        data[34] = 0; data[35] = vmax;
+
+
         data[0] = rect.x;
         data[0] = rect.x;
         data[1] = rect.y;
         data[1] = rect.y;
 
 
@@ -108,10 +118,7 @@ public:
         data[30] = rect.x;
         data[30] = rect.x;
         data[31] = rect.y + rect.h;
         data[31] = rect.y + rect.h;
 
 
-        /*
-        webView_->GetSubsystem<UI>()->SubmitBatchVertexData(webView_->GetTexture(), vertexData_);
-        */
-
+        ui->SubmitBatchVertexData(tex->GetTexture2D(), vertexData_);
 
 
     }
     }
 
 
@@ -125,7 +132,6 @@ private:
 UIWebView::UIWebView(Context* context) : UIWidget(context, false),
 UIWebView::UIWebView(Context* context) : UIWidget(context, false),
     resizeRequired_(false)
     resizeRequired_(false)
 {
 {
-
     widget_ = new WebViewWidget();
     widget_ = new WebViewWidget();
     widget_->SetDelegate(this);
     widget_->SetDelegate(this);
     widget_->SetGravity(WIDGET_GRAVITY_ALL);
     widget_->SetGravity(WIDGET_GRAVITY_ALL);
@@ -133,6 +139,11 @@ UIWebView::UIWebView(Context* context) : UIWidget(context, false),
 
 
     UI* ui = GetSubsystem<UI>();
     UI* ui = GetSubsystem<UI>();
     ui->WrapWidget(this, widget_);
     ui->WrapWidget(this, widget_);
+
+    webClient_ = new WebClient(context);
+    webTexture_ = new WebTexture2D(context);
+    webClient_->SetWebRenderHandler(webTexture_);
+    webClient_->CreateBrowser();
 }
 }
 
 
 UIWebView::~UIWebView()
 UIWebView::~UIWebView()
@@ -140,5 +151,27 @@ UIWebView::~UIWebView()
 
 
 }
 }
 
 
+bool UIWebView::OnEvent(const TBWidgetEvent &ev)
+{
+    if (ev.type == EVENT_TYPE_POINTER_DOWN || ev.type == EVENT_TYPE_POINTER_UP)
+    {
+        webClient_->SendMouseClickEvent(ev.target_x, ev.target_y, 0, ev.type == EVENT_TYPE_POINTER_UP, 0);
+        return true;
+    }
+    else if (ev.type == EVENT_TYPE_POINTER_MOVE)
+    {
+        webClient_->SendMouseMoveEvent(ev.target_x, ev.target_y, 0);
+        return true;
+    }
+
+
+    return UIWidget::OnEvent(ev);
+}
+
+WebTexture2D* UIWebView::GetWebTexture2D() const
+{
+    return webTexture_;
+}
+
 
 
 }
 }

+ 14 - 0
Source/AtomicWebView/UIWebView.h

@@ -22,12 +22,19 @@
 
 
 #pragma once
 #pragma once
 
 
+#include <TurboBadger/tb_widgets.h>
+
 #include <Atomic/UI/UI.h>
 #include <Atomic/UI/UI.h>
 #include <Atomic/UI/UIWidget.h>
 #include <Atomic/UI/UIWidget.h>
 
 
+#include <Atomic/Graphics/Texture2D.h>
+
 namespace Atomic
 namespace Atomic
 {
 {
 
 
+class WebClient;
+class WebTexture2D;
+
 class UIWebView : public UIWidget
 class UIWebView : public UIWidget
 {
 {
     OBJECT(UIWebView)
     OBJECT(UIWebView)
@@ -39,12 +46,19 @@ public:
 
 
     void SetResizeRequired() { resizeRequired_  = true; }
     void SetResizeRequired() { resizeRequired_  = true; }
 
 
+    WebTexture2D* GetWebTexture2D() const;
+
 protected:
 protected:
 
 
+    bool OnEvent(const tb::TBWidgetEvent &ev);
+
 private:
 private:
 
 
     bool resizeRequired_;
     bool resizeRequired_;
 
 
+    SharedPtr<WebClient> webClient_;
+    SharedPtr<WebTexture2D> webTexture_;
+
 };
 };
 
 
 }
 }

+ 1 - 99
Source/AtomicWebView/WebBrowserHost.cpp

@@ -23,11 +23,7 @@
 namespace Atomic
 namespace Atomic
 {
 {
 
 
-#ifdef ATOMIC_PLATFORM_OSX
-void* GetNSWindowContentView(void* window);
-#endif
-
-class WebBrowserHostPrivate : public CefLifeSpanHandler
+class WebBrowserHostPrivate
 {
 {
     friend class WebBrowserHost;
     friend class WebBrowserHost;
 
 
@@ -44,70 +40,8 @@ public:
         host_ = 0;
         host_ = 0;
     }
     }
 
 
-    // CefLifeSpanHandler methods:
-    virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE
-    {
-        CEF_REQUIRE_UI_THREAD();
-        browsers_.Push(browser);
-    }
-
-    virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE
-    {
-        return false;
-    }
-
-    virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE
-    {
-        CEF_REQUIRE_UI_THREAD();
-
-        // Remove from the list of existing browsers.
-        Vector<CefRefPtr<CefBrowser>>::Iterator itr = browsers_.Begin();
-        while (itr != browsers_.End())
-        {
-            if ((*itr)->IsSame(browser))
-            {
-                browsers_.Erase(itr);
-                break;
-            }
-
-            itr++;
-        }
-    }
-
-    void CloseAllBrowsers(bool force_close)
-    {
-        if (!CefCurrentlyOn(TID_UI))
-        {
-            // Execute on the UI thread.
-            CefPostTask(TID_UI,
-                        base::Bind(&WebBrowserHostPrivate::CloseAllBrowsers, this, force_close));
-
-            return;
-        }
-
-        if (!browsers_.Size())
-            return;
-
-        // make a copy of vector, as we'll be erasing as we go
-        Vector<CefRefPtr<CefBrowser>> browsers = browsers_;
-
-        Vector<CefRefPtr<CefBrowser>>::Iterator itr = browsers.Begin();
-
-        while (itr != browsers.End())
-        {
-            (*itr)->GetHost()->CloseBrowser(force_close);
-            itr++;
-        }
-
-        browsers_.Clear();
-    }
-
-    IMPLEMENT_REFCOUNTING(WebBrowserHostPrivate);
-
 private:
 private:
 
 
-    Vector<CefRefPtr<CefBrowser>> browsers_;
-
     WeakPtr<WebBrowserHost> host_;
     WeakPtr<WebBrowserHost> host_;
 
 
 };
 };
@@ -143,7 +77,6 @@ WebBrowserHost::WebBrowserHost(Context* context) : Object (context)
     }
     }
 
 
     d_ = new WebBrowserHostPrivate(this);
     d_ = new WebBrowserHostPrivate(this);
-    d_->AddRef();
 
 
     SubscribeToEvent(E_BEGINFRAME, HANDLER(WebBrowserHost, HandleBeginFrame));
     SubscribeToEvent(E_BEGINFRAME, HANDLER(WebBrowserHost, HandleBeginFrame));
 
 
@@ -151,40 +84,9 @@ WebBrowserHost::WebBrowserHost(Context* context) : Object (context)
 
 
 WebBrowserHost::~WebBrowserHost()
 WebBrowserHost::~WebBrowserHost()
 {
 {
-    d_->CloseAllBrowsers(true);
-    d_->Release();
     CefShutdown();
     CefShutdown();
 }
 }
 
 
-CefLifeSpanHandler* WebBrowserHost::GetCefLifeSpanHandler()
-{
-    return d_;
-}
-
-bool WebBrowserHost::CreateBrowser(WebClient* webClient)
-{
-    CefWindowInfo windowInfo;
-    CefBrowserSettings browserSettings;
-
-    Graphics* graphics = GetSubsystem<Graphics>();
-
-    SDL_Window* sdlWindow = static_cast<SDL_Window*>(graphics->GetSDLWindow());
-    SDL_SysWMinfo info;
-    SDL_VERSION(&info.version);
-
-    if(SDL_GetWindowWMInfo(sdlWindow, &info))
-    {
-        NSView* view = (NSView*) GetNSWindowContentView(info.info.cocoa.window);
-        windowInfo.SetAsWindowless(view, false);
-
-        return CefBrowserHost::CreateBrowser(windowInfo, (CefClient*) webClient->d_,
-                                             "https://html5test.com/", browserSettings, nullptr);
-    }
-
-    return false;
-
-}
-
 void WebBrowserHost::HandleBeginFrame(StringHash eventType, VariantMap& eventData)
 void WebBrowserHost::HandleBeginFrame(StringHash eventType, VariantMap& eventData)
 {
 {
     CefDoMessageLoopWork();
     CefDoMessageLoopWork();

+ 0 - 6
Source/AtomicWebView/WebBrowserHost.h

@@ -3,8 +3,6 @@
 
 
 #pragma once
 #pragma once
 
 
-class CefLifeSpanHandler;
-
 namespace Atomic
 namespace Atomic
 {
 {
 
 
@@ -21,10 +19,6 @@ public:
     /// Destruct.
     /// Destruct.
     virtual ~WebBrowserHost();
     virtual ~WebBrowserHost();
 
 
-    bool CreateBrowser(WebClient* webClient);
-
-    CefLifeSpanHandler* GetCefLifeSpanHandler();
-
 private:
 private:
 
 
     void HandleBeginFrame(StringHash eventType, VariantMap& eventData);
     void HandleBeginFrame(StringHash eventType, VariantMap& eventData);

+ 168 - 2
Source/AtomicWebView/WebClient.cpp

@@ -1,6 +1,20 @@
 
 
+#include <SDL/include/SDL.h>
+#include <ThirdParty/SDL/include/SDL_syswm.h>
+
+#include <ThirdParty/CEF/include/cef_app.h>
 #include <ThirdParty/CEF/include/cef_client.h>
 #include <ThirdParty/CEF/include/cef_client.h>
+#include <ThirdParty/CEF/include/cef_browser.h>
+#include <ThirdParty/CEF/include/wrapper/cef_helpers.h>
+#include <ThirdParty/CEF/include/base/cef_bind.h>
+#include <ThirdParty/CEF/include/wrapper/cef_closure_task.h>
+
 
 
+#include <Atomic/Core/ProcessUtils.h>
+#include <Atomic/Core/CoreEvents.h>
+#include <Atomic/IO/Log.h>
+
+#include <Atomic/Graphics/Graphics.h>
 
 
 #include "WebBrowserHost.h"
 #include "WebBrowserHost.h"
 #include "WebClient.h"
 #include "WebClient.h"
@@ -8,7 +22,11 @@
 namespace Atomic
 namespace Atomic
 {
 {
 
 
-class WebClientPrivate : public CefClient
+#ifdef ATOMIC_PLATFORM_OSX
+void* GetNSWindowContentView(void* window);
+#endif
+
+class WebClientPrivate : public CefClient, public CefLifeSpanHandler
 {
 {
     friend class WebClient;
     friend class WebClient;
 
 
@@ -33,7 +51,7 @@ public:
 
 
     virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE
     virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE
     {
     {
-        return webBrowserHost_->GetCefLifeSpanHandler();
+        return this;
     }
     }
 
 
     bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
     bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
@@ -43,12 +61,99 @@ public:
         return false;
         return false;
     }
     }
 
 
+    bool CreateBrowser()
+    {
+        CefWindowInfo windowInfo;
+        CefBrowserSettings browserSettings;
+
+        Graphics* graphics = webClient_->GetSubsystem<Graphics>();
+
+        SDL_Window* sdlWindow = static_cast<SDL_Window*>(graphics->GetSDLWindow());
+        SDL_SysWMinfo info;
+        SDL_VERSION(&info.version);
+
+        if(SDL_GetWindowWMInfo(sdlWindow, &info))
+        {
+            NSView* view = (NSView*) GetNSWindowContentView(info.info.cocoa.window);
+            windowInfo.SetAsWindowless(view, false);
+
+            CefRefPtr<CefBrowser> browser = CefBrowserHost::CreateBrowserSync(windowInfo, this,
+                                                                              "https://html5test.com/", browserSettings, nullptr);
+
+            if (!browser.get())
+                return false;
+
+            browsers_.Push(browser);
+
+            return true;
+        }
+
+        return false;
+
+    }
+
+    // CefLifeSpanHandler methods:
+    virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE
+    {
+        CEF_REQUIRE_UI_THREAD();
+    }
+
+    virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE
+    {
+        return false;
+    }
+
+    virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE
+    {
+        CEF_REQUIRE_UI_THREAD();
+
+        // Remove from the list of existing browsers.
+        Vector<CefRefPtr<CefBrowser>>::Iterator itr = browsers_.Begin();
+        while (itr != browsers_.End())
+        {
+            if ((*itr)->IsSame(browser))
+            {
+                browsers_.Erase(itr);
+                break;
+            }
+
+            itr++;
+        }
+    }
+
+    void CloseAllBrowsers(bool force_close)
+    {
+        if (!CefCurrentlyOn(TID_UI))
+        {
+            // Execute on the UI thread.
+            CefPostTask(TID_UI,
+                        base::Bind(&WebClientPrivate::CloseAllBrowsers, this, force_close));
+
+            return;
+        }
+
+        if (!browsers_.Size())
+            return;
 
 
+        // make a copy of vector, as we'll be erasing as we go
+        Vector<CefRefPtr<CefBrowser>> browsers = browsers_;
+
+        Vector<CefRefPtr<CefBrowser>>::Iterator itr = browsers.Begin();
+
+        while (itr != browsers.End())
+        {
+            (*itr)->GetHost()->CloseBrowser(force_close);
+            itr++;
+        }
+
+        browsers_.Clear();
+    }
 
 
     IMPLEMENT_REFCOUNTING(WebClientPrivate);
     IMPLEMENT_REFCOUNTING(WebClientPrivate);
 
 
 private:
 private:
 
 
+    Vector<CefRefPtr<CefBrowser>> browsers_;
     WeakPtr<WebBrowserHost> webBrowserHost_;
     WeakPtr<WebBrowserHost> webBrowserHost_;
     WeakPtr<WebClient> webClient_;
     WeakPtr<WebClient> webClient_;
 
 
@@ -66,10 +171,71 @@ WebClient::~WebClient()
     //d_->Release();
     //d_->Release();
 }
 }
 
 
+void WebClient::SendMouseClickEvent(int x, int y, unsigned button, bool mouseUp, unsigned modifier) const
+{
+    if (!d_->browsers_.Size())
+        return;
+
+    CefRefPtr<CefBrowser> browser = d_->browsers_[0];
+    CefRefPtr<CefBrowserHost> host = browser->GetHost();
+
+    CefMouseEvent mevent;
+    mevent.x = x;
+    mevent.y = y;
+    mevent.modifiers = 0;
+
+    //MBT_LEFT   = 0,
+    //MBT_MIDDLE,
+    //MBT_RIGHT,
+
+    host->SendMouseClickEvent(mevent, (CefBrowserHost::MouseButtonType) button, mouseUp, 1);
+
+}
+
+void WebClient::SendMouseMoveEvent(int x, int y, unsigned modifier, bool mouseLeave) const
+{
+    if (!d_->browsers_.Size())
+        return;
+
+    CefRefPtr<CefBrowser> browser = d_->browsers_[0];
+    CefRefPtr<CefBrowserHost> host = browser->GetHost();
+
+    CefMouseEvent mevent;
+    mevent.x = x;
+    mevent.y = y;
+    mevent.modifiers = 0;
+
+    //MBT_LEFT   = 0,
+    //MBT_MIDDLE,
+    //MBT_RIGHT,
+
+    host->SendMouseMoveEvent(mevent, mouseLeave);
+
+}
+
+void WebClient::WasResized()
+{
+    if (!d_->browsers_.Size())
+        return;
+
+    d_->browsers_[0]->GetHost()->WasResized();;
+}
+
+bool WebClient::CreateBrowser()
+{
+    return d_->CreateBrowser();
+}
+
 void WebClient::SetWebRenderHandler(WebRenderHandler* handler)
 void WebClient::SetWebRenderHandler(WebRenderHandler* handler)
 {
 {
+    handler->SetWebClient(this);
     renderHandler_ = handler;
     renderHandler_ = handler;
 }
 }
 
 
+CefClient* WebClient::GetCefClient()
+{
+    return d_;
+}
+
 
 
 }
 }

+ 12 - 0
Source/AtomicWebView/WebClient.h

@@ -4,6 +4,8 @@
 
 
 #pragma once
 #pragma once
 
 
+class CefClient;
+
 namespace Atomic
 namespace Atomic
 {
 {
 
 
@@ -23,8 +25,18 @@ public:
     /// Destruct.
     /// Destruct.
     virtual ~WebClient();
     virtual ~WebClient();
 
 
+    // call once initialized with handlers
+    bool CreateBrowser();
+
     void SetWebRenderHandler(WebRenderHandler* handler);
     void SetWebRenderHandler(WebRenderHandler* handler);
 
 
+    CefClient* GetCefClient();
+
+    void WasResized();
+
+    void SendMouseClickEvent(int x, int y, unsigned button, bool mouseUp, unsigned modifier) const;
+    void SendMouseMoveEvent(int x, int y, unsigned modifier, bool mouseLeave = false) const;
+
 private:
 private:
 
 
     SharedPtr<WebRenderHandler> renderHandler_;
     SharedPtr<WebRenderHandler> renderHandler_;

+ 17 - 1
Source/AtomicWebView/WebRenderHandler.cpp

@@ -3,13 +3,18 @@
 #include <Atomic/Graphics/Graphics.h>
 #include <Atomic/Graphics/Graphics.h>
 #include <Atomic/Graphics/Technique.h>
 #include <Atomic/Graphics/Technique.h>
 
 
+#include "WebClient.h"
 #include "WebRenderHandler.h"
 #include "WebRenderHandler.h"
 
 
 namespace Atomic
 namespace Atomic
 {
 {
 
 
 
 
-WebRenderHandler::WebRenderHandler(Context* context) : Object (context)
+WebRenderHandler::WebRenderHandler(Context* context) : Object (context),
+    currentWidth_(0),
+    currentHeight_(0),
+    maxHeight_(0),
+    maxWidth_(0)
 {
 {
 }
 }
 
 
@@ -18,5 +23,16 @@ WebRenderHandler::~WebRenderHandler()
 
 
 }
 }
 
 
+void WebRenderHandler::SetWebClient(WebClient* webClient)
+{
+    webClient_ = webClient;
+}
+
+WebClient* WebRenderHandler::GetWebClient() const
+{
+    return webClient_;
+}
+
+
 
 
 }
 }

+ 7 - 6
Source/AtomicWebView/WebRenderHandler.h

@@ -9,6 +9,8 @@ class CefRenderHandler;
 namespace Atomic
 namespace Atomic
 {
 {
 
 
+class WebClient;
+
 class ATOMIC_API WebRenderHandler : public Object
 class ATOMIC_API WebRenderHandler : public Object
 {
 {
     OBJECT(WebRenderHandler);
     OBJECT(WebRenderHandler);
@@ -20,18 +22,15 @@ public:
     /// Destruct.
     /// Destruct.
     virtual ~WebRenderHandler();
     virtual ~WebRenderHandler();
 
 
-    virtual void SetCurrentWidth(unsigned width) = 0;
-    virtual void SetCurrentHeight(unsigned height) = 0;
-
-    virtual void SetMaxWidth(unsigned width) = 0;
-    virtual void SetMaxHeight(unsigned height) = 0;
-
     unsigned GetCurrentWidth() const { return currentWidth_; }
     unsigned GetCurrentWidth() const { return currentWidth_; }
     unsigned GetCurrentHeight() const { return currentHeight_; }
     unsigned GetCurrentHeight() const { return currentHeight_; }
 
 
     unsigned GetMaxWidth() const { return maxWidth_; }
     unsigned GetMaxWidth() const { return maxWidth_; }
     unsigned GetMaxHeight() const { return maxHeight_; }
     unsigned GetMaxHeight() const { return maxHeight_; }
 
 
+    void SetWebClient(WebClient* webClient);
+    WebClient* GetWebClient() const;
+
     virtual CefRenderHandler* GetCEFRenderHandler() = 0;
     virtual CefRenderHandler* GetCEFRenderHandler() = 0;
 
 
 protected:
 protected:
@@ -42,6 +41,8 @@ protected:
     unsigned maxHeight_;
     unsigned maxHeight_;
     unsigned maxWidth_;
     unsigned maxWidth_;
 
 
+    WeakPtr<WebClient> webClient_;
+
 
 
 };
 };
 
 

+ 40 - 18
Source/AtomicWebView/WebTexture2D.cpp

@@ -29,9 +29,30 @@ public:
     }
     }
 
 
     void OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList &dirtyRects,
     void OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList &dirtyRects,
-                           const void *buffer, int width, int height) OVERRIDE
+                 const void *buffer, int width, int height) OVERRIDE
     {
     {
-        webTexture2D_->texture_->SetData(0, 0, 0, width, height, buffer);
+
+        if (type == PET_VIEW)
+        {
+            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:
 private:
@@ -45,18 +66,14 @@ WebTexture2D::WebTexture2D(Context* context, int width, int height) : WebRenderH
     d_ = new WebTexture2DPrivate(this);
     d_ = new WebTexture2DPrivate(this);
     d_->AddRef();
     d_->AddRef();
 
 
-    ResourceCache* cache = GetSubsystem<ResourceCache>();
-
-    currentWidth_ = maxWidth_ = width;
-    currentHeight_ = maxHeight_ = height;
-
     texture_ = new Texture2D(context_);
     texture_ = new Texture2D(context_);
     texture_->SetNumLevels(1);
     texture_->SetNumLevels(1);
-    texture_->SetSize(width, height, Graphics::GetBGRAFormat(), TEXTURE_DYNAMIC);
     texture_->SetFilterMode(FILTER_BILINEAR);
     texture_->SetFilterMode(FILTER_BILINEAR);
 
 
-    material_ = new Material(context_);
+    SetCurrentSize(width, height);
 
 
+    ResourceCache* cache = GetSubsystem<ResourceCache>();
+    material_ = new Material(context_);
     material_->SetTechnique(0, cache->GetResource<Technique>("Techniques/DiffUnlit.xml"));
     material_->SetTechnique(0, cache->GetResource<Technique>("Techniques/DiffUnlit.xml"));
     material_->SetTexture(TU_DIFFUSE, texture_);
     material_->SetTexture(TU_DIFFUSE, texture_);
 }
 }
@@ -71,23 +88,28 @@ CefRenderHandler* WebTexture2D::GetCEFRenderHandler()
     return d_;
     return d_;
 }
 }
 
 
-void WebTexture2D::SetCurrentWidth(unsigned width)
-{
-
-}
 
 
-void WebTexture2D::SetCurrentHeight(unsigned height)
+void WebTexture2D::SetCurrentSize(unsigned width, unsigned height)
 {
 {
+    currentWidth_ = width;
+    currentHeight_ = height;
 
 
-}
+    unsigned newMaxWidth = NextPowerOfTwo(width);
+    unsigned newMaxHeight = NextPowerOfTwo(height);
 
 
-void WebTexture2D::SetMaxWidth(unsigned width)
-{
+    if (newMaxWidth != maxWidth_ || newMaxHeight != maxHeight_)
+    {
+        SetMaxSize(newMaxWidth, newMaxHeight);
+    }
 
 
 }
 }
 
 
-void WebTexture2D::SetMaxHeight(unsigned height)
+void WebTexture2D::SetMaxSize(unsigned width, unsigned height)
 {
 {
+    maxWidth_ = width;
+    maxHeight_ = height;
+
+    texture_->SetSize(maxWidth_, maxHeight_, Graphics::GetBGRAFormat(), TEXTURE_DYNAMIC);
 
 
 }
 }
 
 

+ 2 - 5
Source/AtomicWebView/WebTexture2D.h

@@ -24,11 +24,8 @@ public:
     /// Destruct.
     /// Destruct.
     virtual ~WebTexture2D();
     virtual ~WebTexture2D();
 
 
-    virtual void SetCurrentWidth(unsigned width);
-    virtual void SetCurrentHeight(unsigned height);
-
-    virtual void SetMaxWidth(unsigned width);
-    virtual void SetMaxHeight(unsigned height);
+    virtual void SetCurrentSize(unsigned width, unsigned height);
+    virtual void SetMaxSize(unsigned width, unsigned height);
 
 
     CefRenderHandler* GetCEFRenderHandler();
     CefRenderHandler* GetCEFRenderHandler();