OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 27 matching lines...) Expand all Loading... |
38 class MockGraphicsLayerClient : public GraphicsLayerClient { | 38 class MockGraphicsLayerClient : public GraphicsLayerClient { |
39 public: | 39 public: |
40 virtual void notifyAnimationStarted(const GraphicsLayer*, double monotonicTi
me) OVERRIDE { } | 40 virtual void notifyAnimationStarted(const GraphicsLayer*, double monotonicTi
me) OVERRIDE { } |
41 virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsL
ayerPaintingPhase, const IntRect& inClip) OVERRIDE { } | 41 virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsL
ayerPaintingPhase, const IntRect& inClip) OVERRIDE { } |
42 virtual String debugName(const GraphicsLayer*) OVERRIDE { return String(); } | 42 virtual String debugName(const GraphicsLayer*) OVERRIDE { return String(); } |
43 }; | 43 }; |
44 | 44 |
45 class TestImage : public Image { | 45 class TestImage : public Image { |
46 public: | 46 public: |
47 | 47 |
48 static PassRefPtr<TestImage> create(const IntSize& size, SkAlphaType alphaTy
pe) | 48 static PassRefPtr<TestImage> create(const IntSize& size, bool isOpaque) |
49 { | 49 { |
50 return adoptRef(new TestImage(size, alphaType)); | 50 return adoptRef(new TestImage(size, isOpaque)); |
51 } | 51 } |
52 | 52 |
53 explicit TestImage(const IntSize& size, SkAlphaType alphaType) | 53 explicit TestImage(const IntSize& size, bool isOpaque) |
54 : Image(0) | 54 : Image(0) |
55 , m_size(size) | 55 , m_size(size) |
56 { | 56 { |
57 m_nativeImage = NativeImageSkia::create(); | 57 m_nativeImage = NativeImageSkia::create(); |
58 m_nativeImage->bitmap().setConfig(SkBitmap::kARGB_8888_Config, size.widt
h(), size.height(), 0, alphaType); | 58 EXPECT_TRUE(m_nativeImage->bitmap().allocN32Pixels(size.width(), size.he
ight(), isOpaque)); |
59 m_nativeImage->bitmap().allocPixels(); | |
60 } | 59 } |
61 | 60 |
62 virtual bool isBitmapImage() const OVERRIDE | 61 virtual bool isBitmapImage() const OVERRIDE |
63 { | 62 { |
64 return true; | 63 return true; |
65 } | 64 } |
66 | 65 |
67 virtual bool currentFrameKnownToBeOpaque() OVERRIDE | 66 virtual bool currentFrameKnownToBeOpaque() OVERRIDE |
68 { | 67 { |
69 return m_nativeImage->bitmap().isOpaque(); | 68 return m_nativeImage->bitmap().isOpaque(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 104 |
106 virtual blink::WebLayer* contentsLayer() const { return GraphicsLayer::conte
ntsLayer(); } | 105 virtual blink::WebLayer* contentsLayer() const { return GraphicsLayer::conte
ntsLayer(); } |
107 }; | 106 }; |
108 | 107 |
109 TEST(ImageLayerChromiumTest, opaqueImages) | 108 TEST(ImageLayerChromiumTest, opaqueImages) |
110 { | 109 { |
111 MockGraphicsLayerClient client; | 110 MockGraphicsLayerClient client; |
112 OwnPtr<GraphicsLayerForTesting> graphicsLayer = adoptPtr(new GraphicsLayerFo
rTesting(&client)); | 111 OwnPtr<GraphicsLayerForTesting> graphicsLayer = adoptPtr(new GraphicsLayerFo
rTesting(&client)); |
113 ASSERT_TRUE(graphicsLayer.get()); | 112 ASSERT_TRUE(graphicsLayer.get()); |
114 | 113 |
115 RefPtr<Image> opaqueImage = TestImage::create(IntSize(100, 100), kOpaque_SkA
lphaType); | 114 RefPtr<Image> opaqueImage = TestImage::create(IntSize(100, 100), true /* opa
que */); |
116 ASSERT_TRUE(opaqueImage.get()); | 115 ASSERT_TRUE(opaqueImage.get()); |
117 RefPtr<Image> nonOpaqueImage = TestImage::create(IntSize(100, 100), kPremul_
SkAlphaType); | 116 RefPtr<Image> nonOpaqueImage = TestImage::create(IntSize(100, 100), false /*
opaque */); |
118 ASSERT_TRUE(nonOpaqueImage.get()); | 117 ASSERT_TRUE(nonOpaqueImage.get()); |
119 | 118 |
120 ASSERT_FALSE(graphicsLayer->contentsLayer()); | 119 ASSERT_FALSE(graphicsLayer->contentsLayer()); |
121 | 120 |
122 graphicsLayer->setContentsToImage(opaqueImage.get()); | 121 graphicsLayer->setContentsToImage(opaqueImage.get()); |
123 ASSERT_TRUE(graphicsLayer->contentsLayer()->opaque()); | 122 ASSERT_TRUE(graphicsLayer->contentsLayer()->opaque()); |
124 | 123 |
125 graphicsLayer->setContentsToImage(nonOpaqueImage.get()); | 124 graphicsLayer->setContentsToImage(nonOpaqueImage.get()); |
126 ASSERT_FALSE(graphicsLayer->contentsLayer()->opaque()); | 125 ASSERT_FALSE(graphicsLayer->contentsLayer()->opaque()); |
127 } | 126 } |
128 | 127 |
129 } // namespace | 128 } // namespace |
OLD | NEW |