OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "CCRendererSoftware.h" | 7 #include "CCRendererSoftware.h" |
8 | 8 |
9 #include "CCQuadSink.h" | 9 #include "CCQuadSink.h" |
10 #include "CCRenderPass.h" | 10 #include "CCRenderPass.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "cc/test/test_common.h" | 21 #include "cc/test/test_common.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 using namespace cc; | 25 using namespace cc; |
26 using namespace WebKit; | 26 using namespace WebKit; |
27 using namespace WebKitTests; | 27 using namespace WebKitTests; |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 class CCRendererSoftwareTest : public testing::Test, public CCRendererClient { | 31 class SoftwareRendererTest : public testing::Test, public RendererClient { |
32 public: | 32 public: |
33 void initializeRenderer() { | 33 void initializeRenderer() { |
34 m_outputSurface = FakeWebCompositorOutputSurface::createSoftware(scoped_
ptr<WebKit::WebCompositorSoftwareOutputDevice>(new FakeWebCompositorSoftwareOutp
utDevice)); | 34 m_outputSurface = FakeWebCompositorOutputSurface::createSoftware(scoped_
ptr<WebKit::WebCompositorSoftwareOutputDevice>(new FakeWebCompositorSoftwareOutp
utDevice)); |
35 m_resourceProvider = CCResourceProvider::create(m_outputSurface.get()); | 35 m_resourceProvider = ResourceProvider::create(m_outputSurface.get()); |
36 m_renderer = CCRendererSoftware::create(this, resourceProvider(), softwa
reDevice()); | 36 m_renderer = SoftwareRenderer::create(this, resourceProvider(), software
Device()); |
37 } | 37 } |
38 | 38 |
39 WebCompositorSoftwareOutputDevice* softwareDevice() const { return m_outputS
urface->softwareDevice(); } | 39 WebCompositorSoftwareOutputDevice* softwareDevice() const { return m_outputS
urface->softwareDevice(); } |
40 FakeWebCompositorOutputSurface* outputSurface() const { return m_outputSurfa
ce.get(); } | 40 FakeWebCompositorOutputSurface* outputSurface() const { return m_outputSurfa
ce.get(); } |
41 CCResourceProvider* resourceProvider() const { return m_resourceProvider.get
(); } | 41 ResourceProvider* resourceProvider() const { return m_resourceProvider.get()
; } |
42 CCRendererSoftware* renderer() const { return m_renderer.get(); } | 42 SoftwareRenderer* renderer() const { return m_renderer.get(); } |
43 void setViewportSize(IntSize viewportSize) { m_viewportSize = viewportSize;
} | 43 void setViewportSize(IntSize viewportSize) { m_viewportSize = viewportSize;
} |
44 | 44 |
45 // CCRendererClient implementation. | 45 // RendererClient implementation. |
46 virtual const IntSize& deviceViewportSize() const OVERRIDE { return m_viewpo
rtSize; } | 46 virtual const IntSize& deviceViewportSize() const OVERRIDE { return m_viewpo
rtSize; } |
47 virtual const CCLayerTreeSettings& settings() const OVERRIDE { return m_sett
ings; } | 47 virtual const LayerTreeSettings& settings() const OVERRIDE { return m_settin
gs; } |
48 virtual void didLoseContext() OVERRIDE { } | 48 virtual void didLoseContext() OVERRIDE { } |
49 virtual void onSwapBuffersComplete() OVERRIDE { } | 49 virtual void onSwapBuffersComplete() OVERRIDE { } |
50 virtual void setFullRootLayerDamage() OVERRIDE { } | 50 virtual void setFullRootLayerDamage() OVERRIDE { } |
51 virtual void setMemoryAllocationLimitBytes(size_t) OVERRIDE { } | 51 virtual void setMemoryAllocationLimitBytes(size_t) OVERRIDE { } |
52 | 52 |
53 protected: | 53 protected: |
54 DebugScopedSetImplThread m_alwaysImplThread; | 54 DebugScopedSetImplThread m_alwaysImplThread; |
55 | 55 |
56 scoped_ptr<FakeWebCompositorOutputSurface> m_outputSurface; | 56 scoped_ptr<FakeWebCompositorOutputSurface> m_outputSurface; |
57 scoped_ptr<CCResourceProvider> m_resourceProvider; | 57 scoped_ptr<ResourceProvider> m_resourceProvider; |
58 scoped_ptr<CCRendererSoftware> m_renderer; | 58 scoped_ptr<SoftwareRenderer> m_renderer; |
59 IntSize m_viewportSize; | 59 IntSize m_viewportSize; |
60 CCLayerTreeSettings m_settings; | 60 LayerTreeSettings m_settings; |
61 }; | 61 }; |
62 | 62 |
63 TEST_F(CCRendererSoftwareTest, solidColorQuad) | 63 TEST_F(SoftwareRendererTest, solidColorQuad) |
64 { | 64 { |
65 IntSize outerSize(100, 100); | 65 IntSize outerSize(100, 100); |
66 int outerPixels = outerSize.width() * outerSize.height(); | 66 int outerPixels = outerSize.width() * outerSize.height(); |
67 IntSize innerSize(98, 98); | 67 IntSize innerSize(98, 98); |
68 IntRect outerRect(IntPoint(), outerSize); | 68 IntRect outerRect(IntPoint(), outerSize); |
69 IntRect innerRect(IntPoint(1, 1), innerSize); | 69 IntRect innerRect(IntPoint(1, 1), innerSize); |
70 setViewportSize(outerSize); | 70 setViewportSize(outerSize); |
71 | 71 |
72 initializeRenderer(); | 72 initializeRenderer(); |
73 | 73 |
74 scoped_ptr<CCSharedQuadState> sharedQuadState = CCSharedQuadState::create(We
bTransformationMatrix(), outerRect, outerRect, 1.0, true); | 74 scoped_ptr<SharedQuadState> sharedQuadState = SharedQuadState::create(WebTra
nsformationMatrix(), outerRect, outerRect, 1.0, true); |
75 CCRenderPass::Id rootRenderPassId = CCRenderPass::Id(1, 1); | 75 RenderPass::Id rootRenderPassId = RenderPass::Id(1, 1); |
76 scoped_ptr<CCRenderPass> rootRenderPass = CCTestRenderPass::create(rootRende
rPassId, outerRect, WebTransformationMatrix()); | 76 scoped_ptr<RenderPass> rootRenderPass = TestRenderPass::create(rootRenderPas
sId, outerRect, WebTransformationMatrix()); |
77 CCTestRenderPass* testRenderPass = static_cast<CCTestRenderPass*>(rootRender
Pass.get()); | 77 TestRenderPass* testRenderPass = static_cast<TestRenderPass*>(rootRenderPass
.get()); |
78 scoped_ptr<CCDrawQuad> outerQuad = CCSolidColorDrawQuad::create(sharedQuadSt
ate.get(), outerRect, SK_ColorYELLOW).PassAs<CCDrawQuad>(); | 78 scoped_ptr<DrawQuad> outerQuad = SolidColorDrawQuad::create(sharedQuadState.
get(), outerRect, SK_ColorYELLOW).PassAs<DrawQuad>(); |
79 scoped_ptr<CCDrawQuad> innerQuad = CCSolidColorDrawQuad::create(sharedQuadSt
ate.get(), innerRect, SK_ColorCYAN).PassAs<CCDrawQuad>(); | 79 scoped_ptr<DrawQuad> innerQuad = SolidColorDrawQuad::create(sharedQuadState.
get(), innerRect, SK_ColorCYAN).PassAs<DrawQuad>(); |
80 testRenderPass->appendQuad(innerQuad.Pass()); | 80 testRenderPass->appendQuad(innerQuad.Pass()); |
81 testRenderPass->appendQuad(outerQuad.Pass()); | 81 testRenderPass->appendQuad(outerQuad.Pass()); |
82 | 82 |
83 CCRenderPassList list; | 83 RenderPassList list; |
84 CCRenderPassIdHashMap hashmap; | 84 RenderPassIdHashMap hashmap; |
85 list.push_back(rootRenderPass.get()); | 85 list.push_back(rootRenderPass.get()); |
86 hashmap.add(rootRenderPassId, rootRenderPass.Pass()); | 86 hashmap.add(rootRenderPassId, rootRenderPass.Pass()); |
87 renderer()->drawFrame(list, hashmap); | 87 renderer()->drawFrame(list, hashmap); |
88 | 88 |
89 scoped_array<SkColor> pixels(new SkColor[deviceViewportSize().width() * devi
ceViewportSize().height()]); | 89 scoped_array<SkColor> pixels(new SkColor[deviceViewportSize().width() * devi
ceViewportSize().height()]); |
90 renderer()->getFramebufferPixels(pixels.get(), outerRect); | 90 renderer()->getFramebufferPixels(pixels.get(), outerRect); |
91 | 91 |
92 // FIXME: This fails on Android. Endianness maybe? | 92 // FIXME: This fails on Android. Endianness maybe? |
93 // Yellow: expects 0xFFFFFF00, was 0xFF00FFFF on android. | 93 // Yellow: expects 0xFFFFFF00, was 0xFF00FFFF on android. |
94 // Cyan: expects 0xFF00FFFF, was 0xFFFFFF00 on android. | 94 // Cyan: expects 0xFF00FFFF, was 0xFFFFFF00 on android. |
95 // http://crbug.com/154528 | 95 // http://crbug.com/154528 |
96 #ifndef OS_ANDROID | 96 #ifndef OS_ANDROID |
97 EXPECT_EQ(SK_ColorYELLOW, pixels[0]); | 97 EXPECT_EQ(SK_ColorYELLOW, pixels[0]); |
98 EXPECT_EQ(SK_ColorYELLOW, pixels[outerPixels - 1]); | 98 EXPECT_EQ(SK_ColorYELLOW, pixels[outerPixels - 1]); |
99 EXPECT_EQ(SK_ColorCYAN, pixels[outerSize.width() + 1]); | 99 EXPECT_EQ(SK_ColorCYAN, pixels[outerSize.width() + 1]); |
100 EXPECT_EQ(SK_ColorCYAN, pixels[outerPixels - outerSize.width() - 2]); | 100 EXPECT_EQ(SK_ColorCYAN, pixels[outerPixels - outerSize.width() - 2]); |
101 #endif | 101 #endif |
102 } | 102 } |
103 | 103 |
104 TEST_F(CCRendererSoftwareTest, tileQuad) | 104 TEST_F(SoftwareRendererTest, tileQuad) |
105 { | 105 { |
106 IntSize outerSize(100, 100); | 106 IntSize outerSize(100, 100); |
107 int outerPixels = outerSize.width() * outerSize.height(); | 107 int outerPixels = outerSize.width() * outerSize.height(); |
108 IntSize innerSize(98, 98); | 108 IntSize innerSize(98, 98); |
109 int innerPixels = innerSize.width() * innerSize.height(); | 109 int innerPixels = innerSize.width() * innerSize.height(); |
110 IntRect outerRect(IntPoint(), outerSize); | 110 IntRect outerRect(IntPoint(), outerSize); |
111 IntRect innerRect(IntPoint(1, 1), innerSize); | 111 IntRect innerRect(IntPoint(1, 1), innerSize); |
112 setViewportSize(outerSize); | 112 setViewportSize(outerSize); |
113 initializeRenderer(); | 113 initializeRenderer(); |
114 | 114 |
115 CCResourceProvider::ResourceId resourceYellow = resourceProvider()->createRe
source(1, outerSize, GraphicsContext3D::RGBA, CCResourceProvider::TextureUsageAn
y); | 115 ResourceProvider::ResourceId resourceYellow = resourceProvider()->createReso
urce(1, outerSize, GraphicsContext3D::RGBA, ResourceProvider::TextureUsageAny); |
116 CCResourceProvider::ResourceId resourceCyan = resourceProvider()->createReso
urce(1, innerSize, GraphicsContext3D::RGBA, CCResourceProvider::TextureUsageAny)
; | 116 ResourceProvider::ResourceId resourceCyan = resourceProvider()->createResour
ce(1, innerSize, GraphicsContext3D::RGBA, ResourceProvider::TextureUsageAny); |
117 | 117 |
118 SkColor yellow = SK_ColorYELLOW; | 118 SkColor yellow = SK_ColorYELLOW; |
119 SkColor cyan = SK_ColorCYAN; | 119 SkColor cyan = SK_ColorCYAN; |
120 scoped_array<SkColor> yellowPixels(new SkColor[outerPixels]); | 120 scoped_array<SkColor> yellowPixels(new SkColor[outerPixels]); |
121 scoped_array<SkColor> cyanPixels(new SkColor[innerPixels]); | 121 scoped_array<SkColor> cyanPixels(new SkColor[innerPixels]); |
122 for (int i = 0; i < outerPixels; i++) | 122 for (int i = 0; i < outerPixels; i++) |
123 yellowPixels[i] = yellow; | 123 yellowPixels[i] = yellow; |
124 for (int i = 0; i < innerPixels; i++) | 124 for (int i = 0; i < innerPixels; i++) |
125 cyanPixels[i] = cyan; | 125 cyanPixels[i] = cyan; |
126 | 126 |
127 resourceProvider()->upload(resourceYellow, reinterpret_cast<uint8_t*>(yellow
Pixels.get()), IntRect(IntPoint(), outerSize), IntRect(IntPoint(), outerSize), I
ntSize()); | 127 resourceProvider()->upload(resourceYellow, reinterpret_cast<uint8_t*>(yellow
Pixels.get()), IntRect(IntPoint(), outerSize), IntRect(IntPoint(), outerSize), I
ntSize()); |
128 resourceProvider()->upload(resourceCyan, reinterpret_cast<uint8_t*>(cyanPixe
ls.get()), IntRect(IntPoint(), innerSize), IntRect(IntPoint(), innerSize), IntSi
ze()); | 128 resourceProvider()->upload(resourceCyan, reinterpret_cast<uint8_t*>(cyanPixe
ls.get()), IntRect(IntPoint(), innerSize), IntRect(IntPoint(), innerSize), IntSi
ze()); |
129 | 129 |
130 IntRect rect = IntRect(IntPoint(), deviceViewportSize()); | 130 IntRect rect = IntRect(IntPoint(), deviceViewportSize()); |
131 | 131 |
132 scoped_ptr<CCSharedQuadState> sharedQuadState = CCSharedQuadState::create(We
bTransformationMatrix(), outerRect, outerRect, 1.0, true); | 132 scoped_ptr<SharedQuadState> sharedQuadState = SharedQuadState::create(WebTra
nsformationMatrix(), outerRect, outerRect, 1.0, true); |
133 CCRenderPass::Id rootRenderPassId = CCRenderPass::Id(1, 1); | 133 RenderPass::Id rootRenderPassId = RenderPass::Id(1, 1); |
134 scoped_ptr<CCRenderPass> rootRenderPass = CCTestRenderPass::create(rootRende
rPassId, IntRect(IntPoint(), deviceViewportSize()), WebTransformationMatrix()); | 134 scoped_ptr<RenderPass> rootRenderPass = TestRenderPass::create(rootRenderPas
sId, IntRect(IntPoint(), deviceViewportSize()), WebTransformationMatrix()); |
135 CCTestRenderPass* testRenderPass = static_cast<CCTestRenderPass*>(rootRender
Pass.get()); | 135 TestRenderPass* testRenderPass = static_cast<TestRenderPass*>(rootRenderPass
.get()); |
136 scoped_ptr<CCDrawQuad> outerQuad = CCTileDrawQuad::create(sharedQuadState.ge
t(), outerRect, outerRect, resourceYellow, IntPoint(), outerSize, 0, false, fals
e, false, false, false).PassAs<CCDrawQuad>(); | 136 scoped_ptr<DrawQuad> outerQuad = TileDrawQuad::create(sharedQuadState.get(),
outerRect, outerRect, resourceYellow, IntPoint(), outerSize, 0, false, false, f
alse, false, false).PassAs<DrawQuad>(); |
137 scoped_ptr<CCDrawQuad> innerQuad = CCTileDrawQuad::create(sharedQuadState.ge
t(), innerRect, innerRect, resourceCyan, IntPoint(), innerSize, 0, false, false,
false, false, false).PassAs<CCDrawQuad>(); | 137 scoped_ptr<DrawQuad> innerQuad = TileDrawQuad::create(sharedQuadState.get(),
innerRect, innerRect, resourceCyan, IntPoint(), innerSize, 0, false, false, fal
se, false, false).PassAs<DrawQuad>(); |
138 testRenderPass->appendQuad(innerQuad.Pass()); | 138 testRenderPass->appendQuad(innerQuad.Pass()); |
139 testRenderPass->appendQuad(outerQuad.Pass()); | 139 testRenderPass->appendQuad(outerQuad.Pass()); |
140 | 140 |
141 CCRenderPassList list; | 141 RenderPassList list; |
142 CCRenderPassIdHashMap hashmap; | 142 RenderPassIdHashMap hashmap; |
143 list.push_back(rootRenderPass.get()); | 143 list.push_back(rootRenderPass.get()); |
144 hashmap.add(rootRenderPassId, rootRenderPass.Pass()); | 144 hashmap.add(rootRenderPassId, rootRenderPass.Pass()); |
145 renderer()->drawFrame(list, hashmap); | 145 renderer()->drawFrame(list, hashmap); |
146 | 146 |
147 scoped_array<SkColor> pixels(new SkColor[deviceViewportSize().width() * devi
ceViewportSize().height()]); | 147 scoped_array<SkColor> pixels(new SkColor[deviceViewportSize().width() * devi
ceViewportSize().height()]); |
148 renderer()->getFramebufferPixels(pixels.get(), outerRect); | 148 renderer()->getFramebufferPixels(pixels.get(), outerRect); |
149 | 149 |
150 EXPECT_EQ(SK_ColorYELLOW, pixels[0]); | 150 EXPECT_EQ(SK_ColorYELLOW, pixels[0]); |
151 EXPECT_EQ(SK_ColorYELLOW, pixels[outerPixels - 1]); | 151 EXPECT_EQ(SK_ColorYELLOW, pixels[outerPixels - 1]); |
152 EXPECT_EQ(SK_ColorCYAN, pixels[outerSize.width() + 1]); | 152 EXPECT_EQ(SK_ColorCYAN, pixels[outerSize.width() + 1]); |
153 EXPECT_EQ(SK_ColorCYAN, pixels[outerPixels - outerSize.width() - 2]); | 153 EXPECT_EQ(SK_ColorCYAN, pixels[outerPixels - outerSize.width() - 2]); |
154 } | 154 } |
155 | 155 |
156 } // namespace | 156 } // namespace |
OLD | NEW |