| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/render_surface_impl.h" | 7 #include "cc/render_surface_impl.h" |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "cc/damage_tracker.h" | 11 #include "cc/damage_tracker.h" |
| 12 #include "cc/debug_border_draw_quad.h" | 12 #include "cc/debug_border_draw_quad.h" |
| 13 #include "cc/delegated_renderer_layer_impl.h" | 13 #include "cc/delegated_renderer_layer_impl.h" |
| 14 #include "cc/layer_impl.h" | 14 #include "cc/layer_impl.h" |
| 15 #include "cc/math_util.h" | 15 #include "cc/math_util.h" |
| 16 #include "cc/quad_sink.h" | 16 #include "cc/quad_sink.h" |
| 17 #include "cc/render_pass.h" | 17 #include "cc/render_pass.h" |
| 18 #include "cc/render_pass_draw_quad.h" | 18 #include "cc/render_pass_draw_quad.h" |
| 19 #include "cc/render_pass_sink.h" | 19 #include "cc/render_pass_sink.h" |
| 20 #include "cc/shared_quad_state.h" | 20 #include "cc/shared_quad_state.h" |
| 21 #include "ui/gfx/rect_conversions.h" |
| 21 #include <public/WebTransformationMatrix.h> | 22 #include <public/WebTransformationMatrix.h> |
| 22 | 23 |
| 23 using WebKit::WebTransformationMatrix; | 24 using WebKit::WebTransformationMatrix; |
| 24 | 25 |
| 25 namespace cc { | 26 namespace cc { |
| 26 | 27 |
| 27 static const int debugSurfaceBorderWidth = 2; | 28 static const int debugSurfaceBorderWidth = 2; |
| 28 static const int debugSurfaceBorderAlpha = 100; | 29 static const int debugSurfaceBorderAlpha = 100; |
| 29 static const int debugSurfaceBorderColorRed = 0; | 30 static const int debugSurfaceBorderColorRed = 0; |
| 30 static const int debugSurfaceBorderColorGreen = 0; | 31 static const int debugSurfaceBorderColorGreen = 0; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 44 , m_targetRenderSurfaceLayerIndexHistory(0) | 45 , m_targetRenderSurfaceLayerIndexHistory(0) |
| 45 , m_currentLayerIndexHistory(0) | 46 , m_currentLayerIndexHistory(0) |
| 46 { | 47 { |
| 47 m_damageTracker = DamageTracker::create(); | 48 m_damageTracker = DamageTracker::create(); |
| 48 } | 49 } |
| 49 | 50 |
| 50 RenderSurfaceImpl::~RenderSurfaceImpl() | 51 RenderSurfaceImpl::~RenderSurfaceImpl() |
| 51 { | 52 { |
| 52 } | 53 } |
| 53 | 54 |
| 54 FloatRect RenderSurfaceImpl::drawableContentRect() const | 55 gfx::RectF RenderSurfaceImpl::drawableContentRect() const |
| 55 { | 56 { |
| 56 FloatRect drawableContentRect = MathUtil::mapClippedRect(m_drawTransform, m_
contentRect); | 57 gfx::RectF drawableContentRect = MathUtil::mapClippedRect(m_drawTransform, m
_contentRect); |
| 57 if (m_owningLayer->hasReplica()) | 58 if (m_owningLayer->hasReplica()) |
| 58 drawableContentRect.unite(MathUtil::mapClippedRect(m_replicaDrawTransfor
m, m_contentRect)); | 59 drawableContentRect.Union(MathUtil::mapClippedRect(m_replicaDrawTransfor
m, m_contentRect)); |
| 59 | 60 |
| 60 return drawableContentRect; | 61 return drawableContentRect; |
| 61 } | 62 } |
| 62 | 63 |
| 63 std::string RenderSurfaceImpl::name() const | 64 std::string RenderSurfaceImpl::name() const |
| 64 { | 65 { |
| 65 return base::StringPrintf("RenderSurfaceImpl(id=%i,owner=%s)", m_owningLayer
->id(), m_owningLayer->debugName().data()); | 66 return base::StringPrintf("RenderSurfaceImpl(id=%i,owner=%s)", m_owningLayer
->id(), m_owningLayer->debugName().data()); |
| 66 } | 67 } |
| 67 | 68 |
| 68 static std::string indentString(int indent) | 69 static std::string indentString(int indent) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 95 m_damageTracker->currentDamageRect().x(), m_damageTracker->currentDamage
Rect().y(), | 96 m_damageTracker->currentDamageRect().x(), m_damageTracker->currentDamage
Rect().y(), |
| 96 m_damageTracker->currentDamageRect().width(), m_damageTracker->currentDa
mageRect().height()); | 97 m_damageTracker->currentDamageRect().width(), m_damageTracker->currentDa
mageRect().height()); |
| 97 } | 98 } |
| 98 | 99 |
| 99 int RenderSurfaceImpl::owningLayerId() const | 100 int RenderSurfaceImpl::owningLayerId() const |
| 100 { | 101 { |
| 101 return m_owningLayer ? m_owningLayer->id() : 0; | 102 return m_owningLayer ? m_owningLayer->id() : 0; |
| 102 } | 103 } |
| 103 | 104 |
| 104 | 105 |
| 105 void RenderSurfaceImpl::setClipRect(const IntRect& clipRect) | 106 void RenderSurfaceImpl::setClipRect(const gfx::Rect& clipRect) |
| 106 { | 107 { |
| 107 if (m_clipRect == clipRect) | 108 if (m_clipRect == clipRect) |
| 108 return; | 109 return; |
| 109 | 110 |
| 110 m_surfacePropertyChanged = true; | 111 m_surfacePropertyChanged = true; |
| 111 m_clipRect = clipRect; | 112 m_clipRect = clipRect; |
| 112 } | 113 } |
| 113 | 114 |
| 114 bool RenderSurfaceImpl::contentsChanged() const | 115 bool RenderSurfaceImpl::contentsChanged() const |
| 115 { | 116 { |
| 116 return !m_damageTracker->currentDamageRect().isEmpty(); | 117 return !m_damageTracker->currentDamageRect().IsEmpty(); |
| 117 } | 118 } |
| 118 | 119 |
| 119 void RenderSurfaceImpl::setContentRect(const IntRect& contentRect) | 120 void RenderSurfaceImpl::setContentRect(const gfx::Rect& contentRect) |
| 120 { | 121 { |
| 121 if (m_contentRect == contentRect) | 122 if (m_contentRect == contentRect) |
| 122 return; | 123 return; |
| 123 | 124 |
| 124 m_surfacePropertyChanged = true; | 125 m_surfacePropertyChanged = true; |
| 125 m_contentRect = contentRect; | 126 m_contentRect = contentRect; |
| 126 } | 127 } |
| 127 | 128 |
| 128 bool RenderSurfaceImpl::surfacePropertyChanged() const | 129 bool RenderSurfaceImpl::surfacePropertyChanged() const |
| 129 { | 130 { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 150 DelegatedRendererLayerImpl* delegatedRendererLayer = static_cast<DelegatedRe
ndererLayerImpl*>(layer); | 151 DelegatedRendererLayerImpl* delegatedRendererLayer = static_cast<DelegatedRe
ndererLayerImpl*>(layer); |
| 151 m_contributingDelegatedRenderPassLayerList.push_back(delegatedRendererLayer)
; | 152 m_contributingDelegatedRenderPassLayerList.push_back(delegatedRendererLayer)
; |
| 152 } | 153 } |
| 153 | 154 |
| 154 void RenderSurfaceImpl::clearLayerLists() | 155 void RenderSurfaceImpl::clearLayerLists() |
| 155 { | 156 { |
| 156 m_layerList.clear(); | 157 m_layerList.clear(); |
| 157 m_contributingDelegatedRenderPassLayerList.clear(); | 158 m_contributingDelegatedRenderPassLayerList.clear(); |
| 158 } | 159 } |
| 159 | 160 |
| 160 static inline IntRect computeClippedRectInTarget(const LayerImpl* owningLayer) | 161 static inline gfx::Rect computeClippedRectInTarget(const LayerImpl* owningLayer) |
| 161 { | 162 { |
| 162 DCHECK(owningLayer->parent()); | 163 DCHECK(owningLayer->parent()); |
| 163 | 164 |
| 164 const LayerImpl* renderTarget = owningLayer->parent()->renderTarget(); | 165 const LayerImpl* renderTarget = owningLayer->parent()->renderTarget(); |
| 165 const RenderSurfaceImpl* self = owningLayer->renderSurface(); | 166 const RenderSurfaceImpl* self = owningLayer->renderSurface(); |
| 166 | 167 |
| 167 IntRect clippedRectInTarget = self->clipRect(); | 168 gfx::Rect clippedRectInTarget = self->clipRect(); |
| 168 if (owningLayer->backgroundFilters().hasFilterThatMovesPixels()) { | 169 if (owningLayer->backgroundFilters().hasFilterThatMovesPixels()) { |
| 169 // If the layer has background filters that move pixels, we cannot sciss
or as tightly. | 170 // If the layer has background filters that move pixels, we cannot sciss
or as tightly. |
| 170 // FIXME: this should be able to be a tighter scissor, perhaps expanded
by the filter outsets? | 171 // FIXME: this should be able to be a tighter scissor, perhaps expanded
by the filter outsets? |
| 171 clippedRectInTarget = renderTarget->renderSurface()->contentRect(); | 172 clippedRectInTarget = renderTarget->renderSurface()->contentRect(); |
| 172 } else if (clippedRectInTarget.isEmpty()) { | 173 } else if (clippedRectInTarget.IsEmpty()) { |
| 173 // For surfaces, empty clipRect means that the surface does not clip any
thing. | 174 // For surfaces, empty clipRect means that the surface does not clip any
thing. |
| 174 clippedRectInTarget = enclosingIntRect(intersection(renderTarget->render
Surface()->contentRect(), self->drawableContentRect())); | 175 clippedRectInTarget = renderTarget->renderSurface()->contentRect(); |
| 176 clippedRectInTarget.Intersect(gfx::ToEnclosingRect(self->drawableContent
Rect())); |
| 175 } else | 177 } else |
| 176 clippedRectInTarget.intersect(enclosingIntRect(self->drawableContentRect
())); | 178 clippedRectInTarget.Intersect(gfx::ToEnclosingRect(self->drawableContent
Rect())); |
| 177 return clippedRectInTarget; | 179 return clippedRectInTarget; |
| 178 } | 180 } |
| 179 | 181 |
| 180 RenderPass::Id RenderSurfaceImpl::renderPassId() | 182 RenderPass::Id RenderSurfaceImpl::renderPassId() |
| 181 { | 183 { |
| 182 int layerId = m_owningLayer->id(); | 184 int layerId = m_owningLayer->id(); |
| 183 int subId = 0; | 185 int subId = 0; |
| 184 DCHECK(layerId > 0); | 186 DCHECK(layerId > 0); |
| 185 return RenderPass::Id(layerId, subId); | 187 return RenderPass::Id(layerId, subId); |
| 186 } | 188 } |
| 187 | 189 |
| 188 void RenderSurfaceImpl::appendRenderPasses(RenderPassSink& passSink) | 190 void RenderSurfaceImpl::appendRenderPasses(RenderPassSink& passSink) |
| 189 { | 191 { |
| 190 for (size_t i = 0; i < m_contributingDelegatedRenderPassLayerList.size(); ++
i) | 192 for (size_t i = 0; i < m_contributingDelegatedRenderPassLayerList.size(); ++
i) |
| 191 m_contributingDelegatedRenderPassLayerList[i]->appendContributingRenderP
asses(passSink); | 193 m_contributingDelegatedRenderPassLayerList[i]->appendContributingRenderP
asses(passSink); |
| 192 | 194 |
| 193 scoped_ptr<RenderPass> pass = RenderPass::create(renderPassId(), m_contentRe
ct, m_screenSpaceTransform); | 195 scoped_ptr<RenderPass> pass = RenderPass::create(renderPassId(), m_contentRe
ct, m_screenSpaceTransform); |
| 194 pass->setDamageRect(m_damageTracker->currentDamageRect()); | 196 pass->setDamageRect(m_damageTracker->currentDamageRect()); |
| 195 pass->setFilters(m_owningLayer->filters()); | 197 pass->setFilters(m_owningLayer->filters()); |
| 196 pass->setFilter(m_owningLayer->filter()); | 198 pass->setFilter(m_owningLayer->filter()); |
| 197 pass->setBackgroundFilters(m_owningLayer->backgroundFilters()); | 199 pass->setBackgroundFilters(m_owningLayer->backgroundFilters()); |
| 198 passSink.appendRenderPass(pass.Pass()); | 200 passSink.appendRenderPass(pass.Pass()); |
| 199 } | 201 } |
| 200 | 202 |
| 201 void RenderSurfaceImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQ
uadsData, bool forReplica, RenderPass::Id renderPassId) | 203 void RenderSurfaceImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQ
uadsData, bool forReplica, RenderPass::Id renderPassId) |
| 202 { | 204 { |
| 203 DCHECK(!forReplica || m_owningLayer->hasReplica()); | 205 DCHECK(!forReplica || m_owningLayer->hasReplica()); |
| 204 | 206 |
| 205 IntRect clippedRectInTarget = computeClippedRectInTarget(m_owningLayer); | 207 gfx::Rect clippedRectInTarget = computeClippedRectInTarget(m_owningLayer); |
| 206 bool isOpaque = false; | 208 bool isOpaque = false; |
| 207 const WebTransformationMatrix& drawTransform = forReplica ? m_replicaDrawTra
nsform : m_drawTransform; | 209 const WebTransformationMatrix& drawTransform = forReplica ? m_replicaDrawTra
nsform : m_drawTransform; |
| 208 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(SharedQuadSta
te::create(drawTransform, m_contentRect, clippedRectInTarget, m_drawOpacity, isO
paque).Pass()); | 210 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(SharedQuadSta
te::create(drawTransform, m_contentRect, clippedRectInTarget, m_drawOpacity, isO
paque).Pass()); |
| 209 | 211 |
| 210 if (m_owningLayer->hasDebugBorders()) { | 212 if (m_owningLayer->hasDebugBorders()) { |
| 211 int red = forReplica ? debugReplicaBorderColorRed : debugSurfaceBorderCo
lorRed; | 213 int red = forReplica ? debugReplicaBorderColorRed : debugSurfaceBorderCo
lorRed; |
| 212 int green = forReplica ? debugReplicaBorderColorGreen : debugSurfaceBor
derColorGreen; | 214 int green = forReplica ? debugReplicaBorderColorGreen : debugSurfaceBor
derColorGreen; |
| 213 int blue = forReplica ? debugReplicaBorderColorBlue : debugSurfaceBorder
ColorBlue; | 215 int blue = forReplica ? debugReplicaBorderColorBlue : debugSurfaceBorder
ColorBlue; |
| 214 SkColor color = SkColorSetARGB(debugSurfaceBorderAlpha, red, green, blue
); | 216 SkColor color = SkColorSetARGB(debugSurfaceBorderAlpha, red, green, blue
); |
| 215 quadSink.append(DebugBorderDrawQuad::create(sharedQuadState, contentRect
(), color, debugSurfaceBorderWidth).PassAs<DrawQuad>(), appendQuadsData); | 217 quadSink.append(DebugBorderDrawQuad::create(sharedQuadState, contentRect
(), color, debugSurfaceBorderWidth).PassAs<DrawQuad>(), appendQuadsData); |
| 216 } | 218 } |
| 217 | 219 |
| 218 // FIXME: By using the same RenderSurfaceImpl for both the content and its r
eflection, | 220 // FIXME: By using the same RenderSurfaceImpl for both the content and its r
eflection, |
| 219 // it's currently not possible to apply a separate mask to the reflection la
yer | 221 // it's currently not possible to apply a separate mask to the reflection la
yer |
| 220 // or correctly handle opacity in reflections (opacity must be applied after
drawing | 222 // or correctly handle opacity in reflections (opacity must be applied after
drawing |
| 221 // both the layer and its reflection). The solution is to introduce yet anot
her RenderSurfaceImpl | 223 // both the layer and its reflection). The solution is to introduce yet anot
her RenderSurfaceImpl |
| 222 // to draw the layer and its reflection in. For now we only apply a separate
reflection | 224 // to draw the layer and its reflection in. For now we only apply a separate
reflection |
| 223 // mask if the contents don't have a mask of their own. | 225 // mask if the contents don't have a mask of their own. |
| 224 LayerImpl* maskLayer = m_owningLayer->maskLayer(); | 226 LayerImpl* maskLayer = m_owningLayer->maskLayer(); |
| 225 if (maskLayer && (!maskLayer->drawsContent() || maskLayer->bounds().isEmpty(
))) | 227 if (maskLayer && (!maskLayer->drawsContent() || maskLayer->bounds().IsEmpty(
))) |
| 226 maskLayer = 0; | 228 maskLayer = 0; |
| 227 | 229 |
| 228 if (!maskLayer && forReplica) { | 230 if (!maskLayer && forReplica) { |
| 229 maskLayer = m_owningLayer->replicaLayer()->maskLayer(); | 231 maskLayer = m_owningLayer->replicaLayer()->maskLayer(); |
| 230 if (maskLayer && (!maskLayer->drawsContent() || maskLayer->bounds().isEm
pty())) | 232 if (maskLayer && (!maskLayer->drawsContent() || maskLayer->bounds().IsEm
pty())) |
| 231 maskLayer = 0; | 233 maskLayer = 0; |
| 232 } | 234 } |
| 233 | 235 |
| 234 float maskTexCoordScaleX = 1; | 236 float maskTexCoordScaleX = 1; |
| 235 float maskTexCoordScaleY = 1; | 237 float maskTexCoordScaleY = 1; |
| 236 float maskTexCoordOffsetX = 0; | 238 float maskTexCoordOffsetX = 0; |
| 237 float maskTexCoordOffsetY = 0; | 239 float maskTexCoordOffsetY = 0; |
| 238 if (maskLayer) { | 240 if (maskLayer) { |
| 239 maskTexCoordScaleX = contentRect().width() / maskLayer->contentsScaleX()
/ maskLayer->bounds().width(); | 241 maskTexCoordScaleX = contentRect().width() / maskLayer->contentsScaleX()
/ maskLayer->bounds().width(); |
| 240 maskTexCoordScaleY = contentRect().height() / maskLayer->contentsScaleY(
) / maskLayer->bounds().height(); | 242 maskTexCoordScaleY = contentRect().height() / maskLayer->contentsScaleY(
) / maskLayer->bounds().height(); |
| 241 maskTexCoordOffsetX = static_cast<float>(contentRect().x()) / contentRec
t().width() * maskTexCoordScaleX; | 243 maskTexCoordOffsetX = static_cast<float>(contentRect().x()) / contentRec
t().width() * maskTexCoordScaleX; |
| 242 maskTexCoordOffsetY = static_cast<float>(contentRect().y()) / contentRec
t().height() * maskTexCoordScaleY; | 244 maskTexCoordOffsetY = static_cast<float>(contentRect().y()) / contentRec
t().height() * maskTexCoordScaleY; |
| 243 } | 245 } |
| 244 | 246 |
| 245 ResourceProvider::ResourceId maskResourceId = maskLayer ? maskLayer->content
sResourceId() : 0; | 247 ResourceProvider::ResourceId maskResourceId = maskLayer ? maskLayer->content
sResourceId() : 0; |
| 246 IntRect contentsChangedSinceLastFrame = contentsChanged() ? m_contentRect :
IntRect(); | 248 gfx::Rect contentsChangedSinceLastFrame = contentsChanged() ? m_contentRect
: gfx::Rect(); |
| 247 | 249 |
| 248 quadSink.append(RenderPassDrawQuad::create(sharedQuadState, contentRect(), r
enderPassId, forReplica, maskResourceId, contentsChangedSinceLastFrame, | 250 quadSink.append(RenderPassDrawQuad::create(sharedQuadState, contentRect(), r
enderPassId, forReplica, maskResourceId, contentsChangedSinceLastFrame, |
| 249 maskTexCoordScaleX, maskTexCoor
dScaleY, maskTexCoordOffsetX, maskTexCoordOffsetY).PassAs<DrawQuad>(), appendQua
dsData); | 251 maskTexCoordScaleX, maskTexCoor
dScaleY, maskTexCoordOffsetX, maskTexCoordOffsetY).PassAs<DrawQuad>(), appendQua
dsData); |
| 250 } | 252 } |
| 251 | 253 |
| 252 } | 254 } |
| OLD | NEW |