2
* Copyright (C) 2012 Apple 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
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.
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.
27
#include "RemoteGraphicsLayer.h"
29
#include "RemoteLayerTreeContext.h"
30
#include "RemoteLayerTreeTransaction.h"
32
#include <wtf/text/CString.h>
34
using namespace WebCore;
38
static uint64_t generateLayerID()
40
static uint64_t layerID;
44
PassOwnPtr<GraphicsLayer> RemoteGraphicsLayer::create(GraphicsLayerClient* client, RemoteLayerTreeContext* context)
46
return adoptPtr(new RemoteGraphicsLayer(client, context));
49
RemoteGraphicsLayer::RemoteGraphicsLayer(GraphicsLayerClient* client, RemoteLayerTreeContext* context)
50
: GraphicsLayer(client)
51
, m_layerID(generateLayerID())
53
, m_uncommittedLayerChanges(RemoteLayerTreeTransaction::NoChange)
57
RemoteGraphicsLayer::~RemoteGraphicsLayer()
62
void RemoteGraphicsLayer::setName(const String& name)
64
String longName = String::format("RemoteGraphicsLayer(%p) ", this) + name;
65
GraphicsLayer::setName(longName);
67
noteLayerPropertiesChanged(RemoteLayerTreeTransaction::NameChanged);
70
bool RemoteGraphicsLayer::setChildren(const Vector<GraphicsLayer*>& children)
72
if (GraphicsLayer::setChildren(children)) {
73
noteSublayersChanged();
80
void RemoteGraphicsLayer::addChild(GraphicsLayer* childLayer)
82
GraphicsLayer::addChild(childLayer);
83
noteSublayersChanged();
86
void RemoteGraphicsLayer::addChildAtIndex(GraphicsLayer* childLayer, int index)
88
GraphicsLayer::addChildAtIndex(childLayer, index);
89
noteSublayersChanged();
92
void RemoteGraphicsLayer::addChildAbove(GraphicsLayer* childLayer, GraphicsLayer* sibling)
94
GraphicsLayer::addChildAbove(childLayer, sibling);
95
noteSublayersChanged();
98
void RemoteGraphicsLayer::addChildBelow(GraphicsLayer* childLayer, GraphicsLayer* sibling)
100
GraphicsLayer::addChildBelow(childLayer, sibling);
101
noteSublayersChanged();
104
bool RemoteGraphicsLayer::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
106
if (GraphicsLayer::replaceChild(oldChild, newChild)) {
107
noteSublayersChanged();
114
void RemoteGraphicsLayer::removeFromParent()
117
static_cast<RemoteGraphicsLayer*>(m_parent)->noteSublayersChanged();
118
GraphicsLayer::removeFromParent();
121
void RemoteGraphicsLayer::setPosition(const FloatPoint& position)
123
if (position == m_position)
126
GraphicsLayer::setPosition(position);
127
noteLayerPropertiesChanged(RemoteLayerTreeTransaction::PositionChanged);
130
void RemoteGraphicsLayer::setSize(const FloatSize& size)
135
GraphicsLayer::setSize(size);
136
noteLayerPropertiesChanged(RemoteLayerTreeTransaction::SizeChanged);
139
void RemoteGraphicsLayer::setNeedsDisplay()
141
FloatRect hugeRect(-std::numeric_limits<float>::max() / 2, -std::numeric_limits<float>::max() / 2,
142
std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
143
setNeedsDisplayInRect(hugeRect);
146
void RemoteGraphicsLayer::setNeedsDisplayInRect(const FloatRect&)
148
// FIXME: Implement this.
151
void RemoteGraphicsLayer::flushCompositingState(const FloatRect&)
153
recursiveCommitChanges();
156
void RemoteGraphicsLayer::flushCompositingStateForThisLayerOnly()
158
if (!m_uncommittedLayerChanges)
161
m_context->currentTransaction().layerPropertiesChanged(this, m_uncommittedLayerChanges);
163
m_uncommittedLayerChanges = RemoteLayerTreeTransaction::NoChange;
166
void RemoteGraphicsLayer::willBeDestroyed()
168
m_context->layerWillBeDestroyed(this);
169
GraphicsLayer::willBeDestroyed();
172
void RemoteGraphicsLayer::noteLayerPropertiesChanged(unsigned layerChanges)
174
if (!m_uncommittedLayerChanges && m_client)
175
m_client->notifyFlushRequired(this);
176
m_uncommittedLayerChanges |= layerChanges;
179
void RemoteGraphicsLayer::noteSublayersChanged()
181
noteLayerPropertiesChanged(RemoteLayerTreeTransaction::ChildrenChanged);
183
// FIXME: Handle replica layers.
186
void RemoteGraphicsLayer::recursiveCommitChanges()
188
flushCompositingStateForThisLayerOnly();
190
for (size_t i = 0; i < children().size(); ++i) {
191
RemoteGraphicsLayer* graphicsLayer = static_cast<RemoteGraphicsLayer*>(children()[i]);
192
graphicsLayer->recursiveCommitChanges();
196
} // namespace WebKit