Include child layers in the remote layer tree transaction
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebPage / mac / RemoteGraphicsLayer.mm
1 /*
2  * Copyright (C) 2012 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "RemoteGraphicsLayer.h"
28
29 #include "RemoteLayerTreeContext.h"
30 #include "RemoteLayerTreeTransaction.h"
31
32 #include <wtf/text/CString.h>
33
34 using namespace WebCore;
35
36 namespace WebKit {
37
38 static uint64_t generateLayerID()
39 {
40     static uint64_t layerID;
41     return ++layerID;
42 }
43
44 PassOwnPtr<GraphicsLayer> RemoteGraphicsLayer::create(GraphicsLayerClient* client, RemoteLayerTreeContext* context)
45 {
46     return adoptPtr(new RemoteGraphicsLayer(client, context));
47 }
48
49 RemoteGraphicsLayer::RemoteGraphicsLayer(GraphicsLayerClient* client, RemoteLayerTreeContext* context)
50     : GraphicsLayer(client)
51     , m_layerID(generateLayerID())
52     , m_context(context)
53     , m_uncommittedLayerChanges(RemoteLayerTreeTransaction::NoChange)
54 {
55 }
56
57 RemoteGraphicsLayer::~RemoteGraphicsLayer()
58 {
59 }
60
61 void RemoteGraphicsLayer::setName(const String& name)
62 {
63     String longName = String::format("RemoteGraphicsLayer(%p) ", this) + name;
64     GraphicsLayer::setName(longName);
65
66     noteLayerPropertiesChanged(RemoteLayerTreeTransaction::NameChanged);
67 }
68
69 bool RemoteGraphicsLayer::setChildren(const Vector<GraphicsLayer*>& children)
70 {
71     if (GraphicsLayer::setChildren(children)) {
72         noteSublayersChanged();
73         return true;
74     }
75
76     return false;
77 }
78
79 void RemoteGraphicsLayer::addChild(GraphicsLayer* childLayer)
80 {
81     GraphicsLayer::addChild(childLayer);
82     noteSublayersChanged();
83 }
84
85 void RemoteGraphicsLayer::addChildAtIndex(GraphicsLayer* childLayer, int index)
86 {
87     GraphicsLayer::addChildAtIndex(childLayer, index);
88     noteSublayersChanged();
89 }
90
91 void RemoteGraphicsLayer::addChildAbove(GraphicsLayer* childLayer, GraphicsLayer* sibling)
92 {
93     GraphicsLayer::addChildAbove(childLayer, sibling);
94     noteSublayersChanged();
95 }
96
97 void RemoteGraphicsLayer::addChildBelow(GraphicsLayer* childLayer, GraphicsLayer* sibling)
98 {
99     GraphicsLayer::addChildBelow(childLayer, sibling);
100     noteSublayersChanged();
101 }
102
103 bool RemoteGraphicsLayer::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
104 {
105     if (GraphicsLayer::replaceChild(oldChild, newChild)) {
106         noteSublayersChanged();
107         return true;
108     }
109
110     return false;
111 }
112
113 void RemoteGraphicsLayer::setNeedsDisplay()
114 {
115     FloatRect hugeRect(-std::numeric_limits<float>::max() / 2, -std::numeric_limits<float>::max() / 2,
116                        std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
117     setNeedsDisplayInRect(hugeRect);
118 }
119
120 void RemoteGraphicsLayer::setNeedsDisplayInRect(const FloatRect&)
121 {
122     // FIXME: Implement this.
123 }
124
125 void RemoteGraphicsLayer::flushCompositingState(const FloatRect&)
126 {
127     recursiveCommitChanges();
128 }
129
130 void RemoteGraphicsLayer::flushCompositingStateForThisLayerOnly()
131 {
132     if (!m_uncommittedLayerChanges)
133         return;
134
135     m_context->currentTransaction().layerPropertiesChanged(this, m_uncommittedLayerChanges);
136
137     m_uncommittedLayerChanges = RemoteLayerTreeTransaction::NoChange;
138 }
139
140 void RemoteGraphicsLayer::noteLayerPropertiesChanged(unsigned layerChanges)
141 {
142     if (!m_uncommittedLayerChanges && m_client)
143         m_client->notifyFlushRequired(this);
144     m_uncommittedLayerChanges |= layerChanges;
145 }
146
147 void RemoteGraphicsLayer::noteSublayersChanged()
148 {
149     noteLayerPropertiesChanged(RemoteLayerTreeTransaction::ChildrenChanged);
150
151     // FIXME: Handle replica layers.
152 }
153
154 void RemoteGraphicsLayer::recursiveCommitChanges()
155 {
156     flushCompositingStateForThisLayerOnly();
157
158     for (size_t i = 0; i < children().size(); ++i) {
159         RemoteGraphicsLayer* graphicsLayer = static_cast<RemoteGraphicsLayer*>(children()[i]);
160         graphicsLayer->recursiveCommitChanges();
161     }
162 }
163
164 } // namespace WebKit