Don't consider a Bluetooth adapter present until it has an address.
[chromium-blink-merge.git] / cc / CCRenderSurfaceTest.cpp
blob7fc26bad40b727272342e0a9dd9e58629c6ab33b
1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "config.h"
7 #include "CCRenderSurface.h"
9 #include "CCAppendQuadsData.h"
10 #include "CCLayerImpl.h"
11 #include "CCRenderPassSink.h"
12 #include "CCSharedQuadState.h"
13 #include "CCSingleThreadProxy.h"
14 #include "MockCCQuadCuller.h"
15 #include <gmock/gmock.h>
16 #include <gtest/gtest.h>
17 #include <public/WebTransformationMatrix.h>
19 using namespace WebCore;
20 using WebKit::WebTransformationMatrix;
22 namespace {
24 #define EXECUTE_AND_VERIFY_SURFACE_CHANGED(codeToTest) \
25 renderSurface->resetPropertyChangedFlag(); \
26 codeToTest; \
27 EXPECT_TRUE(renderSurface->surfacePropertyChanged())
29 #define EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(codeToTest) \
30 renderSurface->resetPropertyChangedFlag(); \
31 codeToTest; \
32 EXPECT_FALSE(renderSurface->surfacePropertyChanged())
34 TEST(CCRenderSurfaceTest, verifySurfaceChangesAreTrackedProperly)
37 // This test checks that surfacePropertyChanged() has the correct behavior.
40 // This will fake that we are on the correct thread for testing purposes.
41 DebugScopedSetImplThread setImplThread;
43 OwnPtr<CCLayerImpl> owningLayer = CCLayerImpl::create(1);
44 owningLayer->createRenderSurface();
45 ASSERT_TRUE(owningLayer->renderSurface());
46 CCRenderSurface* renderSurface = owningLayer->renderSurface();
47 IntRect testRect = IntRect(IntPoint(3, 4), IntSize(5, 6));
48 owningLayer->resetAllChangeTrackingForSubtree();
50 // Currently, the contentRect, clipRect, and owningLayer->layerPropertyChanged() are
51 // the only sources of change.
52 EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->setClipRect(testRect));
53 EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->setContentRect(testRect));
55 owningLayer->setOpacity(0.5f);
56 EXPECT_TRUE(renderSurface->surfacePropertyChanged());
57 owningLayer->resetAllChangeTrackingForSubtree();
59 // Setting the surface properties to the same values again should not be considered "change".
60 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setClipRect(testRect));
61 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setContentRect(testRect));
63 OwnPtr<CCLayerImpl> dummyMask = CCLayerImpl::create(1);
64 WebTransformationMatrix dummyMatrix;
65 dummyMatrix.translate(1.0, 2.0);
67 // The rest of the surface properties are either internal and should not cause change,
68 // or they are already accounted for by the owninglayer->layerPropertyChanged().
69 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawOpacity(0.5));
70 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawTransform(dummyMatrix));
71 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setReplicaDrawTransform(dummyMatrix));
72 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->clearLayerList());
75 TEST(CCRenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState)
77 // This will fake that we are on the correct thread for testing purposes.
78 DebugScopedSetImplThread setImplThread;
80 OwnPtr<CCLayerImpl> rootLayer = CCLayerImpl::create(1);
82 OwnPtr<CCLayerImpl> owningLayer = CCLayerImpl::create(2);
83 owningLayer->createRenderSurface();
84 ASSERT_TRUE(owningLayer->renderSurface());
85 owningLayer->setRenderTarget(owningLayer.get());
86 CCRenderSurface* renderSurface = owningLayer->renderSurface();
88 rootLayer->addChild(owningLayer.release());
90 IntRect contentRect = IntRect(IntPoint::zero(), IntSize(50, 50));
91 IntRect clipRect = IntRect(IntPoint(5, 5), IntSize(40, 40));
92 WebTransformationMatrix origin;
94 origin.translate(30, 40);
96 renderSurface->setDrawTransform(origin);
97 renderSurface->setContentRect(contentRect);
98 renderSurface->setClipRect(clipRect);
99 renderSurface->setDrawOpacity(1);
101 CCQuadList quadList;
102 CCSharedQuadStateList sharedStateList;
103 MockCCQuadCuller mockQuadCuller(quadList, sharedStateList);
104 CCAppendQuadsData appendQuadsData;
106 bool forReplica = false;
107 renderSurface->appendQuads(mockQuadCuller, appendQuadsData, forReplica, CCRenderPass::Id(2, 0));
109 ASSERT_EQ(1u, sharedStateList.size());
110 CCSharedQuadState* sharedQuadState = sharedStateList[0].get();
112 EXPECT_EQ(30, sharedQuadState->quadTransform.m41());
113 EXPECT_EQ(40, sharedQuadState->quadTransform.m42());
114 EXPECT_EQ(contentRect, IntRect(sharedQuadState->visibleContentRect));
115 EXPECT_EQ(1, sharedQuadState->opacity);
116 EXPECT_FALSE(sharedQuadState->opaque);
119 class TestCCRenderPassSink : public CCRenderPassSink {
120 public:
121 virtual void appendRenderPass(PassOwnPtr<CCRenderPass> renderPass) OVERRIDE { m_renderPasses.append(renderPass); }
123 const Vector<OwnPtr<CCRenderPass> >& renderPasses() const { return m_renderPasses; }
125 private:
126 Vector<OwnPtr<CCRenderPass> > m_renderPasses;
130 TEST(CCRenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass)
132 // This will fake that we are on the correct thread for testing purposes.
133 DebugScopedSetImplThread setImplThread;
135 OwnPtr<CCLayerImpl> rootLayer = CCLayerImpl::create(1);
137 OwnPtr<CCLayerImpl> owningLayer = CCLayerImpl::create(2);
138 owningLayer->createRenderSurface();
139 ASSERT_TRUE(owningLayer->renderSurface());
140 owningLayer->setRenderTarget(owningLayer.get());
141 CCRenderSurface* renderSurface = owningLayer->renderSurface();
143 rootLayer->addChild(owningLayer.release());
145 IntRect contentRect = IntRect(IntPoint::zero(), IntSize(50, 50));
146 WebTransformationMatrix origin;
147 origin.translate(30, 40);
149 renderSurface->setScreenSpaceTransform(origin);
150 renderSurface->setContentRect(contentRect);
152 TestCCRenderPassSink passSink;
154 renderSurface->appendRenderPasses(passSink);
156 ASSERT_EQ(1u, passSink.renderPasses().size());
157 CCRenderPass* pass = passSink.renderPasses()[0].get();
159 EXPECT_EQ(CCRenderPass::Id(2, 0), pass->id());
160 EXPECT_EQ(contentRect, pass->outputRect());
161 EXPECT_EQ(origin, pass->transformToRootTarget());
164 } // namespace