Changeset 87167 in webkit
- Timestamp:
- May 24, 2011 10:41:33 AM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r87166 r87167 1 2011-05-24 Alok Priyadarshi <alokp@chromium.org> 2 3 Reviewed by James Robinson. 4 5 Enable skia gpu rendering for content layers 6 https://bugs.webkit.org/show_bug.cgi?id=56749 7 8 This patch adds gpu accelerated rendering for content and root layers. 9 Layer textures are updated in two stages: 10 1. Paint: The non-accelerated path paints the layer contents into a bitmap. 11 The accelerated path paints into an SkPicture, which is essentially a display list. 12 2. Upload: The non-accelerated path uploads the pixels obtained in the first stage to a texture. 13 The accelerated path renders the picture directly into the texture. 14 15 The accelerated path can be enabled by --enable-accelerated-drawing command-line flag in chromium. 16 Note that this patch does not accelerate the CG path on mac. We have two options here - use skia or accelrate CG path. 17 Any bugs should be caught by layout tests. 18 19 * platform/graphics/chromium/ContentLayerChromium.cpp: 20 (WebCore::ContentLayerChromium::createTextureUpdater): 21 * platform/graphics/chromium/LayerRendererChromium.cpp: 22 (WebCore::LayerRendererChromium::create): 23 (WebCore::LayerRendererChromium::LayerRendererChromium): 24 (WebCore::LayerRendererChromium::skiaContext): 25 (WebCore::LayerRendererChromium::updateAndDrawLayers): 26 (WebCore::LayerRendererChromium::createRootLayerTextureUpdater): 27 * platform/graphics/chromium/LayerRendererChromium.h: 28 (WebCore::LayerRendererChromium::acceleratedDrawing): 29 * platform/graphics/chromium/LayerTextureUpdaterCanvas.cpp: 30 (WebCore::LayerTextureUpdaterSkPicture::LayerTextureUpdaterSkPicture): 31 (WebCore::LayerTextureUpdaterSkPicture::~LayerTextureUpdaterSkPicture): 32 (WebCore::LayerTextureUpdaterSkPicture::prepareToUpdate): 33 (WebCore::LayerTextureUpdaterSkPicture::updateTextureRect): 34 (WebCore::LayerTextureUpdaterSkPicture::deleteFrameBuffer): 35 (WebCore::LayerTextureUpdaterSkPicture::createFrameBuffer): 36 (WebCore::LayerTextureUpdaterSkPicture::clearFrameBuffer): 37 * platform/graphics/chromium/LayerTextureUpdaterCanvas.h: 38 (WebCore::LayerTextureUpdaterSkPicture::orientation): 39 * platform/graphics/chromium/LayerTilerChromium.cpp: 40 (WebCore::LayerTilerChromium::updateRect): 41 (WebCore::LayerTilerChromium::draw): 42 1 43 2011-05-24 Pavel Podivilov <podivilov@chromium.org> 2 44 -
trunk/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp
r86816 r87167 129 129 { 130 130 OwnPtr<LayerPainterChromium> painter = adoptPtr(new ContentLayerPainter(m_owner)); 131 #if USE(SKIA) 132 if (layerRenderer()->accelerateDrawing()) 133 return adoptPtr(new LayerTextureUpdaterSkPicture(layerRendererContext(), painter.release(), layerRenderer()->skiaContext())); 134 #endif 131 135 return adoptPtr(new LayerTextureUpdaterBitmap(layerRendererContext(), painter.release(), layerRenderer()->contextSupportsMapSub())); 132 136 } -
trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
r86975 r87167 52 52 #include "cc/CCLayerImpl.h" 53 53 #if USE(SKIA) 54 #include "Extensions3D.h" 55 #include "GrContext.h" 54 56 #include "NativeImageSkia.h" 55 57 #include "PlatformContextSkia.h" … … 97 99 } 98 100 99 PassRefPtr<LayerRendererChromium> LayerRendererChromium::create(PassRefPtr<GraphicsContext3D> context, PassOwnPtr<LayerPainterChromium> contentPaint )101 PassRefPtr<LayerRendererChromium> LayerRendererChromium::create(PassRefPtr<GraphicsContext3D> context, PassOwnPtr<LayerPainterChromium> contentPaint, bool accelerateDrawing) 100 102 { 101 103 if (!context) 102 104 return 0; 103 105 104 RefPtr<LayerRendererChromium> layerRenderer(adoptRef(new LayerRendererChromium(context, contentPaint )));106 RefPtr<LayerRendererChromium> layerRenderer(adoptRef(new LayerRendererChromium(context, contentPaint, accelerateDrawing))); 105 107 if (!layerRenderer->hardwareCompositing()) 106 108 return 0; … … 110 112 111 113 LayerRendererChromium::LayerRendererChromium(PassRefPtr<GraphicsContext3D> context, 112 PassOwnPtr<LayerPainterChromium> contentPaint) 114 PassOwnPtr<LayerPainterChromium> contentPaint, 115 bool accelerateDrawing) 113 116 : m_viewportScrollPosition(IntPoint(-1, -1)) 114 117 , m_rootLayer(0) 118 , m_accelerateDrawing(accelerateDrawing) 115 119 , m_currentRenderSurface(0) 116 120 , m_offscreenFramebufferId(0) … … 128 132 m_hardwareCompositing = initializeSharedObjects(); 129 133 130 OwnPtr<LayerTextureUpdater> textureUpdater = adoptPtr(new LayerTextureUpdaterBitmap(m_context.get(), contentPaint, m_contextSupportsMapSub)); 131 m_rootLayerContentTiler = LayerTilerChromium::create(this, textureUpdater.release(), IntSize(256, 256), LayerTilerChromium::NoBorderTexels); 134 m_rootLayerContentTiler = LayerTilerChromium::create(this, createRootLayerTextureUpdater(contentPaint), IntSize(256, 256), LayerTilerChromium::NoBorderTexels); 132 135 ASSERT(m_rootLayerContentTiler); 133 136 … … 145 148 return m_context.get(); 146 149 } 150 151 #if USE(SKIA) 152 GrContext* LayerRendererChromium::skiaContext() 153 { 154 if (!m_skiaContext) { 155 WebCore::Extensions3D* extensions = m_context->getExtensions(); 156 extensions->ensureEnabled("GL_EXT_texture_format_BGRA8888"); 157 extensions->ensureEnabled("GL_EXT_read_format_bgra"); 158 159 m_skiaContext = adoptPtr(GrContext::CreateGLShaderContext()); 160 // Limit the number of textures we hold in the bitmap->texture cache. 161 static const int maxTextureCacheCount = 512; 162 // Limit the bytes allocated toward textures in the bitmap->texture cache. 163 static const size_t maxTextureCacheBytes = 50 * 1024 * 1024; 164 m_skiaContext->setTextureCacheLimits(maxTextureCacheCount, maxTextureCacheBytes); 165 } 166 return m_skiaContext.get(); 167 } 168 #endif 147 169 148 170 void LayerRendererChromium::debugGLCall(GraphicsContext3D* context, const char* command, const char* file, int line) … … 261 283 } 262 284 285 PassOwnPtr<LayerTextureUpdater> LayerRendererChromium::createRootLayerTextureUpdater(PassOwnPtr<LayerPainterChromium> painter) 286 { 287 #if USE(SKIA) 288 if (accelerateDrawing()) 289 return adoptPtr(new LayerTextureUpdaterSkPicture(context(), painter, skiaContext())); 290 #endif 291 return adoptPtr(new LayerTextureUpdaterBitmap(context(), painter, contextSupportsMapSub())); 292 } 293 263 294 void LayerRendererChromium::updateLayers(LayerList& renderSurfaceLayerList) 264 295 { -
trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h
r86975 r87167 59 59 #endif 60 60 61 #if USE(SKIA) 62 class GrContext; 63 #endif 64 61 65 namespace WebCore { 62 66 … … 70 74 class LayerRendererChromium : public RefCounted<LayerRendererChromium> { 71 75 public: 72 static PassRefPtr<LayerRendererChromium> create(PassRefPtr<GraphicsContext3D>, PassOwnPtr<LayerPainterChromium> contentPaint );76 static PassRefPtr<LayerRendererChromium> create(PassRefPtr<GraphicsContext3D>, PassOwnPtr<LayerPainterChromium> contentPaint, bool accelerateDrawing); 73 77 74 78 ~LayerRendererChromium(); … … 76 80 GraphicsContext3D* context(); 77 81 bool contextSupportsMapSub() const { return m_contextSupportsMapSub; } 82 #if USE(SKIA) 83 GrContext* skiaContext(); 84 #endif 78 85 79 86 void invalidateRootLayerRect(const IntRect& dirtyRect); … … 102 109 103 110 bool hardwareCompositing() const { return m_hardwareCompositing; } 111 bool accelerateDrawing() const { return m_accelerateDrawing; } 104 112 105 113 void setCompositeOffscreen(bool); … … 151 159 RefPtr<CCLayerImpl> m_rootCCLayerImpl; 152 160 153 LayerRendererChromium(PassRefPtr<GraphicsContext3D>, PassOwnPtr<LayerPainterChromium> contentPaint); 161 LayerRendererChromium(PassRefPtr<GraphicsContext3D>, PassOwnPtr<LayerPainterChromium> contentPaint, bool accelerateDrawing); 162 163 PassOwnPtr<LayerTextureUpdater> createRootLayerTextureUpdater(PassOwnPtr<LayerPainterChromium>); 154 164 155 165 void updateLayers(LayerList& renderSurfaceLayerList); … … 194 204 195 205 bool m_hardwareCompositing; 206 bool m_accelerateDrawing; 196 207 197 208 RenderSurfaceChromium* m_currentRenderSurface; 198 199 209 unsigned m_offscreenFramebufferId; 200 210 bool m_compositeOffscreen; … … 223 233 224 234 RefPtr<GraphicsContext3D> m_context; 235 #if USE(SKIA) 236 OwnPtr<GrContext> m_skiaContext; 237 #endif 238 225 239 ChildContextMap m_childContexts; 226 227 240 // If true, the child contexts were copied to the compositor texture targets 228 241 // and the compositor will need to wait on the proper latches before using -
trunk/Source/WebCore/platform/graphics/chromium/LayerTextureUpdaterCanvas.cpp
r86805 r87167 36 36 #include "TraceEvent.h" 37 37 38 #if USE(SKIA) 39 #include "GrContext.h" 40 #include "PlatformContextSkia.h" 41 #include "SkCanvas.h" 42 #include "SkGpuDevice.h" 43 #include "SkGpuDeviceFactory.h" 44 #endif // USE(SKIA) 45 38 46 namespace WebCore { 39 47 … … 82 90 } 83 91 92 #if USE(SKIA) 93 LayerTextureUpdaterSkPicture::LayerTextureUpdaterSkPicture(GraphicsContext3D* context, PassOwnPtr<LayerPainterChromium> painter, GrContext* skiaContext) 94 : LayerTextureUpdaterCanvas(context, painter) 95 , m_skiaContext(skiaContext) 96 , m_createFrameBuffer(false) 97 , m_fbo(0) 98 , m_stencilBuffer(0) 99 { 100 } 101 102 LayerTextureUpdaterSkPicture::~LayerTextureUpdaterSkPicture() 103 { 104 deleteFrameBuffer(); 105 } 106 107 void LayerTextureUpdaterSkPicture::prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels) 108 { 109 // Need to recreate FBO if tile-size changed. 110 // Note that we cannot create the framebuffer here because this function does not run in compositor thread 111 // and hence does not have access to compositor context. 112 if (m_bufferSize != tileSize) { 113 m_createFrameBuffer = true; 114 m_bufferSize = tileSize; 115 } 116 117 SkCanvas* canvas = m_picture.beginRecording(contentRect.width(), contentRect.height()); 118 PlatformContextSkia platformContext(canvas); 119 GraphicsContext graphicsContext(&platformContext); 120 paintContents(graphicsContext, contentRect); 121 m_picture.endRecording(); 122 } 123 124 void LayerTextureUpdaterSkPicture::updateTextureRect(LayerTexture* texture, const IntRect& sourceRect, const IntRect& destRect) 125 { 126 if (m_createFrameBuffer) { 127 deleteFrameBuffer(); 128 createFrameBuffer(); 129 m_createFrameBuffer = false; 130 } 131 if (!m_fbo) 132 return; 133 134 // Bind texture. 135 context()->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 136 texture->framebufferTexture2D(); 137 ASSERT(context()->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) == GraphicsContext3D::FRAMEBUFFER_COMPLETE); 138 139 context()->viewport(0, 0, m_bufferSize.width(), m_bufferSize.height()); 140 clearFrameBuffer(); 141 142 // Notify SKIA to sync its internal GL state. 143 m_skiaContext->resetContext(); 144 // Offset from source rectangle to this destination rectangle. 145 IntPoint offset(sourceRect.x() - contentRect().x(), sourceRect.y() - contentRect().y()); 146 m_canvas->save(); 147 m_canvas->translate(-offset.x(), -offset.y()); 148 m_canvas->drawPicture(m_picture); 149 m_canvas->restore(); 150 // Flush SKIA context so that all the rendered stuff appears on the texture. 151 m_skiaContext->flush(GrContext::kForceCurrentRenderTarget_FlushBit); 152 153 // Unbind texture. 154 context()->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, 0, 0); 155 context()->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0); 156 } 157 158 void LayerTextureUpdaterSkPicture::deleteFrameBuffer() 159 { 160 m_canvas.clear(); 161 162 if (m_stencilBuffer) 163 context()->deleteRenderbuffer(m_stencilBuffer); 164 if (m_fbo) 165 context()->deleteFramebuffer(m_fbo); 166 } 167 168 bool LayerTextureUpdaterSkPicture::createFrameBuffer() 169 { 170 ASSERT(!m_fbo); 171 ASSERT(!m_bufferSize.isEmpty()); 172 173 // SKIA needs stencil buffer for path rendering. 174 // Make sure it is available. 175 GraphicsContext3D::Attributes contextAttribs = context()->getContextAttributes(); 176 if (!contextAttribs.stencil) 177 return false; 178 179 // Create and bind a frame-buffer-object. 180 m_fbo = context()->createFramebuffer(); 181 if (!m_fbo) 182 return false; 183 context()->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 184 185 // We just need to create a stencil buffer for FBO. 186 // The color buffer (texture) will be provided by tiles. 187 // SKIA does not need depth buffer. 188 m_stencilBuffer = context()->createRenderbuffer(); 189 if (!m_stencilBuffer) { 190 context()->deleteFramebuffer(m_fbo); 191 m_fbo = 0; 192 return false; 193 } 194 context()->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_stencilBuffer); 195 context()->renderbufferStorage(GraphicsContext3D::RENDERBUFFER, GraphicsContext3D::STENCIL_INDEX8, m_bufferSize.width(), m_bufferSize.height()); 196 context()->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::STENCIL_ATTACHMENT, GraphicsContext3D::RENDERBUFFER, m_stencilBuffer); 197 198 // Create a skia gpu canvas. 199 GrPlatformSurfaceDesc targetDesc; 200 targetDesc.reset(); 201 targetDesc.fSurfaceType = kRenderTarget_GrPlatformSurfaceType; 202 targetDesc.fRenderTargetFlags = kNone_GrPlatformRenderTargetFlagBit; 203 targetDesc.fWidth = m_bufferSize.width(); 204 targetDesc.fHeight = m_bufferSize.height(); 205 targetDesc.fConfig = kRGBA_8888_GrPixelConfig; 206 targetDesc.fStencilBits = 8; 207 targetDesc.fPlatformRenderTarget = m_fbo; 208 SkAutoTUnref<GrRenderTarget> target(static_cast<GrRenderTarget*>(m_skiaContext->createPlatformSurface(targetDesc))); 209 SkAutoTUnref<SkDeviceFactory> factory(new SkGpuDeviceFactory(m_skiaContext, target.get())); 210 SkAutoTUnref<SkDevice> device(factory.get()->newDevice(0, SkBitmap::kARGB_8888_Config, m_bufferSize.width(), m_bufferSize.height(), false, false)); 211 m_canvas = adoptPtr(new SkCanvas(factory.get())); 212 m_canvas->setDevice(device.get()); 213 214 context()->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0); 215 return true; 216 } 217 218 void LayerTextureUpdaterSkPicture::clearFrameBuffer() 219 { 220 #ifndef NDEBUG 221 // Clear to green to make it easier to spot unrendered regions. 222 context()->clearColor(0, 1, 0, 1); 223 context()->clear(GraphicsContext3D::COLOR_BUFFER_BIT | GraphicsContext3D::STENCIL_BUFFER_BIT); 224 #endif 225 } 226 #endif // SKIA 227 84 228 } // namespace WebCore 85 229 #endif // USE(ACCELERATED_COMPOSITING) -
trunk/Source/WebCore/platform/graphics/chromium/LayerTextureUpdaterCanvas.h
r86805 r87167 30 30 #if USE(ACCELERATED_COMPOSITING) 31 31 32 #include "GraphicsTypes3D.h" 32 33 #include "LayerTextureSubImage.h" 33 34 #include "LayerTextureUpdater.h" 34 35 #include "PlatformCanvas.h" 35 36 #include <wtf/PassOwnPtr.h> 37 38 #if USE(SKIA) 39 #include "SkPicture.h" 40 41 class GrContext; 42 class SkCanvas; 43 class SkPicture; 44 #endif 36 45 37 46 namespace WebCore { … … 70 79 }; 71 80 81 #if USE(SKIA) 82 class LayerTextureUpdaterSkPicture : public LayerTextureUpdaterCanvas { 83 public: 84 LayerTextureUpdaterSkPicture(GraphicsContext3D*, PassOwnPtr<LayerPainterChromium>, GrContext*); 85 virtual ~LayerTextureUpdaterSkPicture(); 86 87 virtual Orientation orientation() { return LayerTextureUpdater::TopDownOrientation; } 88 virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels); 89 virtual void updateTextureRect(LayerTexture*, const IntRect& sourceRect, const IntRect& destRect); 90 91 private: 92 void deleteFrameBuffer(); 93 bool createFrameBuffer(); 94 void clearFrameBuffer(); 95 96 GrContext* m_skiaContext; // SKIA graphics context. 97 98 bool m_createFrameBuffer; // Need to create FBO if true. 99 SkPicture m_picture; // Recording canvas. 100 IntSize m_bufferSize; // Frame buffer size. 101 Platform3DObject m_fbo; // Frame buffer id. 102 Platform3DObject m_stencilBuffer; 103 OwnPtr<SkCanvas> m_canvas; // GPU accelerated canvas. 104 }; 105 #endif // SKIA 106 72 107 } // namespace WebCore 73 108 #endif // USE(ACCELERATED_COMPOSITING) -
trunk/Source/WebCore/platform/graphics/chromium/LayerTilerChromium.cpp
r86975 r87167 319 319 GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, filter)); 320 320 GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, filter)); 321 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0)); 321 322 322 323 m_textureUpdater->updateTextureRect(tile->texture(), sourceRect, destRect); … … 340 341 GLC(context, context->useProgram(program->program())); 341 342 GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0)); 343 GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0)); 342 344 343 345 int left, top, right, bottom; -
trunk/Source/WebKit/chromium/ChangeLog
r87146 r87167 1 2011-05-24 Alok Priyadarshi <alokp@chromium.org> 2 3 Reviewed by James Robinson. 4 5 Enable skia gpu rendering for content layers 6 https://bugs.webkit.org/show_bug.cgi?id=56749 7 8 * src/WebViewImpl.cpp: 9 (WebKit::WebViewImpl::setIsAcceleratedCompositingActive): 10 (WebKit::WebViewImpl::reallocateRenderer): 11 1 12 2011-05-24 Mikhail Naganov <mnaganov@chromium.org> 2 13 -
trunk/Source/WebKit/chromium/src/WebViewImpl.cpp
r86816 r87167 2479 2479 2480 2480 2481 m_layerRenderer = LayerRendererChromium::create(context.release(), WebViewImplContentPainter::create(this) );2481 m_layerRenderer = LayerRendererChromium::create(context.release(), WebViewImplContentPainter::create(this), m_page->settings()->acceleratedDrawingEnabled()); 2482 2482 if (m_layerRenderer) { 2483 2483 m_client->didActivateAcceleratedCompositing(true); … … 2523 2523 getCompositorContextAttributes(), m_page->chrome(), GraphicsContext3D::RenderDirectlyToHostWindow); 2524 2524 // GraphicsContext3D::create might fail and return 0, in that case LayerRendererChromium::create will also return 0. 2525 RefPtr<LayerRendererChromium> layerRenderer = LayerRendererChromium::create(newContext, WebViewImplContentPainter::create(this) );2525 RefPtr<LayerRendererChromium> layerRenderer = LayerRendererChromium::create(newContext, WebViewImplContentPainter::create(this), m_page->settings()->acceleratedDrawingEnabled()); 2526 2526 2527 2527 // Reattach the root layer. Child layers will get reattached as a side effect of updateLayersRecursive.
Note: See TracChangeset
for help on using the changeset viewer.