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/resources/content_layer_updater.h" | 5 #include "cc/resources/content_layer_updater.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "cc/debug/rendering_stats_instrumentation.h" | 9 #include "cc/debug/rendering_stats_instrumentation.h" |
| 10 #include "cc/resources/layer_painter.h" | 10 #include "cc/resources/layer_painter.h" |
| 11 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
| 12 #include "third_party/skia/include/core/SkPaint.h" | 12 #include "third_party/skia/include/core/SkPaint.h" |
| 13 #include "third_party/skia/include/core/SkRect.h" | 13 #include "third_party/skia/include/core/SkRect.h" |
| 14 #include "third_party/skia/include/core/SkScalar.h" | 14 #include "third_party/skia/include/core/SkScalar.h" |
| 15 #include "ui/gfx/rect_conversions.h" | 15 #include "ui/gfx/rect_conversions.h" |
| 16 #include "ui/gfx/rect_f.h" | 16 #include "ui/gfx/rect_f.h" |
| 17 #include "ui/gfx/skia_util.h" | |
| 17 | 18 |
| 18 namespace cc { | 19 namespace cc { |
| 19 | 20 |
| 20 ContentLayerUpdater::ContentLayerUpdater( | 21 ContentLayerUpdater::ContentLayerUpdater( |
| 21 scoped_ptr<LayerPainter> painter, | 22 scoped_ptr<LayerPainter> painter, |
| 22 RenderingStatsInstrumentation* stats_instrumentation, | 23 RenderingStatsInstrumentation* stats_instrumentation, |
| 23 int layer_id) | 24 int layer_id) |
| 24 : rendering_stats_instrumentation_(stats_instrumentation), | 25 : rendering_stats_instrumentation_(stats_instrumentation), |
| 25 layer_id_(layer_id), | 26 layer_id_(layer_id), |
| 26 layer_is_opaque_(false), | 27 layer_is_opaque_(false), |
| 27 layer_fills_bounds_completely_(false), | 28 layer_fills_bounds_completely_(false), |
| 28 painter_(painter.Pass()) {} | 29 painter_(painter.Pass()), |
| 30 background_color_(SK_ColorTRANSPARENT) { | |
| 31 } | |
| 29 | 32 |
| 30 ContentLayerUpdater::~ContentLayerUpdater() {} | 33 ContentLayerUpdater::~ContentLayerUpdater() {} |
| 31 | 34 |
| 32 void ContentLayerUpdater::set_rendering_stats_instrumentation( | 35 void ContentLayerUpdater::set_rendering_stats_instrumentation( |
| 33 RenderingStatsInstrumentation* rsi) { | 36 RenderingStatsInstrumentation* rsi) { |
| 34 rendering_stats_instrumentation_ = rsi; | 37 rendering_stats_instrumentation_ = rsi; |
| 35 } | 38 } |
| 36 | 39 |
| 37 void ContentLayerUpdater::PaintContents(SkCanvas* canvas, | 40 void ContentLayerUpdater::PaintContents(SkCanvas* canvas, |
| 38 const gfx::Rect& content_rect, | 41 const gfx::Size& content_size, |
|
danakj
2014/09/19 22:02:58
layer_content_size
sky
2014/09/22 17:59:59
Done.
| |
| 42 const gfx::Rect& paint_rect, | |
| 39 float contents_width_scale, | 43 float contents_width_scale, |
| 40 float contents_height_scale) { | 44 float contents_height_scale) { |
| 41 TRACE_EVENT0("cc", "ContentLayerUpdater::PaintContents"); | 45 TRACE_EVENT0("cc", "ContentLayerUpdater::PaintContents"); |
| 42 if (!canvas) | 46 if (!canvas) |
| 43 return; | 47 return; |
| 44 canvas->save(); | 48 canvas->save(); |
| 45 canvas->translate(SkFloatToScalar(-content_rect.x()), | 49 canvas->translate(SkIntToScalar(-paint_rect.x()), |
| 46 SkFloatToScalar(-content_rect.y())); | 50 SkIntToScalar(-paint_rect.y())); |
| 47 | 51 |
| 48 // The |canvas| backing should be sized to hold the |content_rect|. | 52 // The |canvas| backing should be sized to hold the |paint_rect|. |
| 49 DCHECK_EQ(content_rect.width(), canvas->getBaseLayerSize().width()); | 53 DCHECK_EQ(paint_rect.width(), canvas->getBaseLayerSize().width()); |
| 50 DCHECK_EQ(content_rect.height(), canvas->getBaseLayerSize().height()); | 54 DCHECK_EQ(paint_rect.height(), canvas->getBaseLayerSize().height()); |
| 51 | 55 |
| 52 gfx::Rect layer_rect = content_rect; | 56 gfx::Rect layer_rect = paint_rect; |
|
danakj
2014/09/19 22:02:57
move down to where the rest of the computation of
sky
2014/09/22 17:59:59
Done.
| |
| 53 if (contents_width_scale != 1.f || contents_height_scale != 1.f) { | 57 const bool is_scaled = |
| 58 contents_width_scale != 1.f || contents_height_scale != 1.f; | |
| 59 | |
| 60 if (is_scaled && (layer_is_opaque_ || layer_fills_bounds_completely_)) { | |
| 61 // Even if completely covered, for rasterizations that touch the edge of the | |
| 62 // layer, we also need to raster the background color underneath the last | |
| 63 // texel (since the recording won't cover it) and outside the last texel | |
|
danakj
2014/09/19 22:02:57
s/recording/paint/
sky
2014/09/22 17:59:59
Done.
| |
| 64 // (due to linear filtering when using this texture). | |
|
danakj
2014/09/19 22:02:57
this "outside the last texel" isn't needed here, b
sky
2014/09/22 18:00:00
Done.
| |
| 65 // The final texel of content may only be partially covered by a | |
|
danakj
2014/09/19 22:02:57
whitespace above to separate
sky
2014/09/22 17:59:59
Done.
| |
| 66 // rasterization; this rect represents the content rect that is fully | |
| 67 // covered by content. | |
| 68 const gfx::Rect content_rect = gfx::Rect(content_size); | |
|
danakj
2014/09/19 22:02:57
layer_content_rect
sky
2014/09/22 18:00:00
Done.
| |
| 69 gfx::Rect deflated_content_rect = content_rect; | |
|
danakj
2014/09/19 22:02:58
deflated_layer_content_rect
sky
2014/09/22 17:59:59
Done.
| |
| 70 deflated_content_rect.Inset(0, 0, 1, 1); | |
|
danakj
2014/09/19 22:02:57
whitespace below to separate, make it clear the co
sky
2014/09/22 18:00:00
Done.
| |
| 71 if (!content_rect.Contains(paint_rect)) { | |
|
danakj
2014/09/19 22:02:57
deflated_content_rect
sky
2014/09/22 17:59:59
Done.
| |
| 72 // Drawing at most 2 x 2 x (canvas width + canvas height) texels is 2-3X | |
|
danakj
2014/09/19 22:02:58
s/2/1/
sky
2014/09/22 17:59:59
Done.
| |
| 73 // faster than clearing, so special case this. | |
|
danakj
2014/09/19 22:02:58
can you DCHECK_LE(paint_rect.right(), content_rect
sky
2014/09/22 17:59:59
Done.
| |
| 74 canvas->save(); | |
| 75 gfx::Rect inflated_content_rect = content_rect; | |
|
danakj
2014/09/19 22:02:57
remove this just use the content_rect
sky
2014/09/22 17:59:59
Done.
| |
| 76 inflated_content_rect.Inset(0, 0, -1, -1); | |
| 77 canvas->clipRect(gfx::RectToSkRect(inflated_content_rect), | |
| 78 SkRegion::kReplace_Op); | |
| 79 canvas->clipRect(gfx::RectToSkRect(deflated_content_rect), | |
| 80 SkRegion::kDifference_Op); | |
| 81 canvas->drawColor(background_color_, SkXfermode::kSrc_Mode); | |
| 82 canvas->restore(); | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 if (is_scaled) { | |
| 54 canvas->scale(SkFloatToScalar(contents_width_scale), | 87 canvas->scale(SkFloatToScalar(contents_width_scale), |
| 55 SkFloatToScalar(contents_height_scale)); | 88 SkFloatToScalar(contents_height_scale)); |
| 56 | 89 |
| 57 layer_rect = gfx::ScaleToEnclosingRect( | 90 layer_rect = gfx::ScaleToEnclosingRect( |
| 58 content_rect, 1.f / contents_width_scale, 1.f / contents_height_scale); | 91 paint_rect, 1.f / contents_width_scale, 1.f / contents_height_scale); |
| 59 } | 92 } |
| 60 | 93 |
| 61 SkRect layer_sk_rect = SkRect::MakeXYWH( | 94 SkRect layer_sk_rect = SkRect::MakeXYWH( |
| 62 layer_rect.x(), layer_rect.y(), layer_rect.width(), layer_rect.height()); | 95 layer_rect.x(), layer_rect.y(), layer_rect.width(), layer_rect.height()); |
| 63 | 96 |
| 64 canvas->clipRect(layer_sk_rect); | 97 canvas->clipRect(layer_sk_rect); |
| 65 | 98 |
| 66 // If the layer has opaque contents or will fill the bounds completely there | 99 // If the layer has opaque contents or will fill the bounds completely there |
| 67 // is no need to clear the canvas before painting. | 100 // is no need to clear the canvas before painting. |
| 68 if (!layer_is_opaque_ && !layer_fills_bounds_completely_) { | 101 if (!layer_is_opaque_ && !layer_fills_bounds_completely_) { |
| 69 TRACE_EVENT0("cc", "Clear"); | 102 TRACE_EVENT0("cc", "Clear"); |
| 70 canvas->drawColor(SK_ColorTRANSPARENT, SkXfermode::kSrc_Mode); | 103 canvas->drawColor(SK_ColorTRANSPARENT, SkXfermode::kSrc_Mode); |
| 71 } | 104 } |
| 72 | 105 |
| 73 painter_->Paint(canvas, layer_rect); | 106 painter_->Paint(canvas, layer_rect); |
| 74 canvas->restore(); | 107 canvas->restore(); |
| 75 | 108 |
| 76 content_rect_ = content_rect; | 109 paint_rect_ = paint_rect; |
| 77 } | 110 } |
| 78 | 111 |
| 79 void ContentLayerUpdater::SetOpaque(bool opaque) { | 112 void ContentLayerUpdater::SetOpaque(bool opaque) { |
| 80 layer_is_opaque_ = opaque; | 113 layer_is_opaque_ = opaque; |
| 81 } | 114 } |
| 82 | 115 |
| 83 void ContentLayerUpdater::SetFillsBoundsCompletely(bool fills_bounds) { | 116 void ContentLayerUpdater::SetFillsBoundsCompletely(bool fills_bounds) { |
| 84 layer_fills_bounds_completely_ = fills_bounds; | 117 layer_fills_bounds_completely_ = fills_bounds; |
| 85 } | 118 } |
| 86 | 119 |
| 120 void ContentLayerUpdater::SetBackgroundColor(SkColor background_color) { | |
| 121 background_color_ = background_color; | |
| 122 } | |
| 123 | |
| 87 } // namespace cc | 124 } // namespace cc |
| OLD | NEW |