1 /* 2 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Library General Public 6 License as published by the Free Software Foundation; either 7 version 2 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public License 15 along with this library; see the file COPYING.LIB. If not, write to 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Boston, MA 02110-1301, USA. 18 */ 19 20 #include "config.h" 21 #include "GraphicsLayerTextureMapper.h" 22 23 #include "TextureMapperNode.h" 24 25 namespace WebCore { 26 27 GraphicsLayerTextureMapper::GraphicsLayerTextureMapper(GraphicsLayerClient* client) 28 : GraphicsLayer(client) 29 , m_node(new TextureMapperNode()) 30 , m_changeMask(0) 31 { 32 } 33 34 void GraphicsLayerTextureMapper::notifyChange(TextureMapperNode::ChangeMask changeMask) 35 { 36 m_changeMask |= changeMask; 37 if (!client()) 38 return; 39 client()->notifySyncRequired(this); 40 } 41 42 void GraphicsLayerTextureMapper::didSynchronize() 43 { 44 m_syncQueued = false; 45 m_changeMask = 0; 46 m_pendingContent.needsDisplay = false; 47 m_pendingContent.needsDisplayRect = IntRect(); 48 } 49 50 void GraphicsLayerTextureMapper::setName(const String& name) 51 { 52 GraphicsLayer::setName(name); 53 } 54 55 GraphicsLayerTextureMapper::~GraphicsLayerTextureMapper() 56 { 57 } 58 59 /* \reimp (GraphicsLayer.h): The current size might change, thus we need to update the whole display. 60 */ 61 void GraphicsLayerTextureMapper::setNeedsDisplay() 62 { 63 m_pendingContent.needsDisplay = true; 64 notifyChange(TextureMapperNode::DisplayChange); 65 } 66 67 /* \reimp (GraphicsLayer.h) 68 */ 69 void GraphicsLayerTextureMapper::setNeedsDisplayInRect(const FloatRect& rect) 70 { 71 if (m_pendingContent.needsDisplay) 72 return; 73 m_pendingContent.needsDisplayRect.unite(IntRect(rect)); 74 notifyChange(TextureMapperNode::DisplayChange); 75 } 76 77 /* \reimp (GraphicsLayer.h) 78 */ 79 void GraphicsLayerTextureMapper::setParent(GraphicsLayer* layer) 80 { 81 notifyChange(TextureMapperNode::ParentChange); 82 GraphicsLayer::setParent(layer); 83 } 84 85 /* \reimp (GraphicsLayer.h) 86 */ 87 bool GraphicsLayerTextureMapper::setChildren(const Vector<GraphicsLayer*>& children) 88 { 89 notifyChange(TextureMapperNode::ChildrenChange); 90 return GraphicsLayer::setChildren(children); 91 } 92 93 /* \reimp (GraphicsLayer.h) 94 */ 95 void GraphicsLayerTextureMapper::addChild(GraphicsLayer* layer) 96 { 97 notifyChange(TextureMapperNode::ChildrenChange); 98 GraphicsLayer::addChild(layer); 99 } 100 101 /* \reimp (GraphicsLayer.h) 102 */ 103 void GraphicsLayerTextureMapper::addChildAtIndex(GraphicsLayer* layer, int index) 104 { 105 GraphicsLayer::addChildAtIndex(layer, index); 106 notifyChange(TextureMapperNode::ChildrenChange); 107 } 108 109 /* \reimp (GraphicsLayer.h) 110 */ 111 void GraphicsLayerTextureMapper::addChildAbove(GraphicsLayer* layer, GraphicsLayer* sibling) 112 { 113 GraphicsLayer::addChildAbove(layer, sibling); 114 notifyChange(TextureMapperNode::ChildrenChange); 115 } 116 117 /* \reimp (GraphicsLayer.h) 118 */ 119 void GraphicsLayerTextureMapper::addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling) 120 { 121 122 GraphicsLayer::addChildBelow(layer, sibling); 123 notifyChange(TextureMapperNode::ChildrenChange); 124 } 125 126 /* \reimp (GraphicsLayer.h) 127 */ 128 bool GraphicsLayerTextureMapper::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild) 129 { 130 if (GraphicsLayer::replaceChild(oldChild, newChild)) { 131 notifyChange(TextureMapperNode::ChildrenChange); 132 return true; 133 } 134 return false; 135 } 136 137 /* \reimp (GraphicsLayer.h) 138 */ 139 void GraphicsLayerTextureMapper::removeFromParent() 140 { 141 if (!parent()) 142 return; 143 notifyChange(TextureMapperNode::ParentChange); 144 GraphicsLayer::removeFromParent(); 145 } 146 147 /* \reimp (GraphicsLayer.h) 148 */ 149 void GraphicsLayerTextureMapper::setMaskLayer(GraphicsLayer* value) 150 { 151 if (value == maskLayer()) 152 return; 153 GraphicsLayer::setMaskLayer(value); 154 notifyChange(TextureMapperNode::MaskLayerChange); 155 } 156 157 158 /* \reimp (GraphicsLayer.h) 159 */ 160 void GraphicsLayerTextureMapper::setReplicatedByLayer(GraphicsLayer* value) 161 { 162 if (value == replicaLayer()) 163 return; 164 GraphicsLayer::setReplicatedByLayer(value); 165 notifyChange(TextureMapperNode::ReplicaLayerChange); 166 } 167 168 /* \reimp (GraphicsLayer.h) 169 */ 170 void GraphicsLayerTextureMapper::setPosition(const FloatPoint& value) 171 { 172 if (value == position()) 173 return; 174 GraphicsLayer::setPosition(value); 175 notifyChange(TextureMapperNode::PositionChange); 176 } 177 178 /* \reimp (GraphicsLayer.h) 179 */ 180 void GraphicsLayerTextureMapper::setAnchorPoint(const FloatPoint3D& value) 181 { 182 if (value == anchorPoint()) 183 return; 184 GraphicsLayer::setAnchorPoint(value); 185 notifyChange(TextureMapperNode::AnchorPointChange); 186 } 187 188 /* \reimp (GraphicsLayer.h) 189 */ 190 void GraphicsLayerTextureMapper::setSize(const FloatSize& value) 191 { 192 if (value == size()) 193 return; 194 195 GraphicsLayer::setSize(value); 196 notifyChange(TextureMapperNode::SizeChange); 197 } 198 199 /* \reimp (GraphicsLayer.h) 200 */ 201 void GraphicsLayerTextureMapper::setTransform(const TransformationMatrix& value) 202 { 203 if (value == transform()) 204 return; 205 206 GraphicsLayer::setTransform(value); 207 notifyChange(TextureMapperNode::TransformChange); 208 } 209 210 /* \reimp (GraphicsLayer.h) 211 */ 212 void GraphicsLayerTextureMapper::setChildrenTransform(const TransformationMatrix& value) 213 { 214 if (value == childrenTransform()) 215 return; 216 GraphicsLayer::setChildrenTransform(value); 217 notifyChange(TextureMapperNode::ChildrenTransformChange); 218 } 219 220 /* \reimp (GraphicsLayer.h) 221 */ 222 void GraphicsLayerTextureMapper::setPreserves3D(bool value) 223 { 224 if (value == preserves3D()) 225 return; 226 GraphicsLayer::setPreserves3D(value); 227 notifyChange(TextureMapperNode::Preserves3DChange); 228 } 229 230 /* \reimp (GraphicsLayer.h) 231 */ 232 void GraphicsLayerTextureMapper::setMasksToBounds(bool value) 233 { 234 if (value == masksToBounds()) 235 return; 236 GraphicsLayer::setMasksToBounds(value); 237 notifyChange(TextureMapperNode::MasksToBoundsChange); 238 } 239 240 /* \reimp (GraphicsLayer.h) 241 */ 242 void GraphicsLayerTextureMapper::setDrawsContent(bool value) 243 { 244 if (value == drawsContent()) 245 return; 246 notifyChange(TextureMapperNode::DrawsContentChange); 247 GraphicsLayer::setDrawsContent(value); 248 } 249 250 /* \reimp (GraphicsLayer.h) 251 */ 252 void GraphicsLayerTextureMapper::setBackgroundColor(const Color& value) 253 { 254 if (value == m_pendingContent.backgroundColor) 255 return; 256 m_pendingContent.backgroundColor = value; 257 GraphicsLayer::setBackgroundColor(value); 258 notifyChange(TextureMapperNode::BackgroundColorChange); 259 } 260 261 /* \reimp (GraphicsLayer.h) 262 */ 263 void GraphicsLayerTextureMapper::clearBackgroundColor() 264 { 265 if (!m_pendingContent.backgroundColor.isValid()) 266 return; 267 m_pendingContent.backgroundColor = Color(); 268 GraphicsLayer::clearBackgroundColor(); 269 notifyChange(TextureMapperNode::BackgroundColorChange); 270 } 271 272 /* \reimp (GraphicsLayer.h) 273 */ 274 void GraphicsLayerTextureMapper::setContentsOpaque(bool value) 275 { 276 if (value == contentsOpaque()) 277 return; 278 notifyChange(TextureMapperNode::ContentsOpaqueChange); 279 GraphicsLayer::setContentsOpaque(value); 280 } 281 282 /* \reimp (GraphicsLayer.h) 283 */ 284 void GraphicsLayerTextureMapper::setBackfaceVisibility(bool value) 285 { 286 if (value == backfaceVisibility()) 287 return; 288 GraphicsLayer::setBackfaceVisibility(value); 289 notifyChange(TextureMapperNode::BackfaceVisibilityChange); 290 } 291 292 /* \reimp (GraphicsLayer.h) 293 */ 294 void GraphicsLayerTextureMapper::setOpacity(float value) 295 { 296 if (value == opacity()) 297 return; 298 GraphicsLayer::setOpacity(value); 299 notifyChange(TextureMapperNode::OpacityChange); 300 } 301 302 /* \reimp (GraphicsLayer.h) 303 */ 304 void GraphicsLayerTextureMapper::setContentsRect(const IntRect& value) 305 { 306 if (value == contentsRect()) 307 return; 308 GraphicsLayer::setContentsRect(value); 309 notifyChange(TextureMapperNode::ContentsRectChange); 310 } 311 312 /* \reimp (GraphicsLayer.h) 313 */ 314 void GraphicsLayerTextureMapper::setContentsToImage(Image* image) 315 { 316 notifyChange(TextureMapperNode::ContentChange); 317 m_pendingContent.contentType = image ? TextureMapperNode::DirectImageContentType : TextureMapperNode::HTMLContentType; 318 m_pendingContent.image = image; 319 GraphicsLayer::setContentsToImage(image); 320 } 321 322 /* \reimp (GraphicsLayer.h) 323 */ 324 void GraphicsLayerTextureMapper::setContentsBackgroundColor(const Color& color) 325 { 326 notifyChange(TextureMapperNode::ContentChange); 327 m_pendingContent.contentType = TextureMapperNode::ColorContentType; 328 m_pendingContent.backgroundColor = color; 329 GraphicsLayer::setContentsBackgroundColor(color); 330 } 331 332 333 void GraphicsLayerTextureMapper::setContentsToMedia(PlatformLayer* media) 334 { 335 GraphicsLayer::setContentsToMedia(media); 336 notifyChange(TextureMapperNode::ContentChange); 337 m_pendingContent.contentType = media ? TextureMapperNode::MediaContentType : TextureMapperNode::HTMLContentType; 338 if (media) 339 m_pendingContent.media = static_cast<TextureMapperMediaLayer*>(media); 340 else 341 m_pendingContent.media = 0; 342 } 343 344 /* \reimp (GraphicsLayer.h) 345 */ 346 void GraphicsLayerTextureMapper::setContentsOrientation(CompositingCoordinatesOrientation orientation) 347 { 348 if (contentsOrientation() == orientation) 349 return; 350 notifyChange(TextureMapperNode::ContentsOrientationChange); 351 GraphicsLayer::setContentsOrientation(orientation); 352 } 353 354 /* \reimp (GraphicsLayer.h) 355 */ 356 void GraphicsLayerTextureMapper::syncCompositingStateForThisLayerOnly() 357 { 358 m_node->syncCompositingState(this, false); 359 } 360 361 /* \reimp (GraphicsLayer.h) 362 */ 363 void GraphicsLayerTextureMapper::syncCompositingState() 364 { 365 m_node->syncCompositingState(this, true); 366 } 367 368 /* \reimp (GraphicsLayer.h) 369 */ 370 PlatformLayer* GraphicsLayerTextureMapper::platformLayer() const 371 { 372 return m_node.get(); 373 } 374 375 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client) 376 { 377 return new GraphicsLayerTextureMapper(client); 378 } 379 380 } 381