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/SkDevice.h" | |
12 #include "third_party/skia/include/core/SkPaint.h" | 13 #include "third_party/skia/include/core/SkPaint.h" |
13 #include "third_party/skia/include/core/SkRect.h" | 14 #include "third_party/skia/include/core/SkRect.h" |
14 #include "third_party/skia/include/core/SkScalar.h" | 15 #include "third_party/skia/include/core/SkScalar.h" |
15 #include "ui/gfx/rect_conversions.h" | 16 #include "ui/gfx/rect_conversions.h" |
16 #include "ui/gfx/rect_f.h" | 17 #include "ui/gfx/rect_f.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 painter_(painter.Pass()) {} | 27 painter_(painter.Pass()), |
28 layer_is_opaque_(false) {} | |
27 | 29 |
28 ContentLayerUpdater::~ContentLayerUpdater() {} | 30 ContentLayerUpdater::~ContentLayerUpdater() {} |
29 | 31 |
30 void ContentLayerUpdater::set_rendering_stats_instrumentation( | 32 void ContentLayerUpdater::set_rendering_stats_instrumentation( |
31 RenderingStatsInstrumentation* rsi) { | 33 RenderingStatsInstrumentation* rsi) { |
32 rendering_stats_instrumentation_ = rsi; | 34 rendering_stats_instrumentation_ = rsi; |
33 } | 35 } |
34 | 36 |
35 void ContentLayerUpdater::PaintContents(SkCanvas* canvas, | 37 void ContentLayerUpdater::PaintContents(SkCanvas* canvas, |
36 gfx::Rect content_rect, | 38 gfx::Rect content_rect, |
37 float contents_width_scale, | 39 float contents_width_scale, |
38 float contents_height_scale, | 40 float contents_height_scale, |
39 gfx::Rect* resulting_opaque_rect) { | 41 gfx::Rect* resulting_opaque_rect) { |
40 TRACE_EVENT0("cc", "ContentLayerUpdater::PaintContents"); | 42 TRACE_EVENT0("cc", "ContentLayerUpdater::PaintContents"); |
41 canvas->save(); | 43 canvas->save(); |
42 canvas->translate(SkFloatToScalar(-content_rect.x()), | 44 canvas->translate(SkFloatToScalar(-content_rect.x()), |
43 SkFloatToScalar(-content_rect.y())); | 45 SkFloatToScalar(-content_rect.y())); |
44 | 46 |
45 gfx::Rect layer_rect = content_rect; | 47 gfx::Rect layer_rect = content_rect; |
46 | 48 |
47 if (contents_width_scale != 1.f || contents_height_scale != 1.f) { | 49 if (contents_width_scale != 1.f || contents_height_scale != 1.f) { |
48 canvas->scale(SkFloatToScalar(contents_width_scale), | 50 canvas->scale(SkFloatToScalar(contents_width_scale), |
49 SkFloatToScalar(contents_height_scale)); | 51 SkFloatToScalar(contents_height_scale)); |
50 | 52 |
51 layer_rect = gfx::ScaleToEnclosingRect( | 53 layer_rect = gfx::ScaleToEnclosingRect( |
52 content_rect, 1.f / contents_width_scale, 1.f / contents_height_scale); | 54 content_rect, 1.f / contents_width_scale, 1.f / contents_height_scale); |
53 } | 55 } |
54 | 56 |
55 SkPaint paint; | |
56 paint.setAntiAlias(false); | |
57 paint.setXfermodeMode(SkXfermode::kClear_Mode); | |
58 SkRect layer_sk_rect = SkRect::MakeXYWH( | 57 SkRect layer_sk_rect = SkRect::MakeXYWH( |
59 layer_rect.x(), layer_rect.y(), layer_rect.width(), layer_rect.height()); | 58 layer_rect.x(), layer_rect.y(), layer_rect.width(), layer_rect.height()); |
60 canvas->drawRect(layer_sk_rect, paint); | 59 |
60 // If the layer has opaque contents then there is no need to | |
61 // clear the canvas before painting. | |
62 if (!layer_is_opaque_) { | |
63 SkDevice* device = canvas->getDevice(); | |
64 if (content_rect.width() == device->width() && | |
65 content_rect.height() == device->height()) { | |
66 canvas->clear(SK_ColorTRANSPARENT); | |
67 } else { | |
68 SkPaint paint; | |
69 paint.setAntiAlias(false); | |
70 paint.setXfermodeMode(SkXfermode::kClear_Mode); | |
71 canvas->drawRect(layer_sk_rect, paint); | |
enne (OOO)
2013/08/27 17:13:04
Could you just have the first branch of this if/el
| |
72 } | |
73 } | |
74 | |
61 canvas->clipRect(layer_sk_rect); | 75 canvas->clipRect(layer_sk_rect); |
62 | 76 |
63 gfx::RectF opaque_layer_rect; | 77 gfx::RectF opaque_layer_rect; |
64 painter_->Paint(canvas, layer_rect, &opaque_layer_rect); | 78 painter_->Paint(canvas, layer_rect, &opaque_layer_rect); |
65 canvas->restore(); | 79 canvas->restore(); |
66 | 80 |
67 gfx::Rect opaque_content_rect = gfx::ToEnclosedRect(gfx::ScaleRect( | 81 gfx::Rect opaque_content_rect = gfx::ToEnclosedRect(gfx::ScaleRect( |
68 opaque_layer_rect, contents_width_scale, contents_height_scale)); | 82 opaque_layer_rect, contents_width_scale, contents_height_scale)); |
69 *resulting_opaque_rect = opaque_content_rect; | 83 *resulting_opaque_rect = opaque_content_rect; |
70 | 84 |
71 content_rect_ = content_rect; | 85 content_rect_ = content_rect; |
72 } | 86 } |
73 | 87 |
88 void ContentLayerUpdater::SetOpaque(bool opaque) { | |
89 layer_is_opaque_ = opaque; | |
90 } | |
91 | |
74 } // namespace cc | 92 } // namespace cc |
OLD | NEW |