Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 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 "cc/render_pass.h" | 5 #include "cc/render_pass.h" |
| 6 | 6 |
| 7 #include "cc/layer_impl.h" | 7 #include "cc/layer_impl.h" |
| 8 #include "cc/math_util.h" | 8 #include "cc/math_util.h" |
| 9 #include "cc/occlusion_tracker.h" | 9 #include "cc/occlusion_tracker.h" |
| 10 #include "cc/quad_culler.h" | 10 #include "cc/quad_culler.h" |
| 11 #include "cc/shared_quad_state.h" | 11 #include "cc/shared_quad_state.h" |
| 12 #include "cc/solid_color_draw_quad.h" | 12 #include "cc/solid_color_draw_quad.h" |
| 13 #include "third_party/skia/include/core/SkImageFilter.h" | 13 #include "third_party/skia/include/core/SkImageFilter.h" |
| 14 | 14 |
| 15 using WebKit::WebTransformationMatrix; | 15 using WebKit::WebTransformationMatrix; |
| 16 | 16 |
| 17 namespace cc { | 17 namespace cc { |
| 18 | 18 |
| 19 scoped_ptr<RenderPass> RenderPass::create(Id id, gfx::Rect outputRect, const Web Kit::WebTransformationMatrix& transformToRootTarget) | 19 scoped_ptr<RenderPass> RenderPass::Create() { |
| 20 { | 20 return make_scoped_ptr(new RenderPass); |
| 21 return make_scoped_ptr(new RenderPass(id, outputRect, transformToRootTarget) ); | |
| 22 } | 21 } |
| 23 | 22 |
| 24 RenderPass::RenderPass(Id id, gfx::Rect outputRect, const WebKit::WebTransformat ionMatrix& transformToRootTarget) | 23 RenderPass::RenderPass() |
| 25 : m_id(id) | 24 : id(Id(-1, -1)), |
| 26 , m_transformToRootTarget(transformToRootTarget) | 25 has_transparent_background(true), |
| 27 , m_outputRect(outputRect) | 26 has_occlusion_from_outside_target_surface(false), |
| 28 , m_hasTransparentBackground(true) | 27 filter(NULL) { |
| 29 , m_hasOcclusionFromOutsideTargetSurface(false) | |
| 30 , m_filter(0) | |
| 31 { | |
| 32 DCHECK(id.layerId > 0); | |
| 33 DCHECK(id.index >= 0); | |
| 34 } | 28 } |
| 35 | 29 |
| 36 RenderPass::~RenderPass() | 30 RenderPass::~RenderPass() { |
| 37 { | 31 SkSafeUnref(filter); |
| 38 SkSafeUnref(m_filter); | |
| 39 } | 32 } |
| 40 | 33 |
| 41 scoped_ptr<RenderPass> RenderPass::copy(Id newId) const | 34 scoped_ptr<RenderPass> RenderPass::Copy(Id new_id) const { |
| 42 { | 35 DCHECK(new_id != id); |
| 43 DCHECK(newId != m_id); | |
| 44 | 36 |
| 45 scoped_ptr<RenderPass> copyPass(create(newId, m_outputRect, m_transformToRoo tTarget)); | 37 scoped_ptr<RenderPass> copy_pass(Create()); |
| 46 copyPass->setDamageRect(m_damageRect); | 38 copy_pass->SetAll(new_id, |
| 47 copyPass->setHasTransparentBackground(m_hasTransparentBackground); | 39 output_rect, |
| 48 copyPass->setHasOcclusionFromOutsideTargetSurface(m_hasOcclusionFromOutsideT argetSurface); | 40 damage_rect, |
| 49 copyPass->setFilters(m_filters); | 41 transform_to_root_target, |
| 50 copyPass->setBackgroundFilters(m_backgroundFilters); | 42 has_transparent_background, |
| 51 copyPass->setFilter(m_filter); | 43 has_occlusion_from_outside_target_surface, |
| 52 return copyPass.Pass(); | 44 filters, |
| 45 filter, | |
| 46 background_filters); | |
| 47 return copy_pass.Pass(); | |
| 53 } | 48 } |
| 54 | 49 |
| 55 void RenderPass::appendQuadsForLayer(LayerImpl* layer, OcclusionTrackerImpl* occ lusionTracker, AppendQuadsData& appendQuadsData) | 50 void RenderPass::SetNew(Id id, |
| 56 { | 51 gfx::Rect output_rect, |
| 57 bool forSurface = false; | 52 gfx::RectF damage_rect, |
| 58 QuadCuller quadCuller(m_quadList, m_sharedQuadStateList, layer, occlusionTra cker, layer->showDebugBorders(), forSurface); | 53 const WebKit::WebTransformationMatrix& transform_to_root _target) { |
| 54 DCHECK_GT(id.layer_id, 0); | |
| 55 DCHECK_GE(id.index, 0); | |
| 59 | 56 |
| 60 layer->appendQuads(quadCuller, appendQuadsData); | 57 this->id = id; |
| 58 this->output_rect = output_rect; | |
| 59 this->damage_rect = damage_rect; | |
| 60 this->transform_to_root_target = transform_to_root_target; | |
| 61 | |
| 62 DCHECK(quad_list.isEmpty()); | |
| 63 DCHECK(shared_quad_state_list.isEmpty()); | |
| 61 } | 64 } |
| 62 | 65 |
| 63 void RenderPass::appendQuadsForRenderSurfaceLayer(LayerImpl* layer, const Render Pass* contributingRenderPass, OcclusionTrackerImpl* occlusionTracker, AppendQuad sData& appendQuadsData) | 66 void RenderPass::SetAll(Id id, |
| 64 { | 67 gfx::Rect output_rect, |
| 65 bool forSurface = true; | 68 gfx::RectF damage_rect, |
| 66 QuadCuller quadCuller(m_quadList, m_sharedQuadStateList, layer, occlusionTra cker, layer->showDebugBorders(), forSurface); | 69 const WebKit::WebTransformationMatrix& transform_to_root _target, |
| 70 bool has_transparent_background, | |
| 71 bool has_occlusion_from_outside_target_surface, | |
| 72 const WebKit::WebFilterOperations& filters, | |
| 73 SkImageFilter* filter, | |
| 74 const WebKit::WebFilterOperations& background_filters) { | |
| 75 DCHECK_GT(id.layer_id, 0); | |
| 76 DCHECK_GE(id.index, 0); | |
| 67 | 77 |
| 68 bool isReplica = false; | 78 this->id = id; |
| 69 layer->renderSurface()->appendQuads(quadCuller, appendQuadsData, isReplica, contributingRenderPass->id()); | 79 this->output_rect = output_rect; |
| 80 this->damage_rect = damage_rect; | |
| 81 this->transform_to_root_target = transform_to_root_target; | |
| 82 this->has_transparent_background = has_transparent_background; | |
| 83 this->has_occlusion_from_outside_target_surface = | |
| 84 has_occlusion_from_outside_target_surface; | |
| 85 this->filters = filters; | |
| 86 SkRefCnt_SafeAssign(this->filter, filter); | |
| 87 this->background_filters = background_filters; | |
| 70 | 88 |
| 71 // Add replica after the surface so that it appears below the surface. | 89 DCHECK(quad_list.isEmpty()); |
| 72 if (layer->hasReplica()) { | 90 DCHECK(shared_quad_state_list.isEmpty()); |
| 73 isReplica = true; | |
| 74 layer->renderSurface()->appendQuads(quadCuller, appendQuadsData, isRepli ca, contributingRenderPass->id()); | |
| 75 } | |
| 76 } | 91 } |
| 77 | 92 |
| 78 void RenderPass::appendQuadsToFillScreen(LayerImpl* rootLayer, SkColor screenBac kgroundColor, const OcclusionTrackerImpl& occlusionTracker) | 93 void RenderPass::AppendQuadsForLayer( |
|
aelias_OOO_until_Jul13
2012/11/21 01:50:10
These methods aren't very readable without the "m_
danakj
2012/11/21 01:53:02
Ya that's reasonable, they aren't used by tests.
| |
| 79 { | 94 LayerImpl* layer, |
| 80 if (!rootLayer || !screenBackgroundColor) | 95 OcclusionTrackerImpl& occlusion_tracker, |
| 81 return; | 96 AppendQuadsData& append_quads_data) { |
| 82 | 97 |
| 83 Region fillRegion = occlusionTracker.computeVisibleRegionInScreen(); | 98 bool for_surface = false; |
| 84 if (fillRegion.IsEmpty()) | 99 QuadCuller quad_culler(quad_list, |
| 85 return; | 100 shared_quad_state_list, |
| 101 layer, | |
| 102 occlusion_tracker, | |
| 103 layer->showDebugBorders(), | |
| 104 for_surface); | |
| 86 | 105 |
| 87 bool forSurface = false; | 106 layer->appendQuads(quad_culler, append_quads_data); |
| 88 QuadCuller quadCuller(m_quadList, m_sharedQuadStateList, rootLayer, &occlusi onTracker, rootLayer->showDebugBorders(), forSurface); | 107 } |
| 108 | |
| 109 void RenderPass::AppendQuadsForRenderSurfaceLayer( | |
| 110 LayerImpl* layer, | |
| 111 const RenderPass& contributing_render_pass, | |
| 112 OcclusionTrackerImpl& occlusion_tracker, | |
| 113 AppendQuadsData& append_quads_data) { | |
| 114 | |
| 115 bool for_surface = true; | |
| 116 QuadCuller quad_culler(quad_list, | |
| 117 shared_quad_state_list, | |
| 118 layer, | |
| 119 occlusion_tracker, | |
| 120 layer->showDebugBorders(), | |
| 121 for_surface); | |
| 122 | |
| 123 bool is_replica = false; | |
| 124 layer->renderSurface()->appendQuads(quad_culler, | |
| 125 append_quads_data, | |
| 126 is_replica, | |
| 127 contributing_render_pass.id); | |
| 128 | |
| 129 // Add replica after the surface so that it appears below the surface. | |
| 130 if (layer->hasReplica()) { | |
| 131 is_replica = true; | |
| 132 layer->renderSurface()->appendQuads(quad_culler, | |
| 133 append_quads_data, | |
| 134 is_replica, | |
| 135 contributing_render_pass.id); | |
| 136 } | |
| 137 } | |
| 138 | |
| 139 void RenderPass::AppendQuadsToFillScreen( | |
| 140 LayerImpl* root_layer, | |
| 141 SkColor screen_background_color, | |
| 142 const OcclusionTrackerImpl& occlusion_tracker) { | |
| 143 | |
| 144 if (!root_layer || !SkColorGetA(screen_background_color)) | |
| 145 return; | |
| 146 | |
| 147 Region fill_region = occlusion_tracker.computeVisibleRegionInScreen(); | |
| 148 if (fill_region.IsEmpty()) | |
| 149 return; | |
| 150 | |
| 151 bool for_surface = false; | |
| 152 QuadCuller quad_culler(quad_list, | |
| 153 shared_quad_state_list, | |
| 154 root_layer, | |
| 155 occlusion_tracker, | |
| 156 root_layer->showDebugBorders(), | |
| 157 for_surface); | |
| 89 | 158 |
| 90 // Manually create the quad state for the gutter quads, as the root layer | 159 // Manually create the quad state for the gutter quads, as the root layer |
| 91 // doesn't have any bounds and so can't generate this itself. | 160 // doesn't have any bounds and so can't generate this itself. |
| 92 // FIXME: Make the gutter quads generated by the solid color layer (make it smarter about generating quads to fill unoccluded areas). | 161 // FIXME: Make the gutter quads generated by the solid color layer (make it smarter about generating quads to fill unoccluded areas). |
| 93 | 162 |
| 94 DCHECK(rootLayer->screenSpaceTransform().isInvertible()); | 163 DCHECK(root_layer->screenSpaceTransform().isInvertible()); |
| 95 | 164 |
| 96 gfx::Rect rootTargetRect = rootLayer->renderSurface()->contentRect(); | 165 gfx::Rect root_target_rect = root_layer->renderSurface()->contentRect(); |
| 97 float opacity = 1; | 166 float opacity = 1; |
| 98 SharedQuadState* sharedQuadState = quadCuller.useSharedQuadState(SharedQuadS tate::Create()); | 167 SharedQuadState* shared_quad_state = quad_culler.useSharedQuadState( |
| 99 sharedQuadState->SetAll(rootLayer->drawTransform(), rootTargetRect, rootTarg etRect, opacity); | 168 SharedQuadState::Create()); |
| 169 shared_quad_state->SetAll(root_layer->drawTransform(), | |
| 170 root_target_rect, | |
| 171 root_target_rect, | |
| 172 opacity); | |
| 100 | 173 |
| 101 WebTransformationMatrix transformToLayerSpace = rootLayer->screenSpaceTransf orm().inverse(); | 174 WebTransformationMatrix transform_to_layer_space = |
| 102 for (Region::Iterator fillRects(fillRegion); fillRects.has_rect(); fillRects .next()) { | 175 root_layer->screenSpaceTransform().inverse(); |
| 103 // The root layer transform is composed of translations and scales only, no perspective, so mapping is sufficient. | 176 Region::Iterator fill_rects(fill_region); |
|
aelias_OOO_until_Jul13
2012/11/21 01:50:10
nit: why not keep this inside the for()?
danakj
2012/11/21 01:53:02
80 columns nonsense, and splitting the for over 3
| |
| 104 gfx::Rect layerRect = MathUtil::mapClippedRect(transformToLayerSpace, fi llRects.rect()); | 177 for (; fill_rects.has_rect(); fill_rects.next()) { |
| 105 // Skip the quad culler and just append the quads directly to avoid occl usion checks. | 178 // The root layer transform is composed of translations and scales only, |
| 106 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); | 179 // no perspective, so mapping is sufficient. |
| 107 quad->SetNew(sharedQuadState, layerRect, screenBackgroundColor); | 180 gfx::Rect layer_rect = MathUtil::mapClippedRect( |
| 108 m_quadList.append(quad.PassAs<DrawQuad>()); | 181 transform_to_layer_space, fill_rects.rect()); |
| 182 // Skip the quad culler and just append the quads directly to avoid | |
| 183 // occlusion checks. | |
| 184 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); | |
| 185 quad->SetNew(shared_quad_state, layer_rect, screen_background_color); | |
| 186 quad_list.append(quad.PassAs<DrawQuad>()); | |
| 109 } | 187 } |
| 110 } | 188 } |
| 111 | 189 |
| 112 void RenderPass::setFilter(SkImageFilter* filter) { | |
| 113 SkRefCnt_SafeAssign(m_filter, filter); | |
| 114 } | |
| 115 | |
| 116 } // namespace cc | 190 } // namespace cc |
| OLD | NEW |