Changeset 107707 in webkit
- Timestamp:
- Feb 14, 2012 4:53:30 AM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 4 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r107706 r107707 1 2012-02-14 No'am Rosenthal <noam.rosenthal@nokia.com> 2 3 [Qt][Texmap] Refactor backing-store code in TextureMapper 4 https://bugs.webkit.org/show_bug.cgi?id=78305 5 6 Instead of dealing with tiling inside of TextureMapperNode, we now deal with that in a new 7 TextureMapperBackingStore class. Since the class is abstract, WebKit2 can overload it to 8 support remotely-managed tiles. 9 The backing-store for directly composited images is handled separately, in a new class 10 TextureMapperCompositedImage. The TextureMapper implementation decides the dimension of 11 the tiles, for example 2000 in the case of OpenGL. 12 Also, directly composited content is now handled correctly, by painting it after the regular 13 content and not as part of the same texture. 14 15 To make this work, the functions in TextureMapperPlatformLayers had to become non-const, 16 thus the changes to that file and GraphicsContext3DQt. 17 18 Reviewed by Kenneth Rohde Christiansen. 19 20 No new functionality, no new tests. 21 22 * GNUmakefile.list.am: 23 * Target.pri: 24 * WebCore.gypi: 25 * platform/graphics/opengl/TextureMapperGL.h: 26 (WebCore::TextureMapperGL::maxTextureDimension): 27 * platform/graphics/qt/GraphicsContext3DQt.cpp: 28 (GraphicsContext3DPrivate): 29 (WebCore::GraphicsContext3DPrivate::paintToTextureMapper): 30 * platform/graphics/texmap/GraphicsLayerTextureMapper.cpp: 31 (WebCore::GraphicsLayerTextureMapper::GraphicsLayerTextureMapper): 32 (WebCore::GraphicsLayerTextureMapper::didSynchronize): 33 (WebCore::GraphicsLayerTextureMapper::setNeedsDisplay): 34 (WebCore::GraphicsLayerTextureMapper::setContentsNeedsDisplay): 35 (WebCore::GraphicsLayerTextureMapper::setNeedsDisplayInRect): 36 (WebCore::GraphicsLayerTextureMapper::addChildBelow): 37 (WebCore): 38 (WebCore::GraphicsLayerTextureMapper::getContentsLayer): 39 (WebCore::GraphicsLayerTextureMapper::setContentsToImage): 40 (WebCore::GraphicsLayerTextureMapper::setContentsToMedia): 41 * platform/graphics/texmap/GraphicsLayerTextureMapper.h: 42 (GraphicsLayerTextureMapper): 43 (WebCore::GraphicsLayerTextureMapper::platformLayer): 44 (WebCore::GraphicsLayerTextureMapper::needsDisplay): 45 (WebCore::GraphicsLayerTextureMapper::needsDisplayRect): 46 * platform/graphics/texmap/TextureMapper.cpp: 47 * platform/graphics/texmap/TextureMapper.h: 48 (WebCore::TextureMapper::maxTextureDimension): 49 (TextureMapper): 50 * platform/graphics/texmap/TextureMapperBackingStore.cpp: Added. 51 * platform/graphics/texmap/TextureMapperBackingStore.h: Added. 52 * platform/graphics/texmap/TextureMapperNode.cpp: 53 (WebCore::TextureMapperNode::backingStore): 54 (WebCore::TextureMapperNode::updateBackingStore): 55 (WebCore::TextureMapperNode::paint): 56 (WebCore::TextureMapperNode::paintSelf): 57 (WebCore::TextureMapperNode::intermediateSurfaceRect): 58 (WebCore::TextureMapperNode::paintRecursive): 59 (WebCore::TextureMapperNode::syncCompositingStateSelf): 60 (WebCore::TextureMapperNode::syncCompositingState): 61 * platform/graphics/texmap/TextureMapperNode.h: 62 (TextureMapperPaintOptions): 63 (WebCore::TextureMapperPaintOptions::TextureMapperPaintOptions): 64 (WebCore::TextureMapperNode::TextureMapperNode): 65 (TextureMapperNode): 66 (WebCore::TextureMapperNode::setBackingStore): 67 (WebCore::TextureMapperNode::texture): 68 (WebCore::TextureMapperNode::layerRect): 69 (WebCore::TextureMapperNode::createBackingStore): 70 (State): 71 (WebCore::TextureMapperNode::State::State): 72 * platform/graphics/texmap/TextureMapperPlatformLayer.h: 73 (TextureMapperPlatformLayer): 74 (WebCore::TextureMapperPlatformLayer::swapBuffers): 75 1 76 2012-02-14 Shinya Kawanaka <shinyak@google.com> 2 77 -
trunk/Source/WebCore/GNUmakefile.list.am
r107662 r107707 5750 5750 Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp \ 5751 5751 Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.h \ 5752 Source/WebCore/platform/graphics/texmap/TextureMapperBackingStore.cpp \ 5753 Source/WebCore/platform/graphics/texmap/TextureMapperBackingStore.h \ 5752 5754 Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.cpp \ 5753 5755 Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.h \ … … 5772 5774 Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp \ 5773 5775 Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.h \ 5776 Source/WebCore/platform/graphics/texmap/TextureMapperBackingStore.cpp \ 5777 Source/WebCore/platform/graphics/texmap/TextureMapperBackingStore.h \ 5774 5778 Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.cpp \ 5775 5779 Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.h \ -
trunk/Source/WebCore/Target.pri
r107558 r107707 3956 3956 platform/graphics/texmap/TextureMapper.h \ 3957 3957 platform/graphics/texmap/TextureMapperAnimation.h \ 3958 platform/graphics/texmap/TextureMapperBackingStore.h \ 3958 3959 platform/graphics/texmap/TextureMapperImageBuffer.h \ 3959 3960 platform/graphics/texmap/TextureMapperNode.h \ … … 3964 3965 platform/graphics/texmap/TextureMapper.cpp \ 3965 3966 platform/graphics/texmap/TextureMapperAnimation.cpp \ 3967 platform/graphics/texmap/TextureMapperBackingStore.cpp \ 3966 3968 platform/graphics/texmap/TextureMapperImageBuffer.cpp \ 3967 3969 platform/graphics/texmap/TextureMapperNode.cpp \ -
trunk/Source/WebCore/WebCore.gypi
r107558 r107707 3587 3587 'platform/graphics/texmap/TextureMapperAnimation.cpp', 3588 3588 'platform/graphics/texmap/TextureMapperAnimation.h', 3589 'platform/graphics/texmap/TextureMapperBackingStore.cpp', 3590 'platform/graphics/texmap/TextureMapperBackingStore.h', 3589 3591 'platform/graphics/texmap/TextureMapperImageBuffer.cpp', 3590 3592 'platform/graphics/texmap/TextureMapperImageBuffer.h', -
trunk/Source/WebCore/platform/graphics/opengl/TextureMapperGL.h
r106659 r107707 47 47 virtual void endPainting(); 48 48 virtual void endClip(); 49 virtual IntSize maxTextureSize() { return IntSize(2000, 2000); } 49 50 virtual PassRefPtr<BitmapTexture> createTexture(); 50 51 virtual const char* type() const; -
trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp
r106659 r107707 75 75 QGLWidget* getViewportGLWidget(); 76 76 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER) 77 virtual void paintToTextureMapper(TextureMapper*, const FloatRect& target, const TransformationMatrix&, float opacity, BitmapTexture* mask) const;77 virtual void paintToTextureMapper(TextureMapper*, const FloatRect& target, const TransformationMatrix&, float opacity, BitmapTexture* mask); 78 78 #endif 79 79 … … 143 143 144 144 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER) 145 void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity, BitmapTexture* mask) const145 void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity, BitmapTexture* mask) 146 146 { 147 147 blitMultisampleFramebufferAndRestoreContext(); -
trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp
r106190 r107707 29 29 , m_node(adoptPtr(new TextureMapperNode())) 30 30 , m_changeMask(0) 31 , m_needsDisplay(false) 32 , m_contentsLayer(0) 31 33 , m_animationStartedTimer(this, &GraphicsLayerTextureMapper::animationStartedTimerFired) 32 34 { … … 45 47 m_syncQueued = false; 46 48 m_changeMask = 0; 47 m_ pendingContent.needsDisplay = false;48 m_ pendingContent.needsDisplayRect = IntRect();49 m_needsDisplay = false; 50 m_needsDisplayRect = IntRect(); 49 51 } 50 52 … … 62 64 void GraphicsLayerTextureMapper::setNeedsDisplay() 63 65 { 64 m_ pendingContent.needsDisplay = true;66 m_needsDisplay = true; 65 67 notifyChange(TextureMapperNode::DisplayChange); 66 68 } … … 70 72 void GraphicsLayerTextureMapper::setContentsNeedsDisplay() 71 73 { 72 if ( !node()->media())73 m_pendingContent.needsDisplay = true;74 if (m_image) 75 setContentsToImage(m_image.get()); 74 76 notifyChange(TextureMapperNode::DisplayChange); 75 77 } … … 79 81 void GraphicsLayerTextureMapper::setNeedsDisplayInRect(const FloatRect& rect) 80 82 { 81 if (m_ pendingContent.needsDisplay)82 return; 83 m_ pendingContent.needsDisplayRect.unite(rect);83 if (m_needsDisplay) 84 return; 85 m_needsDisplayRect.unite(rect); 84 86 notifyChange(TextureMapperNode::DisplayChange); 85 87 } … … 129 131 void GraphicsLayerTextureMapper::addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling) 130 132 { 131 132 133 GraphicsLayer::addChildBelow(layer, sibling); 133 134 notifyChange(TextureMapperNode::ChildrenChange); … … 260 261 /* \reimp (GraphicsLayer.h) 261 262 */ 262 void GraphicsLayerTextureMapper::setBackgroundColor(const Color& value)263 {264 if (value == m_pendingContent.backgroundColor)265 return;266 m_pendingContent.backgroundColor = value;267 GraphicsLayer::setBackgroundColor(value);268 notifyChange(TextureMapperNode::BackgroundColorChange);269 }270 271 /* \reimp (GraphicsLayer.h)272 */273 void GraphicsLayerTextureMapper::clearBackgroundColor()274 {275 if (!m_pendingContent.backgroundColor.isValid())276 return;277 m_pendingContent.backgroundColor = Color();278 GraphicsLayer::clearBackgroundColor();279 notifyChange(TextureMapperNode::BackgroundColorChange);280 }281 282 /* \reimp (GraphicsLayer.h)283 */284 263 void GraphicsLayerTextureMapper::setContentsOpaque(bool value) 285 264 { … … 324 303 void GraphicsLayerTextureMapper::setContentsToImage(Image* image) 325 304 { 305 if (image == m_image) 306 return; 307 308 m_image = image; 309 if (m_image) { 310 RefPtr<TextureMapperTiledBackingStore> backingStore = TextureMapperTiledBackingStore::create(); 311 backingStore->setContentsToImage(image); 312 m_compositedImage = backingStore; 313 } else 314 m_compositedImage = 0; 315 316 setContentsToMedia(m_compositedImage.get()); 326 317 notifyChange(TextureMapperNode::ContentChange); 327 m_pendingContent.contentType = image ? TextureMapperNode::DirectImageContentType : TextureMapperNode::HTMLContentType;328 m_pendingContent.image = image;329 318 GraphicsLayer::setContentsToImage(image); 330 319 } … … 332 321 void GraphicsLayerTextureMapper::setContentsToMedia(TextureMapperPlatformLayer* media) 333 322 { 323 if (media == m_contentsLayer) 324 return; 325 334 326 GraphicsLayer::setContentsToMedia(media); 335 327 notifyChange(TextureMapperNode::ContentChange); 336 m_pendingContent.contentType = media ? TextureMapperNode::MediaContentType : TextureMapperNode::HTMLContentType; 337 m_pendingContent.media = media; 328 m_contentsLayer = media; 338 329 } 339 330 … … 350 341 { 351 342 m_node->syncCompositingState(this, TextureMapperNode::TraverseDescendants); 352 }353 354 /* \reimp (GraphicsLayer.h)355 */356 PlatformLayer* GraphicsLayerTextureMapper::platformLayer() const357 {358 return const_cast<TextureMapperPlatformLayer*>(node()->media());359 343 } 360 344 -
trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h
r105925 r107707 65 65 virtual void setMasksToBounds(bool b); 66 66 virtual void setDrawsContent(bool b); 67 virtual void setBackgroundColor(const Color&);68 virtual void clearBackgroundColor();69 67 virtual void setContentsOpaque(bool b); 70 68 virtual void setBackfaceVisibility(bool b); … … 78 76 virtual void syncCompositingStateForThisLayerOnly(); 79 77 virtual void setName(const String& name); 80 virtual PlatformLayer* platformLayer() const ;78 virtual PlatformLayer* platformLayer() const { return 0; } 81 79 82 80 void notifyChange(TextureMapperNode::ChangeMask changeMask); 83 inline TextureMapperNode::ContentData& pendingContent() { return m_pendingContent; }84 81 inline int changeMask() const { return m_changeMask; } 85 82 void didSynchronize(); … … 90 87 91 88 TextureMapperNode* node() const { return m_node.get(); } 89 TextureMapperPlatformLayer* contentsLayer() const { return m_contentsLayer; } 90 bool needsDisplay() const { return m_needsDisplay; } 91 IntRect needsDisplayRect() const { return enclosingIntRect(m_needsDisplayRect); } 92 92 93 93 private: 94 94 OwnPtr<TextureMapperNode> m_node; 95 RefPtr<TextureMapperBackingStore> m_compositedImage; 96 RefPtr<Image> m_image; 95 97 bool m_syncQueued; 96 98 int m_changeMask; 97 TextureMapperNode::ContentData m_pendingContent; 99 bool m_needsDisplay; 100 TextureMapperPlatformLayer* m_contentsLayer; 101 FloatRect m_needsDisplayRect; 98 102 TextureMapperAnimations m_animations; 99 103 void animationStartedTimerFired(Timer<GraphicsLayerTextureMapper>*); -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp
r106659 r107707 74 74 } 75 75 76 77 76 PassOwnPtr<TextureMapper> TextureMapper::create(AccelerationMode mode) 78 77 { -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.h
r106668 r107707 107 107 virtual void endPainting() { } 108 108 109 virtual IntSize maxTextureSize() const { return IntSize(INT_MAX, INT_MAX); } 110 109 111 // A surface is released implicitly when dereferenced. 110 112 virtual PassRefPtr<BitmapTexture> acquireTextureFromPool(const IntSize&); -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp
r106804 r107707 21 21 #include "TextureMapperNode.h" 22 22 23 #include "stdio.h" 24 23 25 #if USE(ACCELERATED_COMPOSITING) 24 26 … … 26 28 #include "ImageBuffer.h" 27 29 #include "MathExtras.h" 28 29 namespace {30 static const float gTileDimension = 1024.0;31 }32 30 33 31 namespace WebCore { … … 50 48 { 51 49 m_transform.setLocalTransform(matrix); 50 } 51 52 void TextureMapperNode::clearBackingStoresRecursive() 53 { 54 m_backingStore.clear(); 55 m_contentsLayer = 0; 56 for (size_t i = 0; i < m_children.size(); ++i) 57 m_children[i]->clearBackingStoresRecursive(); 58 if (m_state.maskLayer) 59 m_state.maskLayer->clearBackingStoresRecursive(); 52 60 } 53 61 … … 82 90 } 83 91 84 void TextureMapperNode::computeTiles() 85 { 86 #if USE(TILED_BACKING_STORE) 87 if (m_state.tileOwnership == ExternallyManagedTiles) 88 return; 89 #endif 90 if (m_currentContent.contentType == HTMLContentType && !m_state.drawsContent) { 91 m_ownedTiles.clear(); 92 return; 93 } 94 Vector<FloatRect> tilesToAdd; 95 Vector<int> tilesToRemove; 96 const int TileEraseThreshold = 6; 97 FloatSize size = contentSize(); 98 FloatRect contentRect(0, 0, size.width(), size.height()); 99 100 for (float y = 0; y < contentRect.height(); y += gTileDimension) { 101 for (float x = 0; x < contentRect.width(); x += gTileDimension) { 102 FloatRect tileRect(x, y, gTileDimension, gTileDimension); 103 tileRect.intersect(contentRect); 104 tilesToAdd.append(tileRect); 105 } 106 } 107 108 for (int i = m_ownedTiles.size() - 1; i >= 0; --i) { 109 const FloatRect oldTile = m_ownedTiles[i].rect; 110 bool found = false; 111 112 for (int j = tilesToAdd.size() - 1; j >= 0; --j) { 113 const FloatRect newTile = tilesToAdd[j]; 114 if (oldTile != newTile) 115 continue; 116 117 found = true; 118 tilesToAdd.remove(j); 119 break; 120 } 121 122 if (!found) 123 tilesToRemove.append(i); 124 } 125 126 for (size_t i = 0; i < tilesToAdd.size(); ++i) { 127 if (!tilesToRemove.isEmpty()) { 128 OwnedTile& tile = m_ownedTiles[tilesToRemove[0]]; 129 tilesToRemove.remove(0); 130 tile.rect = tilesToAdd[i]; 131 tile.needsReset = true; 132 continue; 133 } 134 135 OwnedTile tile; 136 tile.rect = tilesToAdd[i]; 137 tile.needsReset = true; 138 m_ownedTiles.append(tile); 139 } 140 141 for (size_t i = 0; i < tilesToRemove.size() && m_ownedTiles.size() > TileEraseThreshold; ++i) 142 m_ownedTiles.remove(tilesToRemove[i]); 143 } 144 145 void TextureMapperNode::renderContent(TextureMapper* textureMapper, GraphicsLayer* layer) 146 { 147 #if USE(TILED_BACKING_STORE) 148 if (m_state.tileOwnership == ExternallyManagedTiles) 149 return; 150 #endif 151 152 if (m_size.isEmpty() || !layer || (!m_state.drawsContent && m_currentContent.contentType == HTMLContentType)) { 153 m_ownedTiles.clear(); 154 return; 155 } 156 157 if (!textureMapper) 158 return; 159 160 IntRect dirtyRect = enclosingIntRect(m_currentContent.needsDisplay ? entireRect() : m_currentContent.needsDisplayRect); 161 162 for (size_t tileIndex = 0; tileIndex < m_ownedTiles.size(); ++tileIndex) { 163 OwnedTile& tile = m_ownedTiles[tileIndex]; 164 if (!tile.texture) 165 tile.texture = textureMapper->createTexture(); 166 RefPtr<BitmapTexture>& texture = tile.texture; 167 IntSize tileSize = enclosingIntRect(tile.rect).size(); 168 169 if (tile.needsReset || texture->contentSize() != tileSize || !texture->isValid()) { 170 tile.needsReset = false; 171 texture->reset(tileSize, m_state.contentsOpaque); 172 dirtyRect.unite(enclosingIntRect(tile.rect)); 173 } 174 } 175 92 void TextureMapperNode::updateBackingStore(TextureMapper* textureMapper, GraphicsLayer* layer) 93 { 94 if (!layer || !textureMapper) 95 return; 96 97 if (!m_shouldUpdateBackingStoreFromLayer) 98 return; 99 100 if (!m_state.drawsContent || m_size.isEmpty()) { 101 m_backingStore.clear(); 102 return; 103 } 104 105 IntRect dirtyRect = enclosingIntRect(m_state.needsDisplay ? layerRect() : m_state.needsDisplayRect); 176 106 if (dirtyRect.isEmpty()) 177 107 return; 108 109 if (!m_backingStore) 110 m_backingStore = TextureMapperTiledBackingStore::create(); 111 112 ASSERT(dynamic_cast<TextuerMapperTiledBackingStore*>(m_backingStore.get())); 178 113 179 114 // Paint the entire dirty rect into an image buffer. This ensures we only paint once. … … 184 119 context->translate(-dirtyRect.x(), -dirtyRect.y()); 185 120 layer->paintGraphicsLayerContents(*context, dirtyRect); 186 if (m_currentContent.contentType == DirectImageContentType)187 context->drawImage(m_currentContent.image.get(), ColorSpaceDeviceRGB, m_state.contentsRect);188 121 189 122 RefPtr<Image> image; … … 196 129 #endif 197 130 198 // Divide the image to tiles. 199 for (size_t tileIndex = 0; tileIndex < m_ownedTiles.size(); ++tileIndex) { 200 OwnedTile& tile = m_ownedTiles[tileIndex]; 201 IntRect targetRect = enclosingIntRect(tile.rect); 202 targetRect.intersect(dirtyRect); 203 if (targetRect.isEmpty()) 204 continue; 205 IntRect sourceRect = targetRect; 206 207 // Normalize sourceRect to the buffer's coordinates. 208 sourceRect.move(-dirtyRect.x(), -dirtyRect.y()); 209 210 // Normalize targetRect to the texture's coordinqates. 211 targetRect.move(-tile.rect.x(), -tile.rect.y()); 212 tile.texture->updateContents(image.get(), targetRect, sourceRect, BitmapTexture::RGBAFormat); 213 } 214 215 m_currentContent.needsDisplay = false; 216 m_currentContent.needsDisplayRect = IntRect(); 131 static_cast<TextureMapperTiledBackingStore*>(m_backingStore.get())->updateContents(textureMapper, image.get(), m_size, dirtyRect); 217 132 } 218 133 219 134 void TextureMapperNode::paint() 220 135 { 221 if (m_size.isEmpty())222 return;223 224 136 computeTransformsRecursive(); 225 137 226 TextureMapperPaintOptions opt; 227 opt.textureMapper = m_textureMapper; 228 opt.textureMapper->bindSurface(0); 229 paintRecursive(opt); 230 } 231 232 FloatRect TextureMapperNode::targetRectForTileRect(const FloatRect& targetRect, const FloatRect& tileRect) const 233 { 234 return FloatRect( 235 targetRect.x() + (tileRect.x() - targetRect.x()), 236 targetRect.y() + (tileRect.y() - targetRect.y()), 237 tileRect.width(), 238 tileRect.height()); 138 TextureMapperPaintOptions options; 139 options.textureMapper = m_textureMapper; 140 options.textureMapper->bindSurface(0); 141 paintRecursive(options); 239 142 } 240 143 241 144 void TextureMapperNode::paintSelf(const TextureMapperPaintOptions& options) 242 145 { 243 if (m_size.isEmpty() || (!m_state.drawsContent && m_currentContent.contentType == HTMLContentType))244 return;245 246 float opacity = options.opacity;247 BitmapTexture* mask = options.mask;248 FloatRect targetRect = this->targetRect();249 250 146 // We apply the following transform to compensate for painting into a surface, and then apply the offset so that the painting fits in the target rect. 251 147 TransformationMatrix transform = … … 254 150 .translate(options.offset.width(), options.offset.height()); 255 151 256 #if USE(TILED_BACKING_STORE) 257 Vector<ExternallyManagedTile> tilesToPaint; 258 259 if (m_state.tileOwnership == ExternallyManagedTiles) { 260 // Sort tiles, with current scale factor last. 261 Vector<ExternallyManagedTile*> tiles; 262 HashMap<int, ExternallyManagedTile>::iterator end = m_externallyManagedTiles.end(); 263 for (HashMap<int, ExternallyManagedTile>::iterator it = m_externallyManagedTiles.begin(); it != end; ++it) { 264 if (!it->second.frontBuffer.texture) 265 continue; 266 267 if (it->second.scale == m_state.contentScale) { 268 tiles.append(&it->second); 269 continue; 270 } 271 272 // This creates a transitional effect looks good only when there's no transparency, so we only use it when the opacity for the layer is above a certain threshold. 273 if (opacity > 0.95) 274 tiles.prepend(&it->second); 275 } 276 277 for (int i = 0; i < tiles.size(); ++i) { 278 ExternallyManagedTile& tile = *tiles[i]; 279 FloatRect rect = tile.frontBuffer.targetRect; 280 BitmapTexture& texture = *tile.frontBuffer.texture; 281 options.textureMapper->drawTexture(texture, rect, transform, opacity, mask); 282 } 283 return; 284 } 285 #endif 286 287 // Now we paint owned tiles, if we're in OwnedTileMode. 288 for (size_t i = 0; i < m_ownedTiles.size(); ++i) { 289 BitmapTexture* texture = m_ownedTiles[i].texture.get(); 290 const FloatRect rect = targetRectForTileRect(targetRect, m_ownedTiles[i].rect); 291 options.textureMapper->drawTexture(*texture, rect, transform, opacity, mask); 292 } 293 294 if (m_currentContent.contentType == MediaContentType && m_currentContent.media) 295 m_currentContent.media->paintToTextureMapper(options.textureMapper, targetRect, transform, opacity, mask); 152 float opacity = options.opacity; 153 RefPtr<BitmapTexture> mask = options.mask; 154 155 if (m_backingStore) 156 m_backingStore->paintToTextureMapper(options.textureMapper, layerRect(), transform, opacity, mask.get()); 157 158 if (m_contentsLayer) 159 m_contentsLayer->paintToTextureMapper(options.textureMapper, m_state.contentsRect, transform, opacity, mask.get()); 296 160 } 297 161 … … 333 197 IntRect rect; 334 198 TransformationMatrix localTransform = TransformationMatrix(matrix).multiply(m_transform.combined()); 335 rect = enclosingIntRect(localTransform.mapRect( entireRect()));199 rect = enclosingIntRect(localTransform.mapRect(layerRect())); 336 200 if (!m_state.masksToBounds && !m_state.maskLayer) { 337 201 for (int i = 0; i < m_children.size(); ++i) … … 434 298 maskTexture = 0; 435 299 436 options.textureMapper->bindSurface(options.surface );300 options.textureMapper->bindSurface(options.surface.get()); 437 301 TransformationMatrix targetTransform = 438 302 TransformationMatrix(options.transform) … … 451 315 } 452 316 453 #if USE(TILED_BACKING_STORE)454 int TextureMapperNode::createContentsTile(float scale)455 {456 static int nextID = 0;457 int id = ++nextID;458 m_externallyManagedTiles.add(id, ExternallyManagedTile(scale));459 m_state.contentScale = scale;460 return id;461 }462 463 void TextureMapperNode::removeContentsTile(int id)464 {465 m_externallyManagedTiles.remove(id);466 }467 468 void TextureMapperNode::purgeNodeTexturesRecursive()469 {470 m_externallyManagedTiles.clear();471 472 for (int i = m_children.size() - 1; i >= 0; --i)473 m_children[i]->purgeNodeTexturesRecursive();474 }475 476 void TextureMapperNode::setTileBackBufferTextureForDirectlyCompositedImage(int id, const IntRect& sourceRect, const FloatRect& targetRect, BitmapTexture* texture)477 {478 HashMap<int, ExternallyManagedTile>::iterator it = m_externallyManagedTiles.find(id);479 480 if (it == m_externallyManagedTiles.end())481 return;482 483 ExternallyManagedTile& tile = it->second;484 485 tile.backBuffer.sourceRect = sourceRect;486 tile.backBuffer.targetRect = targetRect;487 tile.backBuffer.texture = texture;488 tile.isBackBufferUpdated = true;489 tile.isDirectlyCompositedImage = true;490 }491 492 void TextureMapperNode::clearAllDirectlyCompositedImageTiles()493 {494 for (HashMap<int, ExternallyManagedTile>::iterator it = m_externallyManagedTiles.begin(); it != m_externallyManagedTiles.end(); ++it) {495 if (it->second.isDirectlyCompositedImage)496 m_externallyManagedTiles.remove(it);497 }498 }499 500 void TextureMapperNode::setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, const void* data)501 {502 ASSERT(m_textureMapper);503 504 HashMap<int, ExternallyManagedTile>::iterator it = m_externallyManagedTiles.find(id);505 if (it == m_externallyManagedTiles.end())506 return;507 508 ExternallyManagedTile& tile = it->second;509 510 tile.backBuffer.sourceRect = sourceRect;511 tile.backBuffer.targetRect = FloatRect(targetRect);512 tile.backBuffer.targetRect.scale(1.0 / tile.scale);513 514 if (!tile.backBuffer.texture)515 tile.backBuffer.texture = m_textureMapper->createTexture();516 tile.backBuffer.texture->reset(sourceRect.size(), false);517 tile.backBuffer.texture->updateContents(data, sourceRect);518 tile.isBackBufferUpdated = true;519 }520 521 void TextureMapperNode::swapContentsBuffers()522 {523 HashMap<int, ExternallyManagedTile>::iterator end = m_externallyManagedTiles.end();524 for (HashMap<int, ExternallyManagedTile>::iterator it = m_externallyManagedTiles.begin(); it != end; ++it) {525 ExternallyManagedTile& tile = it->second;526 if (!tile.isBackBufferUpdated)527 continue;528 tile.isBackBufferUpdated = false;529 ExternallyManagedTileBuffer swapBuffer = tile.frontBuffer;530 tile.frontBuffer = tile.backBuffer;531 tile.backBuffer = swapBuffer;532 }533 }534 #endif535 536 317 void TextureMapperNode::syncCompositingState(GraphicsLayerTextureMapper* graphicsLayer, int options) 537 318 { … … 542 323 { 543 324 int changeMask = graphicsLayer->changeMask(); 544 const TextureMapperNode::ContentData& pendingContent = graphicsLayer->pendingContent(); 545 #if USE(TILED_BACKING_STORE) 546 swapContentsBuffers(); 547 #endif 548 if (changeMask == NoChanges && graphicsLayer->m_animations.isEmpty() && pendingContent.needsDisplayRect.isEmpty() && !pendingContent.needsDisplay) 549 return; 550 551 if (m_currentContent.contentType == HTMLContentType && (changeMask & ParentChange)) { 325 326 if (changeMask == NoChanges && graphicsLayer->m_animations.isEmpty()) 327 return; 328 329 if (changeMask & ParentChange) { 552 330 TextureMapperNode* newParent = toTextureMapperNode(graphicsLayer->parent()); 553 331 if (newParent != m_parent) { … … 581 359 } 582 360 583 if (changeMask & (SizeChange | ContentsRectChange)) { 584 FloatSize wantedSize(graphicsLayer->size().width(), graphicsLayer->size().height()); 585 if (wantedSize.isEmpty() && pendingContent.contentType == HTMLContentType) 586 wantedSize = FloatSize(graphicsLayer->contentsRect().width(), graphicsLayer->contentsRect().height()); 587 588 if (wantedSize != m_size) 589 m_ownedTiles.clear(); 590 591 m_size = wantedSize; 592 } 361 m_size = graphicsLayer->size(); 593 362 594 363 if (changeMask & MaskLayerChange) { … … 620 389 m_state.childrenTransform = graphicsLayer->childrenTransform(); 621 390 m_state.opacity = graphicsLayer->opacity(); 622 623 m_currentContent.contentType = pendingContent.contentType; 624 m_currentContent.image = pendingContent.image; 625 m_currentContent.media = pendingContent.media; 626 m_currentContent.needsDisplay = m_currentContent.needsDisplay || pendingContent.needsDisplay; 627 if (!m_currentContent.needsDisplay) 628 m_currentContent.needsDisplayRect.unite(pendingContent.needsDisplayRect); 391 m_state.needsDisplay = m_state.needsDisplay || graphicsLayer->needsDisplay(); 392 if (!m_state.needsDisplay) 393 m_state.needsDisplayRect.unite(graphicsLayer->needsDisplayRect()); 394 m_contentsLayer = graphicsLayer->contentsLayer(); 629 395 630 396 m_transform.setPosition(m_state.pos); … … 667 433 void TextureMapperNode::syncCompositingState(GraphicsLayerTextureMapper* graphicsLayer, TextureMapper* textureMapper, int options) 668 434 { 435 if (!textureMapper) 436 return; 437 669 438 if (graphicsLayer && !(options & ComputationsOnly)) { 670 439 syncCompositingStateSelf(graphicsLayer, textureMapper); … … 684 453 685 454 syncAnimations(); 686 computeTiles(); 687 688 if (graphicsLayer) 689 renderContent(textureMapper, graphicsLayer); 455 updateBackingStore(textureMapper, graphicsLayer); 690 456 691 457 if (!(options & TraverseDescendants)) -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperNode.h
r106659 r107707 29 29 #include "TextureMapper.h" 30 30 #include "TextureMapperAnimation.h" 31 #include "TextureMapperBackingStore.h" 31 32 #include "Timer.h" 32 33 #include "TransformOperations.h" … … 43 44 class TextureMapperPaintOptions { 44 45 public: 45 BitmapTexture*surface;46 BitmapTexture*mask;46 RefPtr<BitmapTexture> surface; 47 RefPtr<BitmapTexture> mask; 47 48 float opacity; 48 49 TransformationMatrix transform; … … 50 51 TextureMapper* textureMapper; 51 52 TextureMapperPaintOptions() 52 : surface(0) 53 , mask(0) 54 , opacity(1) 53 : opacity(1) 55 54 , textureMapper(0) 56 55 { } … … 98 97 }; 99 98 100 enum TileOwnership {101 OwnedTiles,102 ExternallyManagedTiles103 };104 105 typedef HashMap<TextureMapperNode*, FloatRect> NodeRectMap;106 107 // The compositor lets us special-case images and colors, so we try to do so.108 enum ContentType { HTMLContentType, DirectImageContentType, ColorContentType, MediaContentType, Canvas3DContentType};109 struct ContentData {110 FloatRect needsDisplayRect;111 bool needsDisplay;112 Color backgroundColor;113 114 ContentType contentType;115 RefPtr<Image> image;116 const TextureMapperPlatformLayer* media;117 ContentData()118 : needsDisplay(false)119 , contentType(HTMLContentType)120 , image(0)121 , media(0)122 {123 }124 };125 126 99 TextureMapperNode() 127 100 : m_parent(0) 128 101 , m_effectTarget(0) 102 , m_contentsLayer(0) 129 103 , m_opacity(1) 130 104 , m_centerZ(0) 105 , m_shouldUpdateBackingStoreFromLayer(true) 131 106 , m_textureMapper(0) 132 107 { } … … 145 120 void paint(); 146 121 147 #if USE(TILED_BACKING_STORE) 148 void setTileOwnership(TileOwnership ownership) { m_state.tileOwnership = ownership; } 149 int createContentsTile(float scale); 150 void removeContentsTile(int id); 151 void setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, const void*); 152 void setTileBackBufferTextureForDirectlyCompositedImage(int id, const IntRect& sourceRect, const FloatRect& targetRect, BitmapTexture*); 153 void clearAllDirectlyCompositedImageTiles(); 154 void purgeNodeTexturesRecursive(); 155 #endif 156 void setID(int id) { m_id = id; } 157 int id() const { return m_id; } 158 159 const TextureMapperPlatformLayer* media() const { return m_currentContent.media; } 122 void setShouldUpdateBackingStoreFromLayer(bool b) { m_shouldUpdateBackingStoreFromLayer = b; } 123 void setBackingStore(TextureMapperBackingStore* backingStore) { m_backingStore = backingStore; } 124 PassRefPtr<TextureMapperBackingStore> backingStore() { return m_backingStore; } 125 void clearBackingStoresRecursive(); 160 126 161 127 private: … … 175 141 static void sortByZOrder(Vector<TextureMapperNode* >& array, int first, int last); 176 142 177 BitmapTexture* texture() { return m_ownedTiles.isEmpty() ? 0 : m_ownedTiles[0].texture.get(); }143 PassRefPtr<BitmapTexture> texture() { return m_backingStore ? m_backingStore->texture() : 0; } 178 144 179 145 void paintRecursive(const TextureMapperPaintOptions&); … … 181 147 void paintSelfAndChildren(const TextureMapperPaintOptions&); 182 148 void paintSelfAndChildrenWithReplica(const TextureMapperPaintOptions&); 183 void renderContent(TextureMapper*, GraphicsLayer*);149 void updateBackingStore(TextureMapper*, GraphicsLayer*); 184 150 185 151 void syncAnimations(); … … 189 155 LayerTransform m_transform; 190 156 191 inline FloatRect targetRect() const157 inline FloatRect layerRect() const 192 158 { 193 return m_currentContent.contentType == HTMLContentType ? entireRect() : m_state.contentsRect;159 return FloatRect(FloatPoint::zero(), m_size); 194 160 } 195 196 inline FloatRect entireRect() const197 {198 return FloatRect(0, 0, m_size.width(), m_size.height());199 }200 201 FloatSize contentSize() const202 {203 return m_currentContent.contentType == DirectImageContentType && m_currentContent.image ? m_currentContent.image->size() : m_size;204 }205 struct OwnedTile {206 FloatRect rect;207 RefPtr<BitmapTexture> texture;208 bool needsReset;209 };210 211 Vector<OwnedTile> m_ownedTiles;212 213 #if USE(TILED_BACKING_STORE)214 struct ExternallyManagedTileBuffer {215 FloatRect sourceRect;216 FloatRect targetRect;217 RefPtr<BitmapTexture> texture;218 };219 220 struct ExternallyManagedTile {221 bool isBackBufferUpdated;222 bool isDirectlyCompositedImage;223 float scale;224 ExternallyManagedTileBuffer frontBuffer;225 ExternallyManagedTileBuffer backBuffer;226 227 ExternallyManagedTile(float scale = 1.0)228 : isBackBufferUpdated(false)229 , isDirectlyCompositedImage(false)230 , scale(scale)231 {232 }233 };234 235 HashMap<int, ExternallyManagedTile> m_externallyManagedTiles;236 #endif237 238 ContentData m_currentContent;239 161 240 162 Vector<TextureMapperNode*> m_children; 241 163 TextureMapperNode* m_parent; 242 164 TextureMapperNode* m_effectTarget; 165 RefPtr<TextureMapperBackingStore> m_backingStore; 166 TextureMapperPlatformLayer* m_contentsLayer; 243 167 FloatSize m_size; 244 168 float m_opacity; 245 169 float m_centerZ; 246 170 String m_name; 247 int m_id;171 bool m_shouldUpdateBackingStoreFromLayer; 248 172 249 173 struct State { … … 255 179 float opacity; 256 180 FloatRect contentsRect; 181 FloatRect needsDisplayRect; 257 182 int descendantsWithContent; 258 183 TextureMapperNode* maskLayer; … … 264 189 bool backfaceVisibility : 1; 265 190 bool visible : 1; 266 bool needs Reset: 1;191 bool needsDisplay: 1; 267 192 bool mightHaveOverlaps : 1; 268 193 bool needsRepaint; 269 float contentScale;270 #if USE(TILED_BACKING_STORE)271 TileOwnership tileOwnership;272 #endif273 194 State() 274 195 : opacity(1.f) … … 281 202 , backfaceVisibility(false) 282 203 , visible(true) 283 , needs Reset(false)204 , needsDisplay(true) 284 205 , mightHaveOverlaps(false) 285 206 , needsRepaint(false) 286 , contentScale(1.0f)287 #if USE(TILED_BACKING_STORE)288 , tileOwnership(OwnedTiles)289 #endif290 207 { 291 208 } -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayer.h
r95901 r107707 21 21 #define TextureMapperPlatformLayer_h 22 22 23 #include "FloatRect.h"24 23 #include "TransformationMatrix.h" 25 24 … … 31 30 class TextureMapperPlatformLayer { 32 31 public: 33 virtual void paintToTextureMapper(TextureMapper*, const FloatRect&, const TransformationMatrix& modelViewMatrix = TransformationMatrix(), float opacity = 1.0, BitmapTexture* mask = 0) const = 0; 32 virtual void paintToTextureMapper(TextureMapper*, const FloatRect&, const TransformationMatrix& modelViewMatrix = TransformationMatrix(), float opacity = 1.0, BitmapTexture* mask = 0) = 0; 33 virtual void swapBuffers() { } 34 34 }; 35 35 -
trunk/Source/WebKit2/ChangeLog
r107706 r107707 1 2012-02-14 No'am Rosenthal <noam.rosenthal@nokia.com> 2 3 [Qt][Texmap] Refactor backing-store code in TextureMapper 4 https://bugs.webkit.org/show_bug.cgi?id=78305 5 6 Move the backing-store code to LayerTreeBackingStore, implementing the virtual functions 7 in TextureMapperBackingStore. 8 We save the double-buffered tile in the backing-store, and then convert them to regular 9 tiles in updateContents, based on the order of painting. 10 Use TextureMapperCompositedImage for images instead of saving our own composited image 11 registry. 12 13 Reviewed by Kenneth Rohde Christiansen. 14 15 * Target.pri: 16 * UIProcess/LayerTreeHostProxy.h: 17 (WebKit): 18 (LayerTreeHostProxy): 19 * UIProcess/qt/LayerBackingStore.cpp: Added. 20 * UIProcess/qt/LayerBackingStore.h: Added. 21 * UIProcess/qt/LayerTreeHostProxyQt.cpp: 22 (WebKit::LayerTreeHostProxy::createLayer): 23 (WebKit::LayerTreeHostProxy::syncLayerParameters): 24 (WebKit::LayerTreeHostProxy::getBackingStore): 25 (WebKit::LayerTreeHostProxy::createTile): 26 (WebKit::LayerTreeHostProxy::removeTile): 27 (WebKit::LayerTreeHostProxy::updateTile): 28 (WebKit::LayerTreeHostProxy::createImage): 29 (WebKit::LayerTreeHostProxy::assignImageToLayer): 30 (WebKit::LayerTreeHostProxy::purgeGLResources): 31 * WebProcess.pro: 32 33 1 34 2012-02-14 Shinya Kawanaka <shinyak@google.com> 2 35 -
trunk/Source/WebKit2/Target.pri
r107232 r107707 254 254 UIProcess/WebResourceLoadClient.h \ 255 255 UIProcess/WebUIClient.h \ 256 UIProcess/qt/LayerBackingStore.h \ 256 257 UIProcess/qt/QtWebContext.h \ 257 258 UIProcess/qt/QtWebPageEventHandler.h \ … … 582 583 UIProcess/WebUIClient.cpp \ 583 584 UIProcess/qt/QtWebContext.cpp \ 585 UIProcess/qt/LayerBackingStore.cpp \ 584 586 UIProcess/qt/LayerTreeHostProxyQt.cpp \ 585 587 UIProcess/qt/QtWebPageEventHandler.cpp \ -
trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.h
r106524 r107707 31 31 #include <WebCore/IntSize.h> 32 32 #include <WebCore/RunLoop.h> 33 #include <WebCore/Timer.h> 33 34 #include <wtf/HashSet.h> 34 35 35 36 #if USE(TEXTURE_MAPPER) 36 37 #include "TextureMapper.h" 37 #include "TextureMapper Node.h"38 #include "TextureMapperBackingStore.h" 38 39 #endif 39 40 40 41 namespace WebKit { 41 42 43 class LayerBackingStore; 42 44 class WebLayerInfo; 43 45 class WebLayerUpdateInfo; … … 99 101 100 102 #if PLATFORM(QT) 101 typedef HashMap<WebCore::IntPoint, RefPtr<WebCore::BitmapTexture> > TiledImage;102 WebCore::TextureMapperNode::NodeRectMap m_nodeVisualContentsRectMap;103 HashMap<int, int> m_tileToNodeTile;104 int remoteTileIDToNodeTileID(int tileID) const;105 HashMap<int64_t, TiledImage> m_directlyCompositedImages;106 107 103 void scheduleWebViewUpdate(); 108 104 void synchronizeViewport(); … … 119 115 void ensureRootLayer(); 120 116 void ensureLayer(WebLayerID); 121 117 PassRefPtr<LayerBackingStore> getBackingStore(WebLayerID); 118 void swapBuffers(); 122 119 #endif 123 120 124 121 OwnPtr<WebCore::GraphicsLayer> m_rootLayer; 125 122 Vector<WebLayerID> m_layersToDelete; 123 HashMap<int64_t, RefPtr<WebCore::TextureMapperBackingStore> > m_directlyCompositedImages; 124 HashSet<RefPtr<LayerBackingStore> > m_backingStoresWithPendingBuffers; 126 125 127 126 #if PLATFORM(QT) -
trunk/Source/WebKit2/UIProcess/qt/LayerTreeHostProxyQt.cpp
r106659 r107707 23 23 #include "LayerTreeHostProxy.h" 24 24 25 #include "GraphicsLayerTextureMapper.h" 26 #include "LayerBackingStore.h" 25 27 #include "LayerTreeHostMessages.h" 26 28 #include "MainThread.h" … … 28 30 #include "ShareableBitmap.h" 29 31 #include "TextureMapper.h" 32 #include "TextureMapperBackingStore.h" 33 #include "TextureMapperNode.h" 30 34 #include "UpdateInfo.h" 31 35 #include "WebCoreArgumentCoders.h" … … 33 37 #include "WebPageProxy.h" 34 38 #include "WebProcessProxy.h" 35 #include "texmap/GraphicsLayerTextureMapper.h"36 #include "texmap/TextureMapper.h"37 #include "texmap/TextureMapperNode.h"38 39 #include <QDateTime> 39 40 #include <cairo/OpenGLShims.h> … … 150 151 GraphicsLayer* newLayer = new GraphicsLayerTextureMapper(this); 151 152 TextureMapperNode* node = toTextureMapperNode(newLayer); 152 node->setID(layerID); 153 node->setTileOwnership(TextureMapperNode::ExternallyManagedTiles); 153 node->setShouldUpdateBackingStoreFromLayer(false); 154 154 return adoptPtr(newLayer); 155 155 } … … 236 236 } 237 237 238 int LayerTreeHostProxy::remoteTileIDToNodeTileID(int tileID) const239 {240 HashMap<int, int>::const_iterator it = m_tileToNodeTile.find(tileID);241 if (it == m_tileToNodeTile.end())242 return 0;243 return it->second;244 }245 246 238 void LayerTreeHostProxy::syncLayerParameters(const WebLayerInfo& layerInfo) 247 239 { … … 250 242 LayerMap::iterator it = m_layers.find(id); 251 243 GraphicsLayer* layer = it->second; 252 bool needsToUpdateImageTiles = layerInfo.imageIsUpdated || layerInfo.contentsRect != layer->contentsRect();244 bool needsToUpdateImageTiles = layerInfo.imageIsUpdated || (layerInfo.contentsRect != layer->contentsRect() && layerInfo.imageBackingStoreID); 253 245 254 246 layer->setName(layerInfo.name); … … 349 341 } 350 342 343 PassRefPtr<LayerBackingStore> LayerTreeHostProxy::getBackingStore(WebLayerID id) 344 { 345 ensureLayer(id); 346 TextureMapperNode* node = toTextureMapperNode(layerByID(id)); 347 RefPtr<LayerBackingStore> backingStore = static_cast<LayerBackingStore*>(node->backingStore().get()); 348 if (!backingStore) { 349 backingStore = LayerBackingStore::create(); 350 node->setBackingStore(backingStore.get()); 351 } 352 ASSERT(backingStore); 353 return backingStore; 354 } 355 351 356 void LayerTreeHostProxy::createTile(WebLayerID layerID, int tileID, float scale) 352 357 { 353 ensureLayer(layerID); 354 TextureMapperNode* node = toTextureMapperNode(layerByID(layerID)); 355 356 int nodeTileID = node->createContentsTile(scale); 357 m_tileToNodeTile.add(tileID, nodeTileID); 358 getBackingStore(layerID)->createTile(tileID, scale); 358 359 } 359 360 360 361 void LayerTreeHostProxy::removeTile(WebLayerID layerID, int tileID) 361 362 { 362 TextureMapperNode* node = toTextureMapperNode(layerByID(layerID)); 363 if (!node) 364 return; 365 366 int nodeTileID = remoteTileIDToNodeTileID(tileID); 367 if (!nodeTileID) 368 return; 369 370 node->removeContentsTile(nodeTileID); 371 m_tileToNodeTile.remove(tileID); 363 getBackingStore(layerID)->removeTile(tileID); 372 364 } 373 365 374 366 void LayerTreeHostProxy::updateTile(WebLayerID layerID, int tileID, const IntRect& sourceRect, const IntRect& targetRect, ShareableBitmap* bitmap) 375 367 { 376 ensureLayer(layerID); 377 TextureMapperNode* node = toTextureMapperNode(layerByID(layerID)); 378 if (!node) 379 return; 380 381 int nodeTileID = remoteTileIDToNodeTileID(tileID); 382 if (!nodeTileID) 383 return; 384 385 node->setTextureMapper(m_textureMapper.get()); 386 QImage image = bitmap->createQImage(); 387 node->setContentsTileBackBuffer(nodeTileID, sourceRect, targetRect, image.constBits()); 368 RefPtr<LayerBackingStore> backingStore = getBackingStore(layerID); 369 backingStore->updateTile(tileID, sourceRect, targetRect, bitmap); 370 m_backingStoresWithPendingBuffers.add(backingStore); 388 371 } 389 372 390 373 void LayerTreeHostProxy::createImage(int64_t imageID, ShareableBitmap* bitmap) 391 374 { 392 TiledImage tiledImage; 393 static const int TileDimension = 1024; 394 QImage image = bitmap->createQImage(); 395 bool imageHasAlpha = image.hasAlphaChannel(); 396 IntRect imageRect(0, 0, image.width(), image.height()); 397 for (int y = 0; y < image.height(); y += TileDimension) { 398 for (int x = 0; x < image.width(); x += TileDimension) { 399 QImage subImage; 400 IntRect rect(x, y, TileDimension, TileDimension); 401 rect.intersect(imageRect); 402 if (QSize(rect.size()) == image.size()) 403 subImage = image; 404 else 405 subImage = image.copy(rect); 406 RefPtr<BitmapTexture> texture = m_textureMapper->createTexture(); 407 texture->reset(rect.size(), !imageHasAlpha); 408 texture->updateContents(subImage.constBits(), IntRect(IntPoint::zero(), rect.size())); 409 tiledImage.add(rect.location(), texture); 410 } 411 } 412 413 m_directlyCompositedImages.set(imageID, tiledImage); 375 RefPtr<TextureMapperTiledBackingStore> backingStore = TextureMapperTiledBackingStore::create(); 376 backingStore->updateContents(m_textureMapper.get(), bitmap->createImage().get()); 377 m_directlyCompositedImages.set(imageID, backingStore); 414 378 } 415 379 … … 421 385 void LayerTreeHostProxy::assignImageToLayer(GraphicsLayer* layer, int64_t imageID) 422 386 { 423 TextureMapperNode* node = toTextureMapperNode(layer); 424 if (!node) 425 return; 426 427 if (!imageID) { 428 node->clearAllDirectlyCompositedImageTiles(); 429 return; 430 } 431 432 FloatSize size(layer->size()); 433 FloatRect contentsRect(layer->contentsRect()); 434 float horizontalFactor = contentsRect.width() / size.width(); 435 float verticalFactor = contentsRect.height() / size.height(); 436 HashMap<int64_t, TiledImage>::iterator it = m_directlyCompositedImages.find(imageID); 437 if (it == m_directlyCompositedImages.end()) 438 return; 439 440 TiledImage::iterator endTileIterator = it->second.end(); 441 for (TiledImage::iterator tileIt = it->second.begin(); tileIt != endTileIterator; ++tileIt) { 442 FloatRect sourceRect(FloatPoint(tileIt->first), FloatSize(tileIt->second->size())); 443 FloatRect targetRect(sourceRect.x() * horizontalFactor + contentsRect.x(), 444 sourceRect.y() * verticalFactor + contentsRect.y(), 445 sourceRect.width() * horizontalFactor, 446 sourceRect.height() * verticalFactor); 447 int newTileID = node->createContentsTile(1.0); 448 node->setTileBackBufferTextureForDirectlyCompositedImage(newTileID, IntRect(sourceRect), targetRect, tileIt->second.get()); 449 } 387 HashMap<int64_t, RefPtr<TextureMapperBackingStore> >::iterator it = m_directlyCompositedImages.find(imageID); 388 ASSERT(it != m_directlyCompositedImages.end()); 389 layer->setContentsToMedia(it->second.get()); 390 } 391 392 void LayerTreeHostProxy::swapBuffers() 393 { 394 HashSet<RefPtr<LayerBackingStore> >::iterator end = m_backingStoresWithPendingBuffers.end(); 395 for (HashSet<RefPtr<LayerBackingStore> >::iterator it = m_backingStoresWithPendingBuffers.begin(); it != end; ++it) 396 (*it)->swapBuffers(m_textureMapper.get()); 397 398 m_backingStoresWithPendingBuffers.clear(); 450 399 } 451 400 … … 453 402 { 454 403 m_rootLayer->syncCompositingState(FloatRect()); 404 swapBuffers(); 405 455 406 // The pending tiles state is on its way for the screen, tell the web process to render the next one. 456 407 m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeHost::RenderNextFrame(), m_drawingAreaProxy->page()->pageID()); … … 630 581 631 582 if (node) 632 node-> purgeNodeTexturesRecursive();583 node->clearBackingStoresRecursive(); 633 584 634 585 m_directlyCompositedImages.clear(); 635 636 586 m_textureMapper.clear(); 637 587 m_backingStoresWithPendingBuffers.clear(); 638 588 m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeHost::PurgeBackingStores(), m_drawingAreaProxy->page()->pageID()); 639 589 }
Note: See TracChangeset
for help on using the changeset viewer.