~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit2/WebProcess/WebPage/mac/RemoteGraphicsLayer.mm

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
    willBeDestroyed();
 
60
}
 
61
 
 
62
void RemoteGraphicsLayer::setName(const String& name)
 
63
{
 
64
    String longName = String::format("RemoteGraphicsLayer(%p) ", this) + name;
 
65
    GraphicsLayer::setName(longName);
 
66
 
 
67
    noteLayerPropertiesChanged(RemoteLayerTreeTransaction::NameChanged);
 
68
}
 
69
 
 
70
bool RemoteGraphicsLayer::setChildren(const Vector<GraphicsLayer*>& children)
 
71
{
 
72
    if (GraphicsLayer::setChildren(children)) {
 
73
        noteSublayersChanged();
 
74
        return true;
 
75
    }
 
76
 
 
77
    return false;
 
78
}
 
79
 
 
80
void RemoteGraphicsLayer::addChild(GraphicsLayer* childLayer)
 
81
{
 
82
    GraphicsLayer::addChild(childLayer);
 
83
    noteSublayersChanged();
 
84
}
 
85
 
 
86
void RemoteGraphicsLayer::addChildAtIndex(GraphicsLayer* childLayer, int index)
 
87
{
 
88
    GraphicsLayer::addChildAtIndex(childLayer, index);
 
89
    noteSublayersChanged();
 
90
}
 
91
 
 
92
void RemoteGraphicsLayer::addChildAbove(GraphicsLayer* childLayer, GraphicsLayer* sibling)
 
93
{
 
94
    GraphicsLayer::addChildAbove(childLayer, sibling);
 
95
    noteSublayersChanged();
 
96
}
 
97
 
 
98
void RemoteGraphicsLayer::addChildBelow(GraphicsLayer* childLayer, GraphicsLayer* sibling)
 
99
{
 
100
    GraphicsLayer::addChildBelow(childLayer, sibling);
 
101
    noteSublayersChanged();
 
102
}
 
103
 
 
104
bool RemoteGraphicsLayer::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
 
105
{
 
106
    if (GraphicsLayer::replaceChild(oldChild, newChild)) {
 
107
        noteSublayersChanged();
 
108
        return true;
 
109
    }
 
110
 
 
111
    return false;
 
112
}
 
113
 
 
114
void RemoteGraphicsLayer::removeFromParent()
 
115
{
 
116
    if (m_parent)
 
117
        static_cast<RemoteGraphicsLayer*>(m_parent)->noteSublayersChanged();
 
118
    GraphicsLayer::removeFromParent();
 
119
}
 
120
 
 
121
void RemoteGraphicsLayer::setPosition(const FloatPoint& position)
 
122
{
 
123
    if (position == m_position)
 
124
        return;
 
125
 
 
126
    GraphicsLayer::setPosition(position);
 
127
    noteLayerPropertiesChanged(RemoteLayerTreeTransaction::PositionChanged);
 
128
}
 
129
 
 
130
void RemoteGraphicsLayer::setSize(const FloatSize& size)
 
131
{
 
132
    if (size == m_size)
 
133
        return;
 
134
 
 
135
    GraphicsLayer::setSize(size);
 
136
    noteLayerPropertiesChanged(RemoteLayerTreeTransaction::SizeChanged);
 
137
}
 
138
 
 
139
void RemoteGraphicsLayer::setNeedsDisplay()
 
140
{
 
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);
 
144
}
 
145
 
 
146
void RemoteGraphicsLayer::setNeedsDisplayInRect(const FloatRect&)
 
147
{
 
148
    // FIXME: Implement this.
 
149
}
 
150
 
 
151
void RemoteGraphicsLayer::flushCompositingState(const FloatRect&)
 
152
{
 
153
    recursiveCommitChanges();
 
154
}
 
155
 
 
156
void RemoteGraphicsLayer::flushCompositingStateForThisLayerOnly()
 
157
{
 
158
    if (!m_uncommittedLayerChanges)
 
159
        return;
 
160
 
 
161
    m_context->currentTransaction().layerPropertiesChanged(this, m_uncommittedLayerChanges);
 
162
 
 
163
    m_uncommittedLayerChanges = RemoteLayerTreeTransaction::NoChange;
 
164
}
 
165
 
 
166
void RemoteGraphicsLayer::willBeDestroyed()
 
167
{
 
168
    m_context->layerWillBeDestroyed(this);
 
169
    GraphicsLayer::willBeDestroyed();
 
170
}
 
171
 
 
172
void RemoteGraphicsLayer::noteLayerPropertiesChanged(unsigned layerChanges)
 
173
{
 
174
    if (!m_uncommittedLayerChanges && m_client)
 
175
        m_client->notifyFlushRequired(this);
 
176
    m_uncommittedLayerChanges |= layerChanges;
 
177
}
 
178
 
 
179
void RemoteGraphicsLayer::noteSublayersChanged()
 
180
{
 
181
    noteLayerPropertiesChanged(RemoteLayerTreeTransaction::ChildrenChanged);
 
182
 
 
183
    // FIXME: Handle replica layers.
 
184
}
 
185
 
 
186
void RemoteGraphicsLayer::recursiveCommitChanges()
 
187
{
 
188
    flushCompositingStateForThisLayerOnly();
 
189
 
 
190
    for (size_t i = 0; i < children().size(); ++i) {
 
191
        RemoteGraphicsLayer* graphicsLayer = static_cast<RemoteGraphicsLayer*>(children()[i]);
 
192
        graphicsLayer->recursiveCommitChanges();
 
193
    }
 
194
}
 
195
 
 
196
} // namespace WebKit