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
3 // found in the LICENSE file.
7 #if USE(ACCELERATED_COMPOSITING)
9 #include "CCQuadCuller.h"
11 #include "CCAppendQuadsData.h"
12 #include "CCDebugBorderDrawQuad.h"
13 #include "CCLayerImpl.h"
14 #include "CCOcclusionTracker.h"
15 #include "CCOverdrawMetrics.h"
16 #include "CCRenderPass.h"
19 #include <public/WebTransformationMatrix.h>
25 static const int debugTileBorderWidth
= 1;
26 static const int debugTileBorderAlpha
= 120;
27 static const int debugTileBorderColorRed
= 160;
28 static const int debugTileBorderColorGreen
= 100;
29 static const int debugTileBorderColorBlue
= 0;
31 CCQuadCuller::CCQuadCuller(CCQuadList
& quadList
, CCSharedQuadStateList
& sharedQuadStateList
, CCLayerImpl
* layer
, const CCOcclusionTrackerImpl
* occlusionTracker
, bool showCullingWithDebugBorderQuads
, bool forSurface
)
32 : m_quadList(quadList
)
33 , m_sharedQuadStateList(sharedQuadStateList
)
34 , m_currentSharedQuadState(0)
36 , m_occlusionTracker(occlusionTracker
)
37 , m_showCullingWithDebugBorderQuads(showCullingWithDebugBorderQuads
)
38 , m_forSurface(forSurface
)
42 CCSharedQuadState
* CCQuadCuller::useSharedQuadState(PassOwnPtr
<CCSharedQuadState
> passSharedQuadState
)
44 OwnPtr
<CCSharedQuadState
> sharedQuadState(passSharedQuadState
);
45 sharedQuadState
->id
= m_sharedQuadStateList
.size();
47 // FIXME: If all quads are culled for the sharedQuadState, we can drop it from the list.
48 m_currentSharedQuadState
= sharedQuadState
.get();
49 m_sharedQuadStateList
.append(sharedQuadState
.release());
50 return m_currentSharedQuadState
;
53 static inline bool appendQuadInternal(PassOwnPtr
<CCDrawQuad
> passDrawQuad
, const IntRect
& culledRect
, CCQuadList
& quadList
, const CCOcclusionTrackerImpl
& occlusionTracker
, bool createDebugBorderQuads
)
55 OwnPtr
<CCDrawQuad
> drawQuad(passDrawQuad
);
56 bool keepQuad
= !culledRect
.isEmpty();
58 drawQuad
->setQuadVisibleRect(culledRect
);
60 occlusionTracker
.overdrawMetrics().didCullForDrawing(drawQuad
->quadTransform(), drawQuad
->quadRect(), culledRect
);
61 occlusionTracker
.overdrawMetrics().didDraw(drawQuad
->quadTransform(), culledRect
, drawQuad
->opaqueRect());
64 if (createDebugBorderQuads
&& !drawQuad
->isDebugQuad() && drawQuad
->quadVisibleRect() != drawQuad
->quadRect()) {
65 SkColor borderColor
= SkColorSetARGB(debugTileBorderAlpha
, debugTileBorderColorRed
, debugTileBorderColorGreen
, debugTileBorderColorBlue
);
66 quadList
.append(CCDebugBorderDrawQuad::create(drawQuad
->sharedQuadState(), drawQuad
->quadVisibleRect(), borderColor
, debugTileBorderWidth
));
69 // Release the quad after we're done using it.
70 quadList
.append(drawQuad
.release());
75 bool CCQuadCuller::append(PassOwnPtr
<CCDrawQuad
> passDrawQuad
, CCAppendQuadsData
& appendQuadsData
)
77 ASSERT(passDrawQuad
->sharedQuadState() == m_currentSharedQuadState
);
78 ASSERT(passDrawQuad
->sharedQuadStateId() == m_currentSharedQuadState
->id
);
79 ASSERT(!m_sharedQuadStateList
.isEmpty());
80 ASSERT(m_sharedQuadStateList
.last().get() == m_currentSharedQuadState
);
83 bool hasOcclusionFromOutsideTargetSurface
;
86 culledRect
= m_occlusionTracker
->unoccludedContributingSurfaceContentRect(m_layer
, false, passDrawQuad
->quadRect(), &hasOcclusionFromOutsideTargetSurface
);
88 culledRect
= m_occlusionTracker
->unoccludedContentRect(m_layer
, passDrawQuad
->quadRect(), &hasOcclusionFromOutsideTargetSurface
);
90 appendQuadsData
.hadOcclusionFromOutsideTargetSurface
|= hasOcclusionFromOutsideTargetSurface
;
92 return appendQuadInternal(passDrawQuad
, culledRect
, m_quadList
, *m_occlusionTracker
, m_showCullingWithDebugBorderQuads
);
96 #endif // USE(ACCELERATED_COMPOSITING)