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.
5 #include "cc/quad_culler.h"
7 #include "cc/append_quads_data.h"
8 #include "cc/debug_border_draw_quad.h"
9 #include "cc/debug_colors.h"
10 #include "cc/layer_impl.h"
11 #include "cc/occlusion_tracker.h"
12 #include "cc/overdraw_metrics.h"
13 #include "cc/render_pass.h"
14 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/gfx/transform.h"
21 QuadCuller::QuadCuller(QuadList
& quadList
, SharedQuadStateList
& sharedQuadStateList
, const LayerImpl
* layer
, const OcclusionTrackerImpl
& occlusionTracker
, bool showCullingWithDebugBorderQuads
, bool forSurface
)
22 : m_quadList(quadList
)
23 , m_sharedQuadStateList(sharedQuadStateList
)
24 , m_currentSharedQuadState(0)
26 , m_occlusionTracker(occlusionTracker
)
27 , m_showCullingWithDebugBorderQuads(showCullingWithDebugBorderQuads
)
28 , m_forSurface(forSurface
)
32 SharedQuadState
* QuadCuller::useSharedQuadState(scoped_ptr
<SharedQuadState
> sharedQuadState
)
34 // FIXME: If all quads are culled for the sharedQuadState, we can drop it from the list.
35 m_currentSharedQuadState
= sharedQuadState
.get();
36 m_sharedQuadStateList
.append(sharedQuadState
.Pass());
37 return m_currentSharedQuadState
;
40 static inline bool appendQuadInternal(scoped_ptr
<DrawQuad
> drawQuad
, const gfx::Rect
& culledRect
, QuadList
& quadList
, const OcclusionTrackerImpl
& occlusionTracker
, const LayerImpl
* layer
, bool createDebugBorderQuads
)
42 bool keepQuad
= !culledRect
.IsEmpty();
44 drawQuad
->visible_rect
= culledRect
;
46 occlusionTracker
.overdrawMetrics().didCullForDrawing(drawQuad
->quadTransform(), drawQuad
->rect
, culledRect
);
47 gfx::Rect opaqueDrawRect
= drawQuad
->opacity() == 1.0f
? drawQuad
->opaque_rect
: gfx::Rect();
48 occlusionTracker
.overdrawMetrics().didDraw(drawQuad
->quadTransform(), culledRect
, opaqueDrawRect
);
51 if (createDebugBorderQuads
&& !drawQuad
->IsDebugQuad() && drawQuad
->visible_rect
!= drawQuad
->rect
) {
52 SkColor color
= DebugColors::CulledTileBorderColor();
53 float width
= DebugColors::CulledTileBorderWidth(layer
? layer
->layerTreeHostImpl() : NULL
);
54 scoped_ptr
<DebugBorderDrawQuad
> debugBorderQuad
= DebugBorderDrawQuad::Create();
55 debugBorderQuad
->SetNew(drawQuad
->shared_quad_state
, drawQuad
->visible_rect
, color
, width
);
56 quadList
.append(debugBorderQuad
.PassAs
<DrawQuad
>());
59 // Pass the quad after we're done using it.
60 quadList
.append(drawQuad
.Pass());
65 bool QuadCuller::append(scoped_ptr
<DrawQuad
> drawQuad
, AppendQuadsData
& appendQuadsData
)
67 DCHECK(drawQuad
->shared_quad_state
== m_currentSharedQuadState
);
68 DCHECK(!m_sharedQuadStateList
.isEmpty());
69 DCHECK(m_sharedQuadStateList
.last() == m_currentSharedQuadState
);
72 bool hasOcclusionFromOutsideTargetSurface
;
73 bool implDrawTransformIsUnknown
= false;
76 culledRect
= m_occlusionTracker
.unoccludedContributingSurfaceContentRect(m_layer
, false, drawQuad
->rect
, &hasOcclusionFromOutsideTargetSurface
);
78 culledRect
= m_occlusionTracker
.unoccludedContentRect(m_layer
->renderTarget(), drawQuad
->rect
, drawQuad
->quadTransform(), implDrawTransformIsUnknown
, drawQuad
->clippedRectInTarget(), &hasOcclusionFromOutsideTargetSurface
);
80 appendQuadsData
.hadOcclusionFromOutsideTargetSurface
|= hasOcclusionFromOutsideTargetSurface
;
82 return appendQuadInternal(drawQuad
.Pass(), culledRect
, m_quadList
, m_occlusionTracker
, m_layer
, m_showCullingWithDebugBorderQuads
);