[Chromium] Implement tile-sized painting using SkPicture.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2011 22:37:12 +0000 (22:37 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2011 22:37:12 +0000 (22:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=71869

Patch by David Reveman <reveman@chromium.org> on 2011-12-06
Reviewed by James Robinson.

Source/WebCore:

Add texture uploader that paints tile-sized chunks using SkPicture
recording and playback. Expose setting which allows this texture
updater to be enabled.

No new tests. Covered by existing tests.

* WebCore.gypi:
* platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.cpp: Added.
(WebCore::BitmapSkPictureCanvasLayerTextureUpdater::Texture::Texture):
(WebCore::BitmapSkPictureCanvasLayerTextureUpdater::Texture::prepareRect):
(WebCore::BitmapSkPictureCanvasLayerTextureUpdater::Texture::updateRect):
(WebCore::BitmapSkPictureCanvasLayerTextureUpdater::create):
(WebCore::BitmapSkPictureCanvasLayerTextureUpdater::BitmapSkPictureCanvasLayerTextureUpdater):
(WebCore::BitmapSkPictureCanvasLayerTextureUpdater::~BitmapSkPictureCanvasLayerTextureUpdater):
(WebCore::BitmapSkPictureCanvasLayerTextureUpdater::createTexture):
(WebCore::BitmapSkPictureCanvasLayerTextureUpdater::sampledTexelFormat):
(WebCore::BitmapSkPictureCanvasLayerTextureUpdater::prepareToUpdate):
(WebCore::BitmapSkPictureCanvasLayerTextureUpdater::paintContentsRect):
(WebCore::BitmapSkPictureCanvasLayerTextureUpdater::updateTextureRect):
* platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.h: Added.
(WebCore::BitmapSkPictureCanvasLayerTextureUpdater::Texture::textureUpdater):
(WebCore::BitmapSkPictureCanvasLayerTextureUpdater::orientation):
* platform/graphics/chromium/ContentLayerChromium.cpp:
(WebCore::ContentLayerChromium::createTextureUpdater):
* platform/graphics/chromium/cc/CCLayerTreeHost.h:
(WebCore::CCSettings::CCSettings):

Source/WebKit/chromium:

Add perTilePainting setting that is used by compositor to determine
what texture uploader to use.

* public/WebSettings.h:
* src/WebSettingsImpl.cpp:
(WebKit::WebSettingsImpl::WebSettingsImpl):
(WebKit::WebSettingsImpl::setPerTilePainting):
* src/WebSettingsImpl.h:
(WebKit::WebSettingsImpl::perTilePainting):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::setIsAcceleratedCompositingActive):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@102181 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.h [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/public/WebSettings.h
Source/WebKit/chromium/src/WebSettingsImpl.cpp
Source/WebKit/chromium/src/WebSettingsImpl.h
Source/WebKit/chromium/src/WebViewImpl.cpp

index d02e6b3..4d0da4d 100644 (file)
@@ -1,3 +1,37 @@
+2011-12-06  David Reveman  <reveman@chromium.org>
+
+        [Chromium] Implement tile-sized painting using SkPicture.
+        https://bugs.webkit.org/show_bug.cgi?id=71869
+
+        Reviewed by James Robinson.
+
+        Add texture uploader that paints tile-sized chunks using SkPicture
+        recording and playback. Expose setting which allows this texture
+        updater to be enabled.
+
+        No new tests. Covered by existing tests.
+
+        * WebCore.gypi:
+        * platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.cpp: Added.
+        (WebCore::BitmapSkPictureCanvasLayerTextureUpdater::Texture::Texture):
+        (WebCore::BitmapSkPictureCanvasLayerTextureUpdater::Texture::prepareRect):
+        (WebCore::BitmapSkPictureCanvasLayerTextureUpdater::Texture::updateRect):
+        (WebCore::BitmapSkPictureCanvasLayerTextureUpdater::create):
+        (WebCore::BitmapSkPictureCanvasLayerTextureUpdater::BitmapSkPictureCanvasLayerTextureUpdater):
+        (WebCore::BitmapSkPictureCanvasLayerTextureUpdater::~BitmapSkPictureCanvasLayerTextureUpdater):
+        (WebCore::BitmapSkPictureCanvasLayerTextureUpdater::createTexture):
+        (WebCore::BitmapSkPictureCanvasLayerTextureUpdater::sampledTexelFormat):
+        (WebCore::BitmapSkPictureCanvasLayerTextureUpdater::prepareToUpdate):
+        (WebCore::BitmapSkPictureCanvasLayerTextureUpdater::paintContentsRect):
+        (WebCore::BitmapSkPictureCanvasLayerTextureUpdater::updateTextureRect):
+        * platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.h: Added.
+        (WebCore::BitmapSkPictureCanvasLayerTextureUpdater::Texture::textureUpdater):
+        (WebCore::BitmapSkPictureCanvasLayerTextureUpdater::orientation):
+        * platform/graphics/chromium/ContentLayerChromium.cpp:
+        (WebCore::ContentLayerChromium::createTextureUpdater):
+        * platform/graphics/chromium/cc/CCLayerTreeHost.h:
+        (WebCore::CCSettings::CCSettings):
+
 2011-12-06  Adrienne Walker  <enne@google.com>
 
         [chromium] Don't crash if tile upload happens without painting first
index 27ee427..ed398f8 100644 (file)
             'platform/graphics/cg/TransformationMatrixCG.cpp',
             'platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.cpp',
             'platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.h',
+            'platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.cpp',
+            'platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.h',
             'platform/graphics/chromium/Canvas2DLayerChromium.cpp',
             'platform/graphics/chromium/Canvas2DLayerChromium.h',
             'platform/graphics/chromium/CanvasLayerChromium.cpp',
diff --git a/Source/WebCore/platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.cpp b/Source/WebCore/platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.cpp
new file mode 100644 (file)
index 0000000..8221dd2
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "config.h"
+
+#if USE(ACCELERATED_COMPOSITING)
+#if USE(SKIA)
+
+#include "BitmapSkPictureCanvasLayerTextureUpdater.h"
+
+#include "LayerPainterChromium.h"
+#include "SkCanvas.h"
+#include "skia/ext/platform_canvas.h"
+
+namespace WebCore {
+
+BitmapSkPictureCanvasLayerTextureUpdater::Texture::Texture(BitmapSkPictureCanvasLayerTextureUpdater* textureUpdater, PassOwnPtr<ManagedTexture> texture)
+    : CanvasLayerTextureUpdater::Texture(texture)
+    , m_textureUpdater(textureUpdater)
+{
+}
+
+void BitmapSkPictureCanvasLayerTextureUpdater::Texture::prepareRect(const IntRect& sourceRect)
+{
+    size_t bufferSize = TextureManager::memoryUseBytes(sourceRect.size(), texture()->format());
+    m_pixelData = adoptArrayPtr(new uint8_t[bufferSize]);
+    OwnPtr<SkCanvas> canvas = adoptPtr(new skia::PlatformCanvas(sourceRect.width(), sourceRect.height(), false, m_pixelData.get()));
+    textureUpdater()->paintContentsRect(canvas.get(), sourceRect);
+}
+
+void BitmapSkPictureCanvasLayerTextureUpdater::Texture::updateRect(GraphicsContext3D* context, TextureAllocator* allocator, const IntRect& sourceRect, const IntRect& destRect)
+{
+    texture()->bindTexture(context, allocator);
+    ASSERT(m_pixelData.get());
+    textureUpdater()->updateTextureRect(context, texture()->format(), destRect, m_pixelData.get());
+    m_pixelData.clear();
+}
+
+PassRefPtr<BitmapSkPictureCanvasLayerTextureUpdater> BitmapSkPictureCanvasLayerTextureUpdater::create(PassOwnPtr<LayerPainterChromium> painter, bool useMapTexSubImage)
+{
+    return adoptRef(new BitmapSkPictureCanvasLayerTextureUpdater(painter, useMapTexSubImage));
+}
+
+BitmapSkPictureCanvasLayerTextureUpdater::BitmapSkPictureCanvasLayerTextureUpdater(PassOwnPtr<LayerPainterChromium> painter, bool useMapTexSubImage)
+    : SkPictureCanvasLayerTextureUpdater(painter)
+    , m_texSubImage(useMapTexSubImage)
+{
+}
+
+BitmapSkPictureCanvasLayerTextureUpdater::~BitmapSkPictureCanvasLayerTextureUpdater()
+{
+}
+
+PassOwnPtr<LayerTextureUpdater::Texture> BitmapSkPictureCanvasLayerTextureUpdater::createTexture(TextureManager* manager)
+{
+    return adoptPtr(new Texture(this, ManagedTexture::create(manager)));
+}
+
+LayerTextureUpdater::SampledTexelFormat BitmapSkPictureCanvasLayerTextureUpdater::sampledTexelFormat(GC3Denum textureFormat)
+{
+    // The component order may be bgra if we uploaded bgra pixels to rgba textures.
+    return PlatformColor::sameComponentOrder(textureFormat) ?
+            LayerTextureUpdater::SampledTexelFormatRGBA : LayerTextureUpdater::SampledTexelFormatBGRA;
+}
+
+void BitmapSkPictureCanvasLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels, float contentsScale)
+{
+    m_texSubImage.setSubImageSize(tileSize);
+    SkPictureCanvasLayerTextureUpdater::prepareToUpdate(contentRect, tileSize, borderTexels, contentsScale);
+}
+
+void BitmapSkPictureCanvasLayerTextureUpdater::paintContentsRect(SkCanvas* canvas, const IntRect& sourceRect)
+{
+    // Translate the origin of contentRect to that of sourceRect.
+    canvas->translate(contentRect().x() - sourceRect.x(),
+                      contentRect().y() - sourceRect.y());
+    drawPicture(canvas);
+}
+
+void BitmapSkPictureCanvasLayerTextureUpdater::updateTextureRect(GraphicsContext3D* context, GC3Denum format, const IntRect& destRect, const uint8_t* pixels)
+{
+    m_texSubImage.upload(pixels, destRect, destRect, destRect, format, context);
+}
+
+} // namespace WebCore
+#endif // USE(SKIA)
+#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/Source/WebCore/platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.h b/Source/WebCore/platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.h
new file mode 100644 (file)
index 0000000..c30f307
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#ifndef BitmapSkPictureCanvasLayerTextureUpdater_h
+#define BitmapSkPictureCanvasLayerTextureUpdater_h
+
+#if USE(ACCELERATED_COMPOSITING)
+#if USE(SKIA)
+
+#include "LayerTextureSubImage.h"
+#include "PlatformColor.h"
+#include "SkPictureCanvasLayerTextureUpdater.h"
+
+namespace WebCore {
+
+class BitmapSkPictureCanvasLayerTextureUpdater : public SkPictureCanvasLayerTextureUpdater {
+public:
+    class Texture : public CanvasLayerTextureUpdater::Texture {
+    public:
+        Texture(BitmapSkPictureCanvasLayerTextureUpdater*, PassOwnPtr<ManagedTexture>);
+
+        virtual void prepareRect(const IntRect& sourceRect);
+        virtual void updateRect(GraphicsContext3D*, TextureAllocator*, const IntRect& sourceRect, const IntRect& destRect);
+
+    private:
+        BitmapSkPictureCanvasLayerTextureUpdater* textureUpdater() { return m_textureUpdater; }
+
+        OwnArrayPtr<uint8_t> m_pixelData;
+        BitmapSkPictureCanvasLayerTextureUpdater* m_textureUpdater;
+    };
+
+    static PassRefPtr<BitmapSkPictureCanvasLayerTextureUpdater> create(PassOwnPtr<LayerPainterChromium>, bool useMapTexSubImage);
+    virtual ~BitmapSkPictureCanvasLayerTextureUpdater();
+
+    virtual PassOwnPtr<LayerTextureUpdater::Texture> createTexture(TextureManager*);
+    virtual Orientation orientation() { return LayerTextureUpdater::BottomUpOrientation; }
+    virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat);
+    virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels, float contentsScale);
+    void paintContentsRect(SkCanvas*, const IntRect& sourceRect);
+    void updateTextureRect(GraphicsContext3D*, GC3Denum format, const IntRect& destRect, const uint8_t* pixels);
+
+private:
+    BitmapSkPictureCanvasLayerTextureUpdater(PassOwnPtr<LayerPainterChromium>, bool useMapTexSubImage);
+
+    LayerTextureSubImage m_texSubImage;
+};
+} // namespace WebCore
+#endif // USE(SKIA)
+#endif // USE(ACCELERATED_COMPOSITING)
+#endif // BitmapSkPictureCanvasLayerTextureUpdater_h
index 3aec3eb..2a2466d 100644 (file)
@@ -35,6 +35,7 @@
 #include "ContentLayerChromium.h"
 
 #include "BitmapCanvasLayerTextureUpdater.h"
+#include "BitmapSkPictureCanvasLayerTextureUpdater.h"
 #include "FrameBufferSkPictureCanvasLayerTextureUpdater.h"
 #include "LayerPainterChromium.h"
 #include "LayerRendererChromium.h"
@@ -120,6 +121,11 @@ void ContentLayerChromium::createTextureUpdater(const CCLayerTreeHost* host)
         m_textureUpdater = FrameBufferSkPictureCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_delegate));
         return;
     }
+
+    if (host->settings().perTilePainting) {
+        m_textureUpdater = BitmapSkPictureCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_delegate), host->layerRendererCapabilities().usingMapSub);
+        return;
+    }
 #endif // USE(SKIA)
 
     m_textureUpdater = BitmapCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_delegate), host->layerRendererCapabilities().usingMapSub);
index 872c3c8..aaad142 100644 (file)
@@ -73,13 +73,15 @@ struct CCSettings {
             , compositeOffscreen(false)
             , showFPSCounter(false)
             , showPlatformLayerTree(false)
-            , refreshRate(0) { }
+            , refreshRate(0)
+            , perTilePainting(false) { }
 
     bool acceleratePainting;
     bool compositeOffscreen;
     bool showFPSCounter;
     bool showPlatformLayerTree;
     double refreshRate;
+    bool perTilePainting;
 };
 
 // Provides information on an Impl's rendering capabilities back to the CCLayerTreeHost
index d831a49..5139cb2 100644 (file)
@@ -1,3 +1,22 @@
+2011-12-06  David Reveman  <reveman@chromium.org>
+
+        [Chromium] Implement tile-sized painting using SkPicture.
+        https://bugs.webkit.org/show_bug.cgi?id=71869
+
+        Reviewed by James Robinson.
+
+        Add perTilePainting setting that is used by compositor to determine
+        what texture uploader to use.
+
+        * public/WebSettings.h:
+        * src/WebSettingsImpl.cpp:
+        (WebKit::WebSettingsImpl::WebSettingsImpl):
+        (WebKit::WebSettingsImpl::setPerTilePainting):
+        * src/WebSettingsImpl.h:
+        (WebKit::WebSettingsImpl::perTilePainting):
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::setIsAcceleratedCompositingActive):
+
 2011-12-06  Dana Jansens  <danakj@chromium.org>
 
         [chromium] Set opaque flag for ImageLayerChromium
index d28aba1..e2e743a 100644 (file)
@@ -133,6 +133,8 @@ public:
     virtual void setEnableScrollAnimator(bool) = 0;
     virtual void setHixie76WebSocketProtocolEnabled(bool) = 0;
     virtual void setVisualWordMovementEnabled(bool) = 0;
+    virtual void setPerTilePainting(bool) = 0;
+    virtual bool perTilePainting() const = 0;
 
 protected:
     ~WebSettings() { }
index 20f2345..06ee010 100644 (file)
@@ -50,6 +50,7 @@ WebSettingsImpl::WebSettingsImpl(Settings* settings)
     , m_compositeToTextureEnabled(false)
     , m_showFPSCounter(false)
     , m_showPlatformLayerTree(false)
+    , m_perTilePainting(false)
 {
     ASSERT(settings);
 }
@@ -498,4 +499,9 @@ void WebSettingsImpl::setShouldDisplayTextDescriptions(bool enabled)
 }
 
 
+void WebSettingsImpl::setPerTilePainting(bool enabled)
+{
+    m_perTilePainting = enabled;
+}
+
 } // namespace WebKit
index 2c23cc2..88e25e9 100644 (file)
@@ -128,12 +128,15 @@ public:
     virtual void setShouldDisplaySubtitles(bool);
     virtual void setShouldDisplayCaptions(bool);
     virtual void setShouldDisplayTextDescriptions(bool);
+    virtual void setPerTilePainting(bool);
+    virtual bool perTilePainting() const { return m_perTilePainting; }
 
 private:
     WebCore::Settings* m_settings;
     bool m_compositeToTextureEnabled;
     bool m_showFPSCounter;
     bool m_showPlatformLayerTree;
+    bool m_perTilePainting;
 };
 
 } // namespace WebKit
index 06c0972..6315b52 100644 (file)
@@ -2898,10 +2898,13 @@ void WebViewImpl::setIsAcceleratedCompositingActive(bool active)
         ccSettings.showFPSCounter = settings()->showFPSCounter();
         ccSettings.showPlatformLayerTree = settings()->showPlatformLayerTree();
         ccSettings.refreshRate = screenRefreshRate(page()->mainFrame()->view());
+
         ASSERT(ccSettings.refreshRate >= 0);
         if (!ccSettings.refreshRate)
             ccSettings.refreshRate = defaultRefreshRate;
 
+        ccSettings.perTilePainting = settings()->perTilePainting();
+
         m_nonCompositedContentHost = NonCompositedContentHost::create(WebViewImplContentPainter::create(this));
         m_layerTreeHost = CCLayerTreeHost::create(this, ccSettings);
         if (m_layerTreeHost) {