[WinCairo] Accelerated compositing should be disabled when graphics card does not...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Feb 2015 22:48:27 +0000 (22:48 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Feb 2015 22:48:27 +0000 (22:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=140667

Patch by peavo@outlook.com <peavo@outlook.com> on 2015-02-11
Reviewed by Alex Christensen.

* WebCoreSupport/AcceleratedCompositingContext.cpp:
(AcceleratedCompositingContext::scrollNonCompositedContents):
(AcceleratedCompositingContext::acceleratedCompositingAvailable):
* WebCoreSupport/AcceleratedCompositingContext.h:
* WebView.cpp:
(WebView::notifyPreferencesChanged):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@179962 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/win/ChangeLog
Source/WebKit/win/WebCoreSupport/AcceleratedCompositingContext.cpp
Source/WebKit/win/WebCoreSupport/AcceleratedCompositingContext.h
Source/WebKit/win/WebView.cpp

index 87149fa..8bdad31 100644 (file)
@@ -1,3 +1,17 @@
+2015-02-11  peavo@outlook.com  <peavo@outlook.com>
+
+        [WinCairo] Accelerated compositing should be disabled when graphics card does not support it.
+        https://bugs.webkit.org/show_bug.cgi?id=140667
+
+        Reviewed by Alex Christensen.
+
+        * WebCoreSupport/AcceleratedCompositingContext.cpp:
+        (AcceleratedCompositingContext::scrollNonCompositedContents):
+        (AcceleratedCompositingContext::acceleratedCompositingAvailable):
+        * WebCoreSupport/AcceleratedCompositingContext.h:
+        * WebView.cpp:
+        (WebView::notifyPreferencesChanged):
+
 2015-02-09  Brent Fulgham  <bfulgham@apple.com>
 
         AX: [Win] OBJID_CLIENT comparisons broken in 64-bit builds
index a7157ea..b3e375d 100644 (file)
 
 #include "WebView.h"
 
+#include <WebCore/DefWndProcWindowClass.h>
 #include <WebCore/Document.h>
 #include <WebCore/Frame.h>
 #include <WebCore/FrameView.h>
 #include <WebCore/GraphicsLayerTextureMapper.h>
+#include <WebCore/HWndDC.h>
 #include <WebCore/MainFrame.h>
 #include <WebCore/Page.h>
 #include <WebCore/Settings.h>
@@ -243,6 +245,77 @@ void AcceleratedCompositingContext::scrollNonCompositedContents(const IntRect& s
     scheduleLayerFlush();
 }
 
+bool AcceleratedCompositingContext::acceleratedCompositingAvailable()
+{
+    const int width = 10;
+    const int height = 10;
+
+    // Create test window to render texture in.
+    HWND testWindow = ::CreateWindowEx(WS_EX_NOACTIVATE, defWndProcWindowClassName(), L"AcceleratedCompositingTesterWindow", WS_POPUP | WS_VISIBLE | WS_DISABLED, -width, -height, width, height, 0, 0, 0, 0);
+
+    if (!testWindow)
+        return false;
+
+    // Create GL context.
+    std::unique_ptr<WebCore::GLContext> context = GLContext::createContextForWindow(testWindow, GLContext::sharingContext());
+
+    if (!context) {
+        ::DestroyWindow(testWindow);
+        return false;
+    }
+
+    context->makeContextCurrent();
+
+    std::unique_ptr<WebCore::TextureMapper> textureMapper = TextureMapperGL::create(TextureMapper::OpenGLMode);
+
+    if (!textureMapper) {
+        ::DestroyWindow(testWindow);
+        return false;
+    }
+
+    // Create texture.
+    RefPtr<BitmapTexture> texture = textureMapper->createTexture();
+
+    if (!texture) {
+        ::DestroyWindow(testWindow);
+        return false;
+    }
+
+    texture->reset(IntSize(width, height));
+
+    // Copy bitmap data to texture.
+    const int bitmapSize = width * height;
+    int data[bitmapSize];
+    const COLORREF colorRed = RGB(255, 0, 0);
+    const COLORREF colorGreen = RGB(0, 255, 0);
+    for (int i = 0; i < bitmapSize; i++)
+        data[i] = colorGreen;
+    IntRect targetRect(0, 0, width, height);
+    IntPoint offset(0, 0);
+    int bytesPerLine = width * 4;
+    BitmapTexture::UpdateContentsFlag flags = BitmapTexture::UpdateCanModifyOriginalImageData;
+    texture->updateContents(data, targetRect, offset, bytesPerLine, flags);
+
+    // Render texture.
+    textureMapper->beginPainting();
+    FloatRect rect(0, 0, width, height);
+    textureMapper->drawTexture(*texture, rect);
+    textureMapper->endPainting();
+
+    // Set color of pixel (0, 0) to red, to make sure it is different from the bitmap color.
+    HWndDC hdc(testWindow);
+    ::SetPixel(hdc, 0, 0, colorRed);
+
+    context->swapBuffers();
+
+    // Check if pixel (0, 0) has expected color.
+    COLORREF pixelColor = ::GetPixel(hdc, 0, 0);
+
+    ::DestroyWindow(testWindow);
+
+    return pixelColor == colorGreen;
+}
+
 void AcceleratedCompositingContext::scheduleLayerFlush()
 {
     if (!enabled())
index fc39ce0..9a11428 100644 (file)
@@ -65,6 +65,8 @@ public:
     bool flushPendingLayerChangesSoon();
     void scrollNonCompositedContents(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
 
+    static bool acceleratedCompositingAvailable();
+
 private:
     WebView& m_webView;
     std::unique_ptr<WebCore::GLContext> m_context;
index fc8551a..539bda6 100644 (file)
@@ -5051,6 +5051,10 @@ HRESULT WebView::notifyPreferencesChanged(IWebNotification* notification)
     hr = prefsPrivate->acceleratedCompositingEnabled(&enabled);
     if (FAILED(hr))
         return hr;
+#if USE(TEXTURE_MAPPER_GL)
+    static bool acceleratedCompositingAvailable = AcceleratedCompositingContext::acceleratedCompositingAvailable();
+    enabled = enabled && acceleratedCompositingAvailable;
+#endif
     settings.setAcceleratedCompositingEnabled(enabled);
 
     hr = prefsPrivate->showDebugBorders(&enabled);