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" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 canvas->scale(SkFloatToScalar(contents_width_scale), | 55 canvas->scale(SkFloatToScalar(contents_width_scale), |
56 SkFloatToScalar(contents_height_scale)); | 56 SkFloatToScalar(contents_height_scale)); |
57 | 57 |
58 layer_rect = gfx::ScaleToEnclosingRect( | 58 layer_rect = gfx::ScaleToEnclosingRect( |
59 content_rect, 1.f / contents_width_scale, 1.f / contents_height_scale); | 59 content_rect, 1.f / contents_width_scale, 1.f / contents_height_scale); |
60 } | 60 } |
61 | 61 |
62 SkRect layer_sk_rect = SkRect::MakeXYWH( | 62 SkRect layer_sk_rect = SkRect::MakeXYWH( |
63 layer_rect.x(), layer_rect.y(), layer_rect.width(), layer_rect.height()); | 63 layer_rect.x(), layer_rect.y(), layer_rect.width(), layer_rect.height()); |
64 | 64 |
65 canvas->clipRect(layer_sk_rect); | |
66 | |
65 // If the layer has opaque contents then there is no need to | 67 // If the layer has opaque contents then there is no need to |
66 // clear the canvas before painting. | 68 // clear the canvas before painting. |
67 if (!layer_is_opaque_) | 69 if (!layer_is_opaque_) { |
68 canvas->clear(SK_ColorTRANSPARENT); | 70 TRACE_EVENT0("cc", "Clear"); |
69 | 71 |
70 canvas->clipRect(layer_sk_rect); | 72 // If the canvas is substantially larger than the area that will be painted |
73 // then it's faster to clear only the pixels within the clipRect. | |
74 const float kClearFasterThanDrawRatio = 0.8f; | |
75 int canvasArea = | |
enne (OOO)
2013/11/06 01:59:45
canvasArea => canvas_area
| |
76 canvas->getDevice()->width() * canvas->getDevice()->height(); | |
77 int clipArea = layer_rect.width() * layer_rect.height(); | |
enne (OOO)
2013/11/06 01:59:45
clipArea => clip_area
| |
78 if (kClearFasterThanDrawRatio * canvasArea < clipArea) | |
79 canvas->clear(SK_ColorTRANSPARENT); | |
80 else | |
81 canvas->drawColor(SK_ColorTRANSPARENT, SkXfermode::kSrc_Mode); | |
82 } | |
71 | 83 |
72 gfx::RectF opaque_layer_rect; | 84 gfx::RectF opaque_layer_rect; |
73 painter_->Paint(canvas, layer_rect, &opaque_layer_rect); | 85 painter_->Paint(canvas, layer_rect, &opaque_layer_rect); |
74 canvas->restore(); | 86 canvas->restore(); |
75 | 87 |
76 gfx::Rect opaque_content_rect = gfx::ToEnclosedRect(gfx::ScaleRect( | 88 gfx::Rect opaque_content_rect = gfx::ToEnclosedRect(gfx::ScaleRect( |
77 opaque_layer_rect, contents_width_scale, contents_height_scale)); | 89 opaque_layer_rect, contents_width_scale, contents_height_scale)); |
78 *resulting_opaque_rect = opaque_content_rect; | 90 *resulting_opaque_rect = opaque_content_rect; |
79 | 91 |
80 content_rect_ = content_rect; | 92 content_rect_ = content_rect; |
81 } | 93 } |
82 | 94 |
83 void ContentLayerUpdater::SetOpaque(bool opaque) { | 95 void ContentLayerUpdater::SetOpaque(bool opaque) { |
84 layer_is_opaque_ = opaque; | 96 layer_is_opaque_ = opaque; |
85 } | 97 } |
86 | 98 |
87 } // namespace cc | 99 } // namespace cc |
OLD | NEW |