2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "WebCompositorImpl.h"
30 #include "CCThreadImpl.h"
31 #include "WebCompositorClient.h"
32 #include "WebInputEvent.h"
33 #include "cc/CCInputHandler.h"
34 #include "cc/CCThreadProxy.h"
35 #include <wtf/ThreadingPrimitives.h>
37 using namespace WebCore;
41 PassOwnPtr<CCInputHandler> CCInputHandler::create(CCInputHandlerClient* inputHandlerClient)
43 return WebKit::WebCompositorImpl::create(inputHandlerClient);
50 void WebCompositor::setThread(WebThread* compositorThread)
52 ASSERT(compositorThread);
53 CCThreadProxy::setImplThread(CCThreadImpl::create(compositorThread).leakPtr());
57 // These statics may only be accessed from the compositor thread.
58 int WebCompositorImpl::s_nextAvailableIdentifier = 1;
59 HashSet<WebCompositorImpl*>* WebCompositorImpl::s_compositors = 0;
61 WebCompositor* WebCompositor::fromIdentifier(int identifier)
63 ASSERT(CCProxy::isImplThread());
64 return WebCompositorImpl::fromIdentifier(identifier);
67 WebCompositor* WebCompositorImpl::fromIdentifier(int identifier)
69 ASSERT(CCProxy::isImplThread());
74 for (HashSet<WebCompositorImpl*>::iterator it = s_compositors->begin(); it != s_compositors->end(); ++it) {
75 if ((*it)->identifier() == identifier)
81 WebCompositorImpl::WebCompositorImpl(CCInputHandlerClient* inputHandlerClient)
83 , m_identifier(s_nextAvailableIdentifier++)
84 , m_inputHandlerClient(inputHandlerClient)
86 ASSERT(CCProxy::isImplThread());
89 s_compositors = new HashSet<WebCompositorImpl*>;
90 s_compositors->add(this);
93 WebCompositorImpl::~WebCompositorImpl()
95 ASSERT(CCProxy::isImplThread());
97 m_client->willShutdown();
99 ASSERT(s_compositors);
100 s_compositors->remove(this);
101 if (!s_compositors->size()) {
102 delete s_compositors;
107 void WebCompositorImpl::setClient(WebCompositorClient* client)
109 ASSERT(CCProxy::isImplThread());
110 // It's valid to set a new client if we've never had one or to clear the client, but it's not valid to change from having one client to a different one.
111 ASSERT(!m_client || !client);
115 void WebCompositorImpl::handleInputEvent(const WebInputEvent& event)
117 ASSERT(CCProxy::isImplThread());
120 if (event.type == WebInputEvent::MouseWheel && !m_inputHandlerClient->haveWheelEventHandlers()) {
121 const WebMouseWheelEvent& wheelEvent = *static_cast<const WebMouseWheelEvent*>(&event);
122 m_inputHandlerClient->scrollRootLayer(IntSize(-wheelEvent.deltaX, -wheelEvent.deltaY));
123 m_client->didHandleInputEvent();
126 m_client->didNotHandleInputEvent(true /* sendToWidget */);
129 int WebCompositorImpl::identifier() const
131 ASSERT(CCProxy::isImplThread());
135 void WebCompositorImpl::willDraw(double frameBeginTimeMs)