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 are
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "PageOverlay.h"
32 #include "GraphicsLayer.h"
33 #include "GraphicsLayerClient.h"
36 #include "WebViewClient.h"
37 #include "WebViewImpl.h"
39 using namespace WebCore;
43 PassOwnPtr<PageOverlay> PageOverlay::create(WebViewImpl* viewImpl, PageOverlayClient* client)
45 return adoptPtr(new PageOverlay(viewImpl, client));
48 PageOverlay::PageOverlay(WebViewImpl* viewImpl, PageOverlayClient* client)
49 : m_viewImpl(viewImpl)
54 #if USE(ACCELERATED_COMPOSITING)
55 class OverlayGraphicsLayerClientImpl : public WebCore::GraphicsLayerClient {
57 static PassOwnPtr<OverlayGraphicsLayerClientImpl*> create(WebViewImpl* webViewImpl, PageOverlay::PageOverlayClient* pageOverlayClient)
59 return adoptPtr(new OverlayGraphicsLayerClientImpl(webViewImpl, pageOverlayClient));
62 virtual ~OverlayGraphicsLayerClientImpl() { }
64 virtual void notifyAnimationStarted(const GraphicsLayer*, double time) { }
66 virtual void notifySyncRequired(const GraphicsLayer*) { }
68 virtual void paintContents(const GraphicsLayer*, GraphicsContext& context, GraphicsLayerPaintingPhase, const IntRect& inClip)
70 m_pageOverlayClient->paintPageOverlay(context);
73 virtual bool showDebugBorders() const
75 return m_webViewImpl->page()->settings()->showDebugBorders();
78 virtual bool showRepaintCounter() const
80 return m_webViewImpl->page()->settings()->showRepaintCounter();
84 explicit OverlayGraphicsLayerClientImpl(WebViewImpl* webViewImpl, PageOverlay::PageOverlayClient* pageOverlayClient)
85 : m_pageOverlayClient(pageOverlayClient)
86 , m_webViewImpl(webViewImpl)
90 PageOverlay::PageOverlayClient* m_pageOverlayClient;
91 WebViewImpl* m_webViewImpl;
95 void PageOverlay::clear()
99 #if USE(ACCELERATED_COMPOSITING)
101 m_layer->removeFromParent();
103 m_layerClient = nullptr;
108 void PageOverlay::update()
110 invalidateWebFrame();
112 #if USE(ACCELERATED_COMPOSITING)
114 m_layerClient = OverlayGraphicsLayerClientImpl::create(m_viewImpl, m_client);
115 m_layer = GraphicsLayer::create(m_layerClient.get());
116 m_layer->setName("WebViewImpl page overlay content");
117 m_layer->setDrawsContent(true);
118 const WebSize& size = m_viewImpl->size();
119 m_layer->setSize(IntSize(size.width, size.height));
121 m_viewImpl->setOverlayLayer(m_layer.get());
122 m_layer->setNeedsDisplay();
126 void PageOverlay::paintWebFrame(GraphicsContext& gc)
128 if (!m_viewImpl->isAcceleratedCompositingActive())
129 m_client->paintPageOverlay(gc);
132 void PageOverlay::invalidateWebFrame()
134 // PageOverlayClient does the actual painting of the overlay.
135 // Here we just make sure to invalidate.
136 if (!m_viewImpl->isAcceleratedCompositingActive()) {
137 // FIXME: able to invalidate a smaller rect.
138 // FIXME: Is it important to just invalidate a smaller rect given that
139 // this is not on a critical codepath? In order to do so, we'd
140 // have to take scrolling into account.
141 const WebSize& size = m_viewImpl->size();
142 WebRect damagedRect(0, 0, size.width, size.height);
143 if (m_viewImpl->client())
144 m_viewImpl->client()->didInvalidateRect(damagedRect);
148 } // namespace WebKit