Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: cc/resources/display_list_raster_source.cc

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/resources/display_list_raster_source.h ('k') | cc/resources/display_list_recording_source.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/resources/display_list_raster_source.h"
6
7 #include "base/debug/trace_event.h"
8 #include "cc/base/region.h"
9 #include "cc/debug/debug_colors.h"
10 #include "cc/resources/display_item_list.h"
11 #include "cc/resources/raster_source_helper.h"
12 #include "skia/ext/analysis_canvas.h"
13 #include "third_party/skia/include/core/SkCanvas.h"
14 #include "third_party/skia/include/core/SkPictureRecorder.h"
15 #include "ui/gfx/geometry/rect_conversions.h"
16
17 namespace {
18
19 #ifdef NDEBUG
20 const bool kDefaultClearCanvasSetting = false;
21 #else
22 const bool kDefaultClearCanvasSetting = true;
23 #endif
24
25 } // namespace
26
27 namespace cc {
28
29 scoped_refptr<DisplayListRasterSource> DisplayListRasterSource::Create() {
30 return make_scoped_refptr(new DisplayListRasterSource);
31 }
32
33 scoped_refptr<DisplayListRasterSource>
34 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
35 const DisplayListRecordingSource* other) {
36 return make_scoped_refptr(new DisplayListRasterSource(other));
37 }
38
39 DisplayListRasterSource::DisplayListRasterSource()
40 : background_color_(SK_ColorTRANSPARENT),
41 requires_clear_(true),
42 can_use_lcd_text_(true),
43 is_solid_color_(false),
44 solid_color_(SK_ColorTRANSPARENT),
45 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting),
46 slow_down_raster_scale_factor_for_debug_(0),
47 should_attempt_to_use_distance_field_text_(false) {
48 }
49
50 DisplayListRasterSource::DisplayListRasterSource(
51 const DisplayListRecordingSource* other)
52 : display_list_(other->display_list_),
53 background_color_(SK_ColorTRANSPARENT),
54 requires_clear_(true),
55 can_use_lcd_text_(other->can_use_lcd_text_),
56 is_solid_color_(other->is_solid_color_),
57 solid_color_(other->solid_color_),
58 recorded_viewport_(other->recorded_viewport_),
59 size_(other->size_),
60 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting),
61 slow_down_raster_scale_factor_for_debug_(
62 other->slow_down_raster_scale_factor_for_debug_),
63 should_attempt_to_use_distance_field_text_(false) {
64 }
65
66 DisplayListRasterSource::~DisplayListRasterSource() {
67 }
68
69 void DisplayListRasterSource::PlaybackToSharedCanvas(
70 SkCanvas* canvas,
71 const gfx::Rect& canvas_rect,
72 float contents_scale) const {
73 RasterCommon(canvas, NULL, canvas_rect, contents_scale, false);
74 }
75
76 void DisplayListRasterSource::RasterForAnalysis(skia::AnalysisCanvas* canvas,
77 const gfx::Rect& canvas_rect,
78 float contents_scale) const {
79 RasterCommon(canvas, canvas, canvas_rect, contents_scale, true);
80 }
81
82 void DisplayListRasterSource::PlaybackToCanvas(SkCanvas* canvas,
83 const gfx::Rect& canvas_rect,
84 float contents_scale) const {
85 RasterSourceHelper::PrepareForPlaybackToCanvas(
86 canvas, canvas_rect, gfx::Rect(size_), contents_scale, background_color_,
87 clear_canvas_with_debug_color_, requires_clear_);
88
89 RasterCommon(canvas, NULL, canvas_rect, contents_scale, false);
90 }
91
92 void DisplayListRasterSource::RasterCommon(SkCanvas* canvas,
93 SkDrawPictureCallback* callback,
94 const gfx::Rect& canvas_rect,
95 float contents_scale,
96 bool is_analysis) const {
97 canvas->translate(-canvas_rect.x(), -canvas_rect.y());
98 gfx::Rect content_rect =
99 gfx::ToEnclosingRect(gfx::ScaleRect(gfx::Rect(size_), contents_scale));
100 content_rect.Intersect(canvas_rect);
101
102 canvas->clipRect(gfx::RectToSkRect(content_rect), SkRegion::kIntersect_Op);
103
104 DCHECK(display_list_.get());
105 display_list_->Raster(canvas, callback, contents_scale);
106 }
107
108 skia::RefPtr<SkPicture> DisplayListRasterSource::GetFlattenedPicture() {
109 TRACE_EVENT0("cc", "DisplayListRasterSource::GetFlattenedPicture");
110
111 gfx::Rect display_list_rect(size_);
112 SkPictureRecorder recorder;
113 SkCanvas* canvas = recorder.beginRecording(display_list_rect.width(),
114 display_list_rect.height());
115 if (!display_list_rect.IsEmpty())
116 PlaybackToCanvas(canvas, display_list_rect, 1.0);
117 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording());
118
119 return picture;
120 }
121
122 size_t DisplayListRasterSource::GetPictureMemoryUsage() const {
123 return display_list_->PictureMemoryUsage();
124 }
125
126 void DisplayListRasterSource::PerformSolidColorAnalysis(
127 const gfx::Rect& content_rect,
128 float contents_scale,
129 RasterSource::SolidColorAnalysis* analysis) const {
130 DCHECK(analysis);
131 TRACE_EVENT0("cc", "DisplayListRasterSource::PerformSolidColorAnalysis");
132
133 gfx::Rect layer_rect =
134 gfx::ScaleToEnclosingRect(content_rect, 1.0f / contents_scale);
135
136 layer_rect.Intersect(gfx::Rect(size_));
137 skia::AnalysisCanvas canvas(layer_rect.width(), layer_rect.height());
138 RasterForAnalysis(&canvas, layer_rect, 1.0f);
139 analysis->is_solid_color = canvas.GetColorIfSolid(&analysis->solid_color);
140 }
141
142 void DisplayListRasterSource::GatherPixelRefs(
143 const gfx::Rect& content_rect,
144 float contents_scale,
145 std::vector<SkPixelRef*>* pixel_refs) const {
146 // TODO(ajuma): Implement this.
147 }
148
149 bool DisplayListRasterSource::CoversRect(const gfx::Rect& content_rect,
150 float contents_scale) const {
151 if (size_.IsEmpty())
152 return false;
153 gfx::Rect layer_rect =
154 gfx::ScaleToEnclosingRect(content_rect, 1.f / contents_scale);
155 layer_rect.Intersect(gfx::Rect(size_));
156
157 return recorded_viewport_.Contains(layer_rect);
158 }
159
160 gfx::Size DisplayListRasterSource::GetSize() const {
161 return size_;
162 }
163
164 bool DisplayListRasterSource::IsSolidColor() const {
165 return is_solid_color_;
166 }
167
168 SkColor DisplayListRasterSource::GetSolidColor() const {
169 DCHECK(IsSolidColor());
170 return solid_color_;
171 }
172
173 bool DisplayListRasterSource::HasRecordings() const {
174 return !!display_list_.get();
175 }
176
177 void DisplayListRasterSource::SetShouldAttemptToUseDistanceFieldText() {
178 should_attempt_to_use_distance_field_text_ = true;
179 }
180
181 void DisplayListRasterSource::SetBackgoundColor(SkColor background_color) {
182 background_color_ = background_color;
183 }
184
185 void DisplayListRasterSource::SetRequiresClear(bool requires_clear) {
186 requires_clear_ = requires_clear;
187 }
188
189 bool DisplayListRasterSource::ShouldAttemptToUseDistanceFieldText() const {
190 return should_attempt_to_use_distance_field_text_;
191 }
192
193 void DisplayListRasterSource::AsValueInto(
194 base::debug::TracedValue* array) const {
195 if (display_list_.get())
196 TracedValue::AppendIDRef(display_list_.get(), array);
197 }
198
199 void DisplayListRasterSource::DidBeginTracing() {
200 if (display_list_.get())
201 display_list_->EmitTraceSnapshot();
202 }
203
204 bool DisplayListRasterSource::CanUseLCDText() const {
205 return can_use_lcd_text_;
206 }
207
208 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/display_list_raster_source.h ('k') | cc/resources/display_list_recording_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698