| 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" | |
| 8 #include "cc/math_util.h" | |
| 9 #include "cc/occlusion_tracker.h" | |
| 10 #include "cc/quad_culler.h" | |
| 11 #include "cc/shared_quad_state.h" | |
| 12 #include "cc/solid_color_draw_quad.h" | |
| 13 #include "third_party/skia/include/core/SkImageFilter.h" | 7 #include "third_party/skia/include/core/SkImageFilter.h" |
| 14 | 8 |
| 15 using WebKit::WebTransformationMatrix; | 9 using WebKit::WebTransformationMatrix; |
| 16 | 10 |
| 17 namespace cc { | 11 namespace cc { |
| 18 | 12 |
| 19 scoped_ptr<RenderPass> RenderPass::create(Id id, gfx::Rect outputRect, const Web
Kit::WebTransformationMatrix& transformToRootTarget) | 13 scoped_ptr<RenderPass> RenderPass::Create() { |
| 20 { | 14 return make_scoped_ptr(new RenderPass); |
| 21 return make_scoped_ptr(new RenderPass(id, outputRect, transformToRootTarget)
); | |
| 22 } | 15 } |
| 23 | 16 |
| 24 RenderPass::RenderPass(Id id, gfx::Rect outputRect, const WebKit::WebTransformat
ionMatrix& transformToRootTarget) | 17 RenderPass::RenderPass() |
| 25 : m_id(id) | 18 : id(Id(-1, -1)), |
| 26 , m_transformToRootTarget(transformToRootTarget) | 19 has_transparent_background(true), |
| 27 , m_outputRect(outputRect) | 20 has_occlusion_from_outside_target_surface(false), |
| 28 , m_hasTransparentBackground(true) | 21 filter(NULL) { |
| 29 , m_hasOcclusionFromOutsideTargetSurface(false) | |
| 30 , m_filter(0) | |
| 31 { | |
| 32 DCHECK(id.layerId > 0); | |
| 33 DCHECK(id.index >= 0); | |
| 34 } | 22 } |
| 35 | 23 |
| 36 RenderPass::~RenderPass() | 24 RenderPass::~RenderPass() { |
| 37 { | 25 SkSafeUnref(filter); |
| 38 SkSafeUnref(m_filter); | |
| 39 } | 26 } |
| 40 | 27 |
| 41 scoped_ptr<RenderPass> RenderPass::copy(Id newId) const | 28 scoped_ptr<RenderPass> RenderPass::Copy(Id new_id) const { |
| 42 { | 29 DCHECK(new_id != id); |
| 43 DCHECK(newId != m_id); | |
| 44 | 30 |
| 45 scoped_ptr<RenderPass> copyPass(create(newId, m_outputRect, m_transformToRoo
tTarget)); | 31 scoped_ptr<RenderPass> copy_pass(Create()); |
| 46 copyPass->setDamageRect(m_damageRect); | 32 copy_pass->SetAll(new_id, |
| 47 copyPass->setHasTransparentBackground(m_hasTransparentBackground); | 33 output_rect, |
| 48 copyPass->setHasOcclusionFromOutsideTargetSurface(m_hasOcclusionFromOutsideT
argetSurface); | 34 damage_rect, |
| 49 copyPass->setFilters(m_filters); | 35 transform_to_root_target, |
| 50 copyPass->setBackgroundFilters(m_backgroundFilters); | 36 has_transparent_background, |
| 51 copyPass->setFilter(m_filter); | 37 has_occlusion_from_outside_target_surface, |
| 52 return copyPass.Pass(); | 38 filters, |
| 39 filter, |
| 40 background_filters); |
| 41 return copy_pass.Pass(); |
| 53 } | 42 } |
| 54 | 43 |
| 55 void RenderPass::appendQuadsForLayer(LayerImpl* layer, OcclusionTrackerImpl* occ
lusionTracker, AppendQuadsData& appendQuadsData) | 44 void RenderPass::SetNew(Id id, |
| 56 { | 45 gfx::Rect output_rect, |
| 57 bool forSurface = false; | 46 gfx::RectF damage_rect, |
| 58 QuadCuller quadCuller(m_quadList, m_sharedQuadStateList, layer, occlusionTra
cker, layer->showDebugBorders(), forSurface); | 47 const WebKit::WebTransformationMatrix& transform_to_root
_target) { |
| 48 DCHECK_GT(id.layer_id, 0); |
| 49 DCHECK_GE(id.index, 0); |
| 59 | 50 |
| 60 layer->appendQuads(quadCuller, appendQuadsData); | 51 this->id = id; |
| 52 this->output_rect = output_rect; |
| 53 this->damage_rect = damage_rect; |
| 54 this->transform_to_root_target = transform_to_root_target; |
| 55 |
| 56 DCHECK(quad_list.isEmpty()); |
| 57 DCHECK(shared_quad_state_list.isEmpty()); |
| 61 } | 58 } |
| 62 | 59 |
| 63 void RenderPass::appendQuadsForRenderSurfaceLayer(LayerImpl* layer, const Render
Pass* contributingRenderPass, OcclusionTrackerImpl* occlusionTracker, AppendQuad
sData& appendQuadsData) | 60 void RenderPass::SetAll(Id id, |
| 64 { | 61 gfx::Rect output_rect, |
| 65 bool forSurface = true; | 62 gfx::RectF damage_rect, |
| 66 QuadCuller quadCuller(m_quadList, m_sharedQuadStateList, layer, occlusionTra
cker, layer->showDebugBorders(), forSurface); | 63 const WebKit::WebTransformationMatrix& transform_to_root
_target, |
| 64 bool has_transparent_background, |
| 65 bool has_occlusion_from_outside_target_surface, |
| 66 const WebKit::WebFilterOperations& filters, |
| 67 SkImageFilter* filter, |
| 68 const WebKit::WebFilterOperations& background_filters) { |
| 69 DCHECK_GT(id.layer_id, 0); |
| 70 DCHECK_GE(id.index, 0); |
| 67 | 71 |
| 68 bool isReplica = false; | 72 this->id = id; |
| 69 layer->renderSurface()->appendQuads(quadCuller, appendQuadsData, isReplica,
contributingRenderPass->id()); | 73 this->output_rect = output_rect; |
| 74 this->damage_rect = damage_rect; |
| 75 this->transform_to_root_target = transform_to_root_target; |
| 76 this->has_transparent_background = has_transparent_background; |
| 77 this->has_occlusion_from_outside_target_surface = |
| 78 has_occlusion_from_outside_target_surface; |
| 79 this->filters = filters; |
| 80 SkRefCnt_SafeAssign(this->filter, filter); |
| 81 this->background_filters = background_filters; |
| 70 | 82 |
| 71 // Add replica after the surface so that it appears below the surface. | 83 DCHECK(quad_list.isEmpty()); |
| 72 if (layer->hasReplica()) { | 84 DCHECK(shared_quad_state_list.isEmpty()); |
| 73 isReplica = true; | |
| 74 layer->renderSurface()->appendQuads(quadCuller, appendQuadsData, isRepli
ca, contributingRenderPass->id()); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 void RenderPass::appendQuadsToFillScreen(LayerImpl* rootLayer, SkColor screenBac
kgroundColor, const OcclusionTrackerImpl& occlusionTracker) | |
| 79 { | |
| 80 if (!rootLayer || !screenBackgroundColor) | |
| 81 return; | |
| 82 | |
| 83 Region fillRegion = occlusionTracker.computeVisibleRegionInScreen(); | |
| 84 if (fillRegion.IsEmpty()) | |
| 85 return; | |
| 86 | |
| 87 bool forSurface = false; | |
| 88 QuadCuller quadCuller(m_quadList, m_sharedQuadStateList, rootLayer, &occlusi
onTracker, rootLayer->showDebugBorders(), forSurface); | |
| 89 | |
| 90 // 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. | |
| 92 // FIXME: Make the gutter quads generated by the solid color layer (make it
smarter about generating quads to fill unoccluded areas). | |
| 93 | |
| 94 DCHECK(rootLayer->screenSpaceTransform().isInvertible()); | |
| 95 | |
| 96 gfx::Rect rootTargetRect = rootLayer->renderSurface()->contentRect(); | |
| 97 float opacity = 1; | |
| 98 SharedQuadState* sharedQuadState = quadCuller.useSharedQuadState(SharedQuadS
tate::Create()); | |
| 99 sharedQuadState->SetAll(rootLayer->drawTransform(), rootTargetRect, rootTarg
etRect, opacity); | |
| 100 | |
| 101 WebTransformationMatrix transformToLayerSpace = rootLayer->screenSpaceTransf
orm().inverse(); | |
| 102 for (Region::Iterator fillRects(fillRegion); fillRects.has_rect(); fillRects
.next()) { | |
| 103 // The root layer transform is composed of translations and scales only,
no perspective, so mapping is sufficient. | |
| 104 gfx::Rect layerRect = MathUtil::mapClippedRect(transformToLayerSpace, fi
llRects.rect()); | |
| 105 // Skip the quad culler and just append the quads directly to avoid occl
usion checks. | |
| 106 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); | |
| 107 quad->SetNew(sharedQuadState, layerRect, screenBackgroundColor); | |
| 108 m_quadList.append(quad.PassAs<DrawQuad>()); | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 void RenderPass::setFilter(SkImageFilter* filter) { | |
| 113 SkRefCnt_SafeAssign(m_filter, filter); | |
| 114 } | 85 } |
| 115 | 86 |
| 116 } // namespace cc | 87 } // namespace cc |
| OLD | NEW |