[chromium] Set opaque flag for ImageLayerChromium
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2011 21:37:29 +0000 (21:37 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2011 21:37:29 +0000 (21:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=72964

Patch by Dana Jansens <danakj@chromium.org> on 2011-12-06
Reviewed by James Robinson.

Source/WebCore:

Unit test in tests/ImageLayerChromiumTest.cpp.

* platform/graphics/chromium/GraphicsLayerChromium.cpp:
(WebCore::GraphicsLayerChromium::setContentsToImage):
* platform/graphics/chromium/GraphicsLayerChromium.h:
(WebCore::GraphicsLayerChromium::contentsLayer):
* platform/graphics/chromium/ImageLayerChromium.cpp:
(WebCore::ImageLayerChromium::setContents):

Source/WebKit/chromium:

* WebKit.gypi:
* tests/DragImageTest.cpp:
(WebCore::TestImage::TestImage):
(WebCore::TestImage::nativeImageForCurrentFrame):
* tests/ImageLayerChromiumTest.cpp: Added.
(WebCore::MockGraphicsLayerClient::notifyAnimationStarted):
(WebCore::MockGraphicsLayerClient::notifySyncRequired):
(WebCore::MockGraphicsLayerClient::paintContents):
(WebCore::MockGraphicsLayerClient::showDebugBorders):
(WebCore::MockGraphicsLayerClient::showRepaintCounter):
(WebCore::TestImage::create):
(WebCore::TestImage::TestImage):
(WebCore::TestImage::isBitmapImage):
(WebCore::TestImage::currentFrameHasAlpha):
(WebCore::TestImage::size):
(WebCore::TestImage::nativeImageForCurrentFrame):
(WebCore::TestImage::destroyDecodedData):
(WebCore::TestImage::decodedSize):
(WebCore::TestImage::draw):
(WebCore::TEST):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp
Source/WebCore/platform/graphics/chromium/GraphicsLayerChromium.h
Source/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gypi
Source/WebKit/chromium/tests/DragImageTest.cpp
Source/WebKit/chromium/tests/ImageLayerChromiumTest.cpp [new file with mode: 0644]

index e5fea13..11c54ab 100644 (file)
@@ -1,3 +1,19 @@
+2011-12-06  Dana Jansens  <danakj@chromium.org>
+
+        [chromium] Set opaque flag for ImageLayerChromium
+        https://bugs.webkit.org/show_bug.cgi?id=72964
+
+        Reviewed by James Robinson.
+
+        Unit test in tests/ImageLayerChromiumTest.cpp.
+
+        * platform/graphics/chromium/GraphicsLayerChromium.cpp:
+        (WebCore::GraphicsLayerChromium::setContentsToImage):
+        * platform/graphics/chromium/GraphicsLayerChromium.h:
+        (WebCore::GraphicsLayerChromium::contentsLayer):
+        * platform/graphics/chromium/ImageLayerChromium.cpp:
+        (WebCore::ImageLayerChromium::setContents):
+
 2011-12-06  Alexandre Elias  <aelias@google.com>
 
         [chromium] Apply sent deltas on finishCommit
index 55e8ad9..c66be7a 100644 (file)
@@ -350,6 +350,7 @@ void GraphicsLayerChromium::setContentsToImage(Image* image)
         }
         ImageLayerChromium* imageLayer = static_cast<ImageLayerChromium*>(m_contentsLayer.get());
         imageLayer->setContents(image);
+        imageLayer->setOpaque(image->isBitmapImage() && !image->currentFrameHasAlpha());
         updateContentsRect();
     } else {
         if (m_contentsLayer) {
index b05d07b..df2698a 100644 (file)
@@ -101,6 +101,9 @@ public:
     virtual void paintContents(GraphicsContext&, const IntRect& clip);
     virtual void notifySyncRequired();
 
+    // Exposed for tests.
+    LayerChromium* contentsLayer() const { return m_contentsLayer.get(); }
+
 private:
     void updateOpacityOnLayer();
 
@@ -128,7 +131,6 @@ private:
     void updateContentsScale();
 
     void setupContentsLayer(LayerChromium*);
-    LayerChromium* contentsLayer() const { return m_contentsLayer.get(); }
     float contentsScale() const;
 
     String m_nameBase;
index 70afdd0..4eb65d4 100644 (file)
@@ -164,7 +164,6 @@ void ImageLayerChromium::setContents(Image* contents)
     m_contents = contents;
     m_imageForCurrentFrame = m_contents->nativeImageForCurrentFrame();
     setNeedsDisplay();
-    setOpaque(!m_contents->currentFrameHasAlpha());
 }
 
 void ImageLayerChromium::paintContentsIfDirty()
index 56463bf..d831a49 100644 (file)
@@ -1,3 +1,31 @@
+2011-12-06  Dana Jansens  <danakj@chromium.org>
+
+        [chromium] Set opaque flag for ImageLayerChromium
+        https://bugs.webkit.org/show_bug.cgi?id=72964
+
+        Reviewed by James Robinson.
+
+        * WebKit.gypi:
+        * tests/DragImageTest.cpp:
+        (WebCore::TestImage::TestImage):
+        (WebCore::TestImage::nativeImageForCurrentFrame):
+        * tests/ImageLayerChromiumTest.cpp: Added.
+        (WebCore::MockGraphicsLayerClient::notifyAnimationStarted):
+        (WebCore::MockGraphicsLayerClient::notifySyncRequired):
+        (WebCore::MockGraphicsLayerClient::paintContents):
+        (WebCore::MockGraphicsLayerClient::showDebugBorders):
+        (WebCore::MockGraphicsLayerClient::showRepaintCounter):
+        (WebCore::TestImage::create):
+        (WebCore::TestImage::TestImage):
+        (WebCore::TestImage::isBitmapImage):
+        (WebCore::TestImage::currentFrameHasAlpha):
+        (WebCore::TestImage::size):
+        (WebCore::TestImage::nativeImageForCurrentFrame):
+        (WebCore::TestImage::destroyDecodedData):
+        (WebCore::TestImage::decodedSize):
+        (WebCore::TestImage::draw):
+        (WebCore::TEST):
+
 2011-12-06  Adam Klein  <adamk@chromium.org>
 
         [chromium] Guard access to WebKitPlatformSupport::currentThread with a null check
index b1f9edf..db99897 100644 (file)
         ],
 
         'conditions': [
-            ['OS=="win"', {
+            ['use_skia == 1', {
                 'webkit_unittest_files': [
-                    # FIXME: Port DragImageTest to Mac.
                     'tests/DragImageTest.cpp',
+                    'tests/ImageLayerChromiumTest.cpp',
+                ],
+            }],
+            ['OS=="win"', {
+                'webkit_unittest_files': [
                     # FIXME: Port PopupMenuTest to Linux and Mac.
                     'tests/PopupMenuTest.cpp',
                     'tests/TransparencyWinTest.cpp',
             }],
             ['toolkit_uses_gtk == 1', {
                 'webkit_unittest_files': [
-                    # FIXME: Port DragImageTest to Mac.
-                    'tests/DragImageTest.cpp',
                     'tests/WebInputEventFactoryTestGtk.cpp',
                 ],
             }],
index a49a723..080607c 100644 (file)
 
 #include "config.h"
 
-#include <gtest/gtest.h>
-
 #include "DragImage.h"
+
 #include "Image.h"
 #include "NativeImageSkia.h"
+#include <gtest/gtest.h>
+#include <wtf/PassOwnPtr.h>
 
 using namespace WebCore;
 
@@ -52,17 +53,12 @@ public:
         : Image(0)
         , m_size(size)
     {
-        m_nativeImage = new NativeImageSkia();
+        m_nativeImage = adoptPtr(new NativeImageSkia());
         m_nativeImage->bitmap().setConfig(SkBitmap::kARGB_8888_Config,
                                           size.width(), size.height(), 0);
         m_nativeImage->bitmap().allocPixels();
     }
 
-    virtual ~TestImage()
-    {
-        delete m_nativeImage;
-    }
-
     virtual IntSize size() const
     {
         return m_size;
@@ -73,7 +69,7 @@ public:
         if (m_size.isZero())
             return 0;
 
-        return m_nativeImage;
+        return m_nativeImage.get();
     }
 
     // Stub implementations of pure virtual Image functions.
@@ -96,7 +92,7 @@ private:
 
     IntSize m_size;
 
-    NativeImagePtr m_nativeImage;
+    OwnPtr<NativeImagePtr> m_nativeImage;
 };
 
 TEST(DragImageTest, NullHandling)
diff --git a/Source/WebKit/chromium/tests/ImageLayerChromiumTest.cpp b/Source/WebKit/chromium/tests/ImageLayerChromiumTest.cpp
new file mode 100644 (file)
index 0000000..b28f8e8
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * 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 INC. 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 INC. 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"
+
+#include "ImageLayerChromium.h"
+
+#include "GraphicsLayer.h"
+#include "GraphicsLayerChromium.h"
+#include "NativeImageSkia.h"
+#include <gtest/gtest.h>
+#include <wtf/PassOwnPtr.h>
+
+using namespace WebCore;
+
+namespace {
+
+class MockGraphicsLayerClient : public GraphicsLayerClient {
+  public:
+    virtual void notifyAnimationStarted(const GraphicsLayer*, double time) { }
+    virtual void notifySyncRequired(const GraphicsLayer*) { }
+    virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect& inClip) { }
+    virtual bool showDebugBorders() const { return false; }
+    virtual bool showRepaintCounter() const { return false; }
+};
+
+class TestImage : public Image {
+public:
+
+    static PassRefPtr<TestImage> create(const IntSize& size, bool opaque)
+    {
+        return adoptRef(new TestImage(size, opaque));
+    }
+
+    explicit TestImage(const IntSize& size, bool opaque)
+        : Image(0)
+        , m_size(size)
+    {
+        m_nativeImage = adoptPtr(new NativeImageSkia());
+        m_nativeImage->bitmap().setConfig(SkBitmap::kARGB_8888_Config,
+                                          size.width(), size.height(), 0);
+        m_nativeImage->bitmap().allocPixels();
+        m_nativeImage->bitmap().setIsOpaque(opaque);
+    }
+
+    virtual bool isBitmapImage() const
+    {
+        return true;
+    }
+
+    virtual bool currentFrameHasAlpha()
+    {
+        return !m_nativeImage->bitmap().isOpaque();
+    }
+
+    virtual IntSize size() const
+    {
+        return m_size;
+    }
+
+    virtual NativeImagePtr nativeImageForCurrentFrame()
+    {
+        if (m_size.isZero())
+            return 0;
+
+        return m_nativeImage.get();
+    }
+
+    // Stub implementations of pure virtual Image functions.
+    virtual void destroyDecodedData(bool)
+    {
+    }
+
+    virtual unsigned int decodedSize() const
+    {
+        return 0u;
+    }
+
+    virtual void draw(WebCore::GraphicsContext*, const WebCore::FloatRect&,
+                      const WebCore::FloatRect&, WebCore::ColorSpace,
+                      WebCore::CompositeOperator)
+    {
+    }
+
+private:
+
+    IntSize m_size;
+
+    OwnPtr<NativeImagePtr> m_nativeImage;
+};
+
+TEST(ImageLayerChromiumTest, opaqueImages)
+{
+    MockGraphicsLayerClient client;
+    OwnPtr<GraphicsLayerChromium> graphicsLayer = static_pointer_cast<GraphicsLayerChromium>(GraphicsLayer::create(&client));
+    ASSERT_TRUE(graphicsLayer.get());
+
+    RefPtr<Image> opaqueImage = TestImage::create(IntSize(100, 100), true);
+    ASSERT_TRUE(opaqueImage.get());
+    RefPtr<Image> nonOpaqueImage = TestImage::create(IntSize(100, 100), false);
+    ASSERT_TRUE(nonOpaqueImage.get());
+
+    ASSERT_FALSE(graphicsLayer->contentsLayer());
+
+    graphicsLayer->setContentsToImage(opaqueImage.get());
+    ASSERT_TRUE(graphicsLayer->contentsLayer()->opaque());
+
+    graphicsLayer->setContentsToImage(nonOpaqueImage.get());
+    ASSERT_FALSE(graphicsLayer->contentsLayer()->opaque());
+}
+
+} // namespace