Changeset 87831 in webkit


Ignore:
Timestamp:
Jun 1, 2011 11:39:19 AM (13 years ago)
Author:
Adam Roben
Message:

Render accelerated content into a web process-owned child HWND

This allows us to use WKCACFView's far more efficient kWKCACFViewDrawingDestinationWindow
mode, which gives us asynchronous rendering on a background thread and doesn't require us to
read bits off the GPU back into system memory.

A new class, WKCACFViewWindow, represents the child HWND. The child HWND is placed at the
bottom of the z-order so it won't obscure any other child HWNDs (i.e., windowed plugins).
The child HWND is made transparent to mouse events so that WKView will continue to receive
mouse events even though it is obscured by the child HWND.

There is now a bunch of dead code in DrawingAreaImpl to handle our old rendering model. I'll
remove that in a future patch.

Fixes <http://webkit.org/b/58054> <rdar://problem/9249839> REGRESSION (WebKit2): Accelerated
CSS animations have a lower framerate than in WebKit1

Reviewed by Anders Carlsson.

  • Shared/LayerTreeContext.h: Added HWND member on Windows.
  • Shared/win/CoalescedWindowGeometriesUpdater.cpp:

(WebKit::CoalescedWindowGeometriesUpdater::updateGeometries):

  • Shared/win/CoalescedWindowGeometriesUpdater.h:

Added new BringToTopOrNot argument. Allows the caller to specify that all windows being
updated should also be brought to the top of the z-order.

  • Shared/win/LayerTreeContextWin.cpp:

(WebKit::LayerTreeContext::LayerTreeContext):
(WebKit::LayerTreeContext::~LayerTreeContext):
(WebKit::LayerTreeContext::encode):
(WebKit::LayerTreeContext::decode):
(WebKit::LayerTreeContext::isEmpty):
(WebKit::operator==):
Implemented based on new window member.

  • UIProcess/win/WebView.cpp:

(WebKit::WebView::WebView): Initialize new member.
(WebKit::WebView::onSizeEvent): Resize the layer host window to cover our entire view, if we
have one.
(WebKit::WebView::enterAcceleratedCompositingMode): Store, position, and show the layer host
window.
(WebKit::WebView::exitAcceleratedCompositingMode): Destroy the layer host window.
(WebKit::WebView::updateChildWindowGeometries): Updated for change to
CoalescedWindowGeometriesUpdater.

  • UIProcess/win/WebView.h: Added m_layerHostWindow member.
  • WebProcess/WebPage/LayerTreeHost.h: Added scheduleChildWindowGeometryUpdate.
  • WebProcess/WebPage/ca/win/LayerTreeHostCAWin.cpp:

(WebKit::LayerTreeHostCAWin::supportsAcceleratedCompositing): Simplified by using
WKCACFViewWindow.

(WebKit::LayerTreeHostCAWin::LayerTreeHostCAWin): Removed initialization of a removed
member.
(WebKit::LayerTreeHostCAWin::platformInitialize): Changed to use WKCACFViewWindow,
kWKCACFViewDrawingDestinationWindow, and to initialize the LayerTreeContext.
(WebKit::LayerTreeHostCAWin::invalidate): Leak our window and tell it to clean up after
itself. The UI process will take care of destroying the window when it finishes switching
out of accelerated compositing mode. Removed a WKCACFViewUpdate call that is now handled by
WKCACFViewWindow.
(WebKit::LayerTreeHostCAWin::scheduleChildWindowGeometryUpdate): Added. Calls through to
m_geometriesUpdater.
(WebKit::LayerTreeHostCAWin::sizeDidChange): Updated to use WKCACFViewWindow.
(WebKit::LayerTreeHostCAWin::contextDidChange): Update child window geometries now to keep
them (almost) in sync with the accelerated content. <http://webkit.org/b/61867> covers the
slight asynchrony that still exists.
(WebKit::LayerTreeHostCAWin::setRootCompositingLayer): Don't flush any changes when we don't
have a root layer. This prevents a flash of white when switching out of compositing mode.

  • WebProcess/WebPage/ca/win/LayerTreeHostCAWin.h: Added m_window and m_geometriesUpdater.

Removed code related to the old, synchronous display model.

  • WebProcess/WebPage/ca/win/WKCACFViewWindow.cpp: Added.

(WebKit::WKCACFViewWindow::WKCACFViewWindow): Initialize members and create our window.
(WebKit::WKCACFViewWindow::~WKCACFViewWindow): Destroy our window if needed.
(WebKit::WKCACFViewWindow::onCustomDestroy): Just call ::DestroyWindow.
(WebKit::WKCACFViewWindow::onDestroy): Tell our view not to render into our window anymore.
(WebKit::WKCACFViewWindow::onEraseBackground): Tell Windows not to erase us.
(WebKit::WKCACFViewWindow::onNCDestroy): Clear out m_window since it's now pointing to a
destroy window, and destroy ourselves if requested.
(WebKit::WKCACFViewWindow::onPaint): Tell the view to draw, then clear our invalid region.
(WebKit::WKCACFViewWindow::onPrintClient): Tell our view to draw into the given HDC.
(WebKit::WKCACFViewWindow::registerClass): Register our class (duh).
(WebKit::WKCACFViewWindow::staticWndProc): Get the WKCACFViewWindow pointer, or store the
pointer if needed, then call through to wndProc.
(WebKit::WKCACFViewWindow::wndProc): Call out to the appropriate handler function.

  • WebProcess/WebPage/ca/win/WKCACFViewWindow.h: Added.

(WebKit::WKCACFViewWindow::setDeletesSelfWhenWindowDestroyed): Simple setter.
(WebKit::WKCACFViewWindow::window): Simple getter.

  • WebProcess/WebPage/win/DrawingAreaImplWin.cpp:

(WebKit::DrawingAreaImpl::scheduleChildWindowGeometryUpdate): Let the LayerTreeHost handle
the geometry update, if we have one.

  • win/WebKit2.vcproj: Added WKCACFViewWindow files.
Location:
trunk/Source/WebKit2
Files:
1 added
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r87806 r87831  
     12011-06-01  Adam Roben  <aroben@apple.com>
     2
     3        Render accelerated content into a web process-owned child HWND
     4
     5        This allows us to use WKCACFView's far more efficient kWKCACFViewDrawingDestinationWindow
     6        mode, which gives us asynchronous rendering on a background thread and doesn't require us to
     7        read bits off the GPU back into system memory.
     8
     9        A new class, WKCACFViewWindow, represents the child HWND. The child HWND is placed at the
     10        bottom of the z-order so it won't obscure any other child HWNDs (i.e., windowed plugins).
     11        The child HWND is made transparent to mouse events so that WKView will continue to receive
     12        mouse events even though it is obscured by the child HWND.
     13
     14        There is now a bunch of dead code in DrawingAreaImpl to handle our old rendering model. I'll
     15        remove that in a future patch.
     16
     17        Fixes <http://webkit.org/b/58054> <rdar://problem/9249839> REGRESSION (WebKit2): Accelerated
     18        CSS animations have a lower framerate than in WebKit1
     19
     20        Reviewed by Anders Carlsson.
     21
     22        * Shared/LayerTreeContext.h: Added HWND member on Windows.
     23
     24        * Shared/win/CoalescedWindowGeometriesUpdater.cpp:
     25        (WebKit::CoalescedWindowGeometriesUpdater::updateGeometries):
     26        * Shared/win/CoalescedWindowGeometriesUpdater.h:
     27        Added new BringToTopOrNot argument. Allows the caller to specify that all windows being
     28        updated should also be brought to the top of the z-order.
     29
     30        * Shared/win/LayerTreeContextWin.cpp:
     31        (WebKit::LayerTreeContext::LayerTreeContext):
     32        (WebKit::LayerTreeContext::~LayerTreeContext):
     33        (WebKit::LayerTreeContext::encode):
     34        (WebKit::LayerTreeContext::decode):
     35        (WebKit::LayerTreeContext::isEmpty):
     36        (WebKit::operator==):
     37        Implemented based on new window member.
     38
     39        * UIProcess/win/WebView.cpp:
     40        (WebKit::WebView::WebView): Initialize new member.
     41        (WebKit::WebView::onSizeEvent): Resize the layer host window to cover our entire view, if we
     42        have one.
     43        (WebKit::WebView::enterAcceleratedCompositingMode): Store, position, and show the layer host
     44        window.
     45        (WebKit::WebView::exitAcceleratedCompositingMode): Destroy the layer host window.
     46        (WebKit::WebView::updateChildWindowGeometries): Updated for change to
     47        CoalescedWindowGeometriesUpdater.
     48
     49        * UIProcess/win/WebView.h: Added m_layerHostWindow member.
     50
     51        * WebProcess/WebPage/LayerTreeHost.h: Added scheduleChildWindowGeometryUpdate.
     52
     53        * WebProcess/WebPage/ca/win/LayerTreeHostCAWin.cpp:
     54        (WebKit::LayerTreeHostCAWin::supportsAcceleratedCompositing): Simplified by using
     55        WKCACFViewWindow.
     56
     57        (WebKit::LayerTreeHostCAWin::LayerTreeHostCAWin): Removed initialization of a removed
     58        member.
     59        (WebKit::LayerTreeHostCAWin::platformInitialize): Changed to use WKCACFViewWindow,
     60        kWKCACFViewDrawingDestinationWindow, and to initialize the LayerTreeContext.
     61        (WebKit::LayerTreeHostCAWin::invalidate): Leak our window and tell it to clean up after
     62        itself. The UI process will take care of destroying the window when it finishes switching
     63        out of accelerated compositing mode. Removed a WKCACFViewUpdate call that is now handled by
     64        WKCACFViewWindow.
     65        (WebKit::LayerTreeHostCAWin::scheduleChildWindowGeometryUpdate): Added. Calls through to
     66        m_geometriesUpdater.
     67        (WebKit::LayerTreeHostCAWin::sizeDidChange): Updated to use WKCACFViewWindow.
     68        (WebKit::LayerTreeHostCAWin::contextDidChange): Update child window geometries now to keep
     69        them (almost) in sync with the accelerated content. <http://webkit.org/b/61867> covers the
     70        slight asynchrony that still exists.
     71        (WebKit::LayerTreeHostCAWin::setRootCompositingLayer): Don't flush any changes when we don't
     72        have a root layer. This prevents a flash of white when switching out of compositing mode.
     73
     74        * WebProcess/WebPage/ca/win/LayerTreeHostCAWin.h: Added m_window and m_geometriesUpdater.
     75        Removed code related to the old, synchronous display model.
     76
     77        * WebProcess/WebPage/ca/win/WKCACFViewWindow.cpp: Added.
     78        (WebKit::WKCACFViewWindow::WKCACFViewWindow): Initialize members and create our window.
     79        (WebKit::WKCACFViewWindow::~WKCACFViewWindow): Destroy our window if needed.
     80        (WebKit::WKCACFViewWindow::onCustomDestroy): Just call ::DestroyWindow.
     81        (WebKit::WKCACFViewWindow::onDestroy): Tell our view not to render into our window anymore.
     82        (WebKit::WKCACFViewWindow::onEraseBackground): Tell Windows not to erase us.
     83        (WebKit::WKCACFViewWindow::onNCDestroy): Clear out m_window since it's now pointing to a
     84        destroy window, and destroy ourselves if requested.
     85        (WebKit::WKCACFViewWindow::onPaint): Tell the view to draw, then clear our invalid region.
     86        (WebKit::WKCACFViewWindow::onPrintClient): Tell our view to draw into the given HDC.
     87        (WebKit::WKCACFViewWindow::registerClass): Register our class (duh).
     88        (WebKit::WKCACFViewWindow::staticWndProc): Get the WKCACFViewWindow pointer, or store the
     89        pointer if needed, then call through to wndProc.
     90        (WebKit::WKCACFViewWindow::wndProc): Call out to the appropriate handler function.
     91
     92        * WebProcess/WebPage/ca/win/WKCACFViewWindow.h: Added.
     93        (WebKit::WKCACFViewWindow::setDeletesSelfWhenWindowDestroyed): Simple setter.
     94        (WebKit::WKCACFViewWindow::window): Simple getter.
     95
     96        * WebProcess/WebPage/win/DrawingAreaImplWin.cpp:
     97        (WebKit::DrawingAreaImpl::scheduleChildWindowGeometryUpdate): Let the LayerTreeHost handle
     98        the geometry update, if we have one.
     99
     100        * win/WebKit2.vcproj: Added WKCACFViewWindow files.
     101
    11022011-06-01  Adam Roben  <aroben@apple.com>
    2103
  • trunk/Source/WebKit2/Shared/LayerTreeContext.h

    r86612 r87831  
    4646#if PLATFORM(MAC)
    4747    uint32_t contextID;
     48#elif PLATFORM(WIN)
     49    HWND window;
    4850#endif
    4951};
  • trunk/Source/WebKit2/Shared/win/CoalescedWindowGeometriesUpdater.cpp

    r87805 r87831  
    5656}
    5757
    58 void CoalescedWindowGeometriesUpdater::updateGeometries()
     58void CoalescedWindowGeometriesUpdater::updateGeometries(BringToTopOrNot bringToTopOrNot)
    5959{
    6060    HashMap<HWND, WindowGeometry> geometries;
     
    6969            continue;
    7070
    71         UINT flags = SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER;
     71        UINT flags = SWP_NOACTIVATE;
    7272        if (geometry.visible)
    7373            flags |= SWP_SHOWWINDOW;
     
    7575            flags |= SWP_HIDEWINDOW;
    7676
    77         deferWindowPos = ::DeferWindowPos(deferWindowPos, geometry.window, 0, geometry.frame.x(), geometry.frame.y(), geometry.frame.width(), geometry.frame.height(), flags);
     77        HWND hwndInsertAfter;
     78        if (bringToTopOrNot == BringToTop)
     79            hwndInsertAfter = HWND_TOP;
     80        else {
     81            hwndInsertAfter = 0;
     82            flags |= SWP_NOOWNERZORDER | SWP_NOZORDER;
     83        }
     84
     85        deferWindowPos = ::DeferWindowPos(deferWindowPos, geometry.window, hwndInsertAfter, geometry.frame.x(), geometry.frame.y(), geometry.frame.width(), geometry.frame.height(), flags);
    7886
    7987        setWindowRegion(geometry.window, adoptPtr(::CreateRectRgn(geometry.clipRect.x(), geometry.clipRect.y(), geometry.clipRect.maxX(), geometry.clipRect.maxY())));
  • trunk/Source/WebKit2/Shared/win/CoalescedWindowGeometriesUpdater.h

    r87805 r87831  
    3434struct WindowGeometry;
    3535
     36enum BringToTopOrNot { BringToTop, DoNotBringToTop };
     37
    3638class CoalescedWindowGeometriesUpdater {
    3739    WTF_MAKE_NONCOPYABLE(CoalescedWindowGeometriesUpdater);
     
    4143
    4244    void addPendingUpdate(const WindowGeometry&);
    43     void updateGeometries();
     45    void updateGeometries(BringToTopOrNot);
    4446
    4547private:
  • trunk/Source/WebKit2/Shared/win/LayerTreeContextWin.cpp

    r79335 r87831  
    2727#include "LayerTreeContext.h"
    2828
    29 #include <WebCore/NotImplemented.h>
     29#include "ArgumentCoders.h"
    3030
    3131namespace WebKit {
    3232
    3333LayerTreeContext::LayerTreeContext()
     34    : window(0)
    3435{
    35     notImplemented();
    3636}
    3737
    3838LayerTreeContext::~LayerTreeContext()
    3939{
    40     notImplemented();
    4140}
    4241
    43 void LayerTreeContext::encode(CoreIPC::ArgumentEncoder*) const
     42void LayerTreeContext::encode(CoreIPC::ArgumentEncoder* encoder) const
    4443{
    45     notImplemented();
     44    encoder->encodeUInt64(reinterpret_cast<uint64_t>(window));
    4645}
    4746
    48 bool LayerTreeContext::decode(CoreIPC::ArgumentDecoder*, LayerTreeContext&)
     47bool LayerTreeContext::decode(CoreIPC::ArgumentDecoder* decoder, LayerTreeContext& context)
    4948{
    50     notImplemented();
     49    uint64_t window;
     50    if (!decoder->decode(window))
     51        return false;
     52
     53    context.window = reinterpret_cast<HWND>(window);
    5154    return true;
    5255}
     
    5457bool LayerTreeContext::isEmpty() const
    5558{
    56     notImplemented();
    57     return true;
     59    return !window;
    5860}
    5961
    60 bool operator==(const LayerTreeContext&, const LayerTreeContext&)
     62bool operator==(const LayerTreeContext& a, const LayerTreeContext& b)
    6163{
    62     notImplemented();
    63     return true;
     64    return a.window == b.window;
    6465}
    6566
  • trunk/Source/WebKit2/UIProcess/win/WebView.cpp

    r87805 r87831  
    3636#include "RunLoop.h"
    3737#include "WKAPICast.h"
     38#include "WKCACFViewWindow.h"
    3839#include "WebContext.h"
    3940#include "WebContextMenuProxyWin.h"
     
    277278    , m_overPanY(0)
    278279    , m_gestureReachedScrollingLimit(false)
     280#if USE(ACCELERATED_COMPOSITING)
     281    , m_layerHostWindow(0)
     282#endif
    279283{
    280284    registerWebViewWindowClass();
     
    729733        m_nextResizeScrollOffset = IntSize();
    730734    }
     735
     736#if USE(ACCELERATED_COMPOSITING)
     737    if (m_layerHostWindow)
     738        ::MoveWindow(m_layerHostWindow, 0, 0, width, height, FALSE);
     739#endif
    731740
    732741    handled = true;
     
    15101519#if USE(ACCELERATED_COMPOSITING)
    15111520
    1512 void WebView::enterAcceleratedCompositingMode(const LayerTreeContext&)
    1513 {
    1514     // FIXME: Implement.
    1515     ASSERT_NOT_REACHED();
     1521void WebView::enterAcceleratedCompositingMode(const LayerTreeContext& context)
     1522{
     1523    ASSERT(!context.isEmpty());
     1524
     1525    m_layerHostWindow = context.window;
     1526
     1527    IntSize size = viewSize();
     1528    // Ensure the layer host window is behind all other child windows (since otherwise it would obscure them).
     1529    ::SetWindowPos(m_layerHostWindow, HWND_BOTTOM, 0, 0, size.width(), size.height(), SWP_SHOWWINDOW | SWP_NOACTIVATE);
    15161530}
    15171531
    15181532void WebView::exitAcceleratedCompositingMode()
    15191533{
    1520     // FIXME: Implement.
    1521     ASSERT_NOT_REACHED();
     1534    ASSERT(m_layerHostWindow);
     1535
     1536    // Tell the WKCACFViewWindow to destroy itself. We can't call ::DestroyWindow directly because
     1537    // the window is owned by another thread.
     1538    ::PostMessageW(m_layerHostWindow, WKCACFViewWindow::customDestroyMessage, 0, 0);
     1539    m_layerHostWindow = 0;
    15221540}
    15231541
     
    15361554void WebView::updateChildWindowGeometries()
    15371555{
    1538     m_geometriesUpdater.updateGeometries();
     1556    m_geometriesUpdater.updateGeometries(DoNotBringToTop);
    15391557}
    15401558
  • trunk/Source/WebKit2/UIProcess/win/WebView.h

    r87805 r87831  
    281281    OwnPtr<WebCore::FullScreenController> m_fullScreenController;
    282282#endif
     283
     284#if USE(ACCELERATED_COMPOSITING)
     285    HWND m_layerHostWindow;
     286#endif
    283287};
    284288
  • trunk/Source/WebKit2/WebProcess/WebPage/LayerTreeHost.h

    r87755 r87831  
    4242class WebPage;
    4343
     44#if PLATFORM(WIN)
     45struct WindowGeometry;
     46#endif
     47
    4448class LayerTreeHost : public RefCounted<LayerTreeHost> {
    4549public:
     
    7579    virtual void display(UpdateInfo&) { ASSERT_NOT_REACHED(); }
    7680
     81#if PLATFORM(WIN)
     82    virtual void scheduleChildWindowGeometryUpdate(const WindowGeometry&) = 0;
     83#endif
     84
    7785protected:
    7886    explicit LayerTreeHost(WebPage*);
  • trunk/Source/WebKit2/WebProcess/WebPage/ca/win/LayerTreeHostCAWin.cpp

    r87804 r87831  
    3232#include "ShareableBitmap.h"
    3333#include "UpdateInfo.h"
     34#include "WKCACFViewWindow.h"
    3435#include "WebPage.h"
    35 #include <WebCore/DefWndProcWindowClass.h>
    3636#include <WebCore/GraphicsLayerCA.h>
    3737#include <WebCore/LayerChangesFlusher.h>
     
    5353namespace WebKit {
    5454
    55 static HWND dummyWindow;
    56 static size_t validLayerTreeHostCount;
    57 
    58 // This window is never shown. It is only needed so that D3D can determine the display mode, etc.
    59 static HWND createDummyWindow()
    60 {
    61     return ::CreateWindowW(defWndProcWindowClassName(), 0, WS_POPUP, 0, 0, 10, 10, 0, 0, instanceHandle(), 0);
    62 }
    63 
    6455bool LayerTreeHostCAWin::supportsAcceleratedCompositing()
    6556{
     
    7061    initialized = true;
    7162
    72     ASSERT(!dummyWindow);
    73     dummyWindow = createDummyWindow();
    74     RetainPtr<WKCACFViewRef> view(AdoptCF, WKCACFViewCreate(kWKCACFViewDrawingDestinationImage));
     63    RetainPtr<WKCACFViewRef> view(AdoptCF, WKCACFViewCreate(kWKCACFViewDrawingDestinationWindow));
     64    WKCACFViewWindow dummyWindow(view.get(), 0, 0);
    7565    CGRect fakeBounds = CGRectMake(0, 0, 10, 10);
    76     WKCACFViewUpdate(view.get(), dummyWindow, &fakeBounds);
     66    WKCACFViewUpdate(view.get(), dummyWindow.window(), &fakeBounds);
    7767
    7868    supportsAcceleratedCompositing = WKCACFViewCanDraw(view.get());
    7969
    8070    WKCACFViewUpdate(view.get(), 0, 0);
    81     ::DestroyWindow(dummyWindow);
    82     dummyWindow = 0;
    8371
    8472    return supportsAcceleratedCompositing;
     
    9583    : LayerTreeHostCA(webPage)
    9684    , m_isFlushingLayerChanges(false)
    97     , m_nextDisplayTime(0)
    9885{
    9986}
     
    10390}
    10491
    105 void LayerTreeHostCAWin::platformInitialize(LayerTreeContext&)
    106 {
    107     ++validLayerTreeHostCount;
    108     if (!dummyWindow)
    109         dummyWindow = createDummyWindow();
    110 
    111     m_view.adoptCF(WKCACFViewCreate(kWKCACFViewDrawingDestinationImage));
     92void LayerTreeHostCAWin::platformInitialize(LayerTreeContext& context)
     93{
     94    m_view.adoptCF(WKCACFViewCreate(kWKCACFViewDrawingDestinationWindow));
    11295    WKCACFViewSetContextUserData(m_view.get(), static_cast<AbstractCACFLayerTreeHost*>(this));
    11396    WKCACFViewSetLayer(m_view.get(), rootLayer()->platformLayer());
    11497    WKCACFViewSetContextDidChangeCallback(m_view.get(), contextDidChangeCallback, this);
    11598
     99    // Passing WS_DISABLED makes the window invisible to mouse events, which lets WKView's normal
     100    // event handling mechanism work even when this window is obscuring the entire WKView HWND.
     101    // Note that m_webPage->nativeWindow() is owned by the UI process, so this creates a cross-
     102    // process window hierarchy (and thus implicitly attaches the input queues of the UI and web
     103    // processes' main threads).
     104    m_window = adoptPtr(new WKCACFViewWindow(m_view.get(), m_webPage->nativeWindow(), WS_DISABLED));
     105
    116106    CGRect bounds = m_webPage->bounds();
    117     WKCACFViewUpdate(m_view.get(), dummyWindow, &bounds);
     107    WKCACFViewUpdate(m_view.get(), m_window->window(), &bounds);
     108
     109    context.window = m_window->window();
    118110}
    119111
     
    122114    LayerChangesFlusher::shared().cancelPendingFlush(this);
    123115
    124     WKCACFViewUpdate(m_view.get(), 0, 0);
    125116    WKCACFViewSetContextUserData(m_view.get(), 0);
    126117    WKCACFViewSetLayer(m_view.get(), 0);
    127118    WKCACFViewSetContextDidChangeCallback(m_view.get(), 0, 0);
    128119
     120    // The UI process will destroy m_window's HWND when it gets the message to switch out of
     121    // accelerated compositing mode. We don't want to destroy the HWND before then or we will get a
     122    // flash of white before the UI process has a chance to display the non-composited content.
     123    // Since the HWND needs to outlive us, we leak m_window here and tell it to clean itself up
     124    // when its HWND is destroyed.
     125    WKCACFViewWindow* window = m_window.leakPtr();
     126    window->setDeletesSelfWhenWindowDestroyed(true);
     127
    129128    LayerTreeHostCA::invalidate();
    130 
    131     if (--validLayerTreeHostCount)
    132         return;
    133     ::DestroyWindow(dummyWindow);
    134     dummyWindow = 0;
    135129}
    136130
     
    156150}
    157151
    158 bool LayerTreeHostCAWin::participatesInDisplay()
    159 {
    160     return true;
    161 }
    162 
    163 bool LayerTreeHostCAWin::needsDisplay()
    164 {
    165     return timeUntilNextDisplay() <= 0;
    166 }
    167 
    168 double LayerTreeHostCAWin::timeUntilNextDisplay()
    169 {
    170     return m_nextDisplayTime - currentTime();
    171 }
    172 
    173 static IntSize size(WKCACFImageRef image)
    174 {
    175     return IntSize(WKCACFImageGetWidth(image), WKCACFImageGetHeight(image));
    176 }
    177 
    178 static PassRefPtr<ShareableBitmap> toShareableBitmap(WKCACFImageRef image)
    179 {
    180     size_t fileMappingSize;
    181     HANDLE mapping = WKCACFImageCopyFileMapping(image, &fileMappingSize);
    182     if (!mapping)
    183         return 0;
    184 
    185     RefPtr<SharedMemory> sharedMemory = SharedMemory::adopt(mapping, fileMappingSize, SharedMemory::ReadWrite);
    186     if (!sharedMemory) {
    187         ::CloseHandle(mapping);
    188         return 0;
    189     }
    190 
    191     // WKCACFImage never has an alpha channel.
    192     return ShareableBitmap::create(size(image), 0, sharedMemory.release());
    193 }
    194 
    195 void LayerTreeHostCAWin::display(UpdateInfo& updateInfo)
    196 {
    197     CGPoint imageOrigin;
    198     CFTimeInterval nextDrawTime;
    199     RetainPtr<WKCACFImageRef> image(AdoptCF, WKCACFViewCopyDrawnImage(m_view.get(), &imageOrigin, &nextDrawTime));
    200     m_nextDisplayTime = nextDrawTime - CACurrentMediaTime() + currentTime();
    201     if (!image)
    202         return;
    203     RefPtr<ShareableBitmap> bitmap = toShareableBitmap(image.get());
    204     if (!bitmap)
    205         return;
    206     if (!bitmap->createHandle(updateInfo.bitmapHandle))
    207         return;
    208     updateInfo.updateRectBounds = IntRect(IntPoint(imageOrigin.x, m_webPage->size().height() - imageOrigin.y - bitmap->size().height()), bitmap->size());
    209     updateInfo.updateRects.append(updateInfo.updateRectBounds);
     152void LayerTreeHostCAWin::scheduleChildWindowGeometryUpdate(const WindowGeometry& geometry)
     153{
     154    m_geometriesUpdater.addPendingUpdate(geometry);
    210155}
    211156
     
    214159    LayerTreeHostCA::sizeDidChange(newSize);
    215160    CGRect bounds = CGRectMake(0, 0, newSize.width(), newSize.height());
    216     WKCACFViewUpdate(m_view.get(), dummyWindow, &bounds);
     161    WKCACFViewUpdate(m_view.get(), m_window->window(), &bounds);
    217162    WKCACFViewFlushContext(m_view.get());
    218163}
     
    250195    m_pendingAnimatedLayers.clear();
    251196
    252     m_nextDisplayTime = 0;
    253     static_cast<DrawingAreaImpl*>(m_webPage->drawingArea())->setLayerHostNeedsDisplay();
     197    // Update child window geometries now so that they stay mostly in sync with the accelerated content.
     198    // FIXME: We should really be doing this when the changes we just flushed appear on screen. <http://webkit.org/b/61867>
     199    // We also bring the child windows (i.e., plugins) to the top of the z-order to ensure they are above m_window.
     200    // FIXME: We could do this just once per window when it is first shown. Maybe that would be more efficient?
     201    m_geometriesUpdater.updateGeometries(BringToTop);
    254202}
    255203
     
    296244
    297245void LayerTreeHostCAWin::setRootCompositingLayer(GraphicsLayer* graphicsLayer)
    298 {   
     246{
     247    // Don't flush any changes when we don't have a root layer. This will prevent flashes of white
     248    // when switching out of compositing mode.
     249    setLayerFlushSchedulingEnabled(graphicsLayer);
     250
    299251    // Resubmit all existing animations. CACF does not remember running animations
    300252    // When the layer tree is removed and then added back to the hierarchy
  • trunk/Source/WebKit2/WebProcess/WebPage/ca/win/LayerTreeHostCAWin.h

    r87755 r87831  
    3131#if HAVE(WKQCA)
    3232
     33#include "CoalescedWindowGeometriesUpdater.h"
    3334#include "LayerTreeHostCA.h"
    3435#include <WebCore/AbstractCACFLayerTreeHost.h>
     
    3940
    4041namespace WebKit {
     42
     43class WKCACFViewWindow;
    4144
    4245class LayerTreeHostCAWin : public LayerTreeHostCA, private WebCore::AbstractCACFLayerTreeHost {
     
    5962    virtual void scheduleLayerFlush();
    6063    virtual void setLayerFlushSchedulingEnabled(bool);
    61     virtual bool participatesInDisplay();
    62     virtual bool needsDisplay();
    63     virtual double timeUntilNextDisplay();
    64     virtual void display(UpdateInfo&);
     64    virtual void scheduleChildWindowGeometryUpdate(const WindowGeometry&);
    6565
    6666    // LayerTreeHostCA
     
    7474    virtual void flushPendingLayerChangesNow();
    7575
     76    OwnPtr<WKCACFViewWindow> m_window;
    7677    RetainPtr<WKCACFViewRef> m_view;
    7778    HashSet<RefPtr<WebCore::PlatformCALayer> > m_pendingAnimatedLayers;
    7879    bool m_isFlushingLayerChanges;
    79     double m_nextDisplayTime;
     80    CoalescedWindowGeometriesUpdater m_geometriesUpdater;
    8081};
    8182
  • trunk/Source/WebKit2/WebProcess/WebPage/ca/win/WKCACFViewWindow.h

    r87806 r87831  
    2424 */
    2525
    26 #ifndef CoalescedWindowGeometriesUpdater_h
    27 #define CoalescedWindowGeometriesUpdater_h
     26#ifndef WKCACFViewWindow_h
     27#define WKCACFViewWindow_h
    2828
    29 #include <wtf/HashMap.h>
     29#include "HeaderDetection.h"
     30
     31#if HAVE(WKQCA)
     32
    3033#include <wtf/Noncopyable.h>
     34#include <wtf/RetainPtr.h>
     35
     36typedef struct _WKCACFView* WKCACFViewRef;
    3137
    3238namespace WebKit {
    3339
    34 struct WindowGeometry;
     40// FIXME: Move this class down to WebCore. (Maybe it can even replace some of WKCACFViewLayerTreeHost.)
     41class WKCACFViewWindow {
     42    WTF_MAKE_NONCOPYABLE(WKCACFViewWindow);
     43public:
     44    // WKCACFViewWindow will destroy its HWND when this message is received.
     45    static const UINT customDestroyMessage = WM_USER + 1;
    3546
    36 class CoalescedWindowGeometriesUpdater {
    37     WTF_MAKE_NONCOPYABLE(CoalescedWindowGeometriesUpdater);
    38 public:
    39     CoalescedWindowGeometriesUpdater();
    40     ~CoalescedWindowGeometriesUpdater();
     47    WKCACFViewWindow(WKCACFViewRef, HWND parentWindow, DWORD additionalStyles);
     48    ~WKCACFViewWindow();
    4149
    42     void addPendingUpdate(const WindowGeometry&);
    43     void updateGeometries();
     50    void setDeletesSelfWhenWindowDestroyed(bool deletes) { m_deletesSelfWhenWindowDestroyed = deletes; }
     51
     52    HWND window() const { return m_window; }
    4453
    4554private:
    46     HashMap<HWND, WindowGeometry> m_geometries;
     55    LRESULT onCustomDestroy(WPARAM, LPARAM);
     56    LRESULT onDestroy(WPARAM, LPARAM);
     57    LRESULT onEraseBackground(WPARAM, LPARAM);
     58    LRESULT onNCDestroy(WPARAM, LPARAM);
     59    LRESULT onPaint(WPARAM, LPARAM);
     60    LRESULT onPrintClient(WPARAM, LPARAM);
     61    static void registerClass();
     62    static LRESULT CALLBACK staticWndProc(HWND, UINT, WPARAM, LPARAM);
     63    LRESULT wndProc(UINT, WPARAM, LPARAM);
     64
     65    HWND m_window;
     66    RetainPtr<WKCACFViewRef> m_view;
     67    bool m_deletesSelfWhenWindowDestroyed;
    4768};
    4869
    4970} // namespace WebKit
    5071
    51 #endif // CoalescedWindowGeometriesUpdater_h
     72#endif // HAVE(WKQCA)
     73
     74#endif // WKCACFViewWindow_h
  • trunk/Source/WebKit2/WebProcess/WebPage/win/DrawingAreaImplWin.cpp

    r87806 r87831  
    3535void DrawingAreaImpl::scheduleChildWindowGeometryUpdate(const WindowGeometry& geometry)
    3636{
     37#if USE(ACCELERATED_COMPOSITING)
     38    if (m_layerTreeHost) {
     39        m_layerTreeHost->scheduleChildWindowGeometryUpdate(geometry);
     40        return;
     41    }
     42#endif
     43
    3744    // FIXME: This should be a Messages::DrawingAreaProxy, and DrawingAreaProxy should pass the
    3845    // data off to the WebPageProxy.
  • trunk/Source/WebKit2/win/WebKit2.vcproj

    r87806 r87831  
    20482048                                                        >
    20492049                                                </File>
     2050                                                <File
     2051                                                        RelativePath="..\WebProcess\WebPage\ca\win\WKCACFViewWindow.cpp"
     2052                                                        >
     2053                                                </File>
     2054                                                <File
     2055                                                        RelativePath="..\WebProcess\WebPage\ca\win\WKCACFViewWindow.h"
     2056                                                        >
     2057                                                </File>
    20502058                                        </Filter>
    20512059                                </Filter>
Note: See TracChangeset for help on using the changeset viewer.