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

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

Issue 903273002: Update from https://crrev.com/315085 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months 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/picture.h ('k') | cc/resources/picture_layer_tiling.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/picture.h" 5 #include "cc/resources/picture.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 scoped_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodec::Decode(data, size)); 46 scoped_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodec::Decode(data, size));
47 if (decoded_jpeg) { 47 if (decoded_jpeg) {
48 *bm = *decoded_jpeg; 48 *bm = *decoded_jpeg;
49 return true; 49 return true;
50 } 50 }
51 return false; 51 return false;
52 } 52 }
53 53
54 } // namespace 54 } // namespace
55 55
56 scoped_refptr<Picture> Picture::Create(const gfx::Rect& layer_rect, 56 scoped_refptr<Picture> Picture::Create(
57 ContentLayerClient* client, 57 const gfx::Rect& layer_rect,
58 const gfx::Size& tile_grid_size, 58 ContentLayerClient* client,
59 bool gather_pixel_refs, 59 const gfx::Size& tile_grid_size,
60 RecordingMode recording_mode) { 60 bool gather_pixel_refs,
61 RecordingSource::RecordingMode recording_mode) {
61 scoped_refptr<Picture> picture = make_scoped_refptr(new Picture(layer_rect)); 62 scoped_refptr<Picture> picture = make_scoped_refptr(new Picture(layer_rect));
62 63
63 picture->Record(client, tile_grid_size, recording_mode); 64 picture->Record(client, tile_grid_size, recording_mode);
64 if (gather_pixel_refs) 65 if (gather_pixel_refs)
65 picture->GatherPixelRefs(tile_grid_size); 66 picture->GatherPixelRefs(tile_grid_size);
66 67
67 return picture; 68 return picture;
68 } 69 }
69 70
70 Picture::Picture(const gfx::Rect& layer_rect) 71 Picture::Picture(const gfx::Rect& layer_rect)
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); 163 return SkPictureUtils::ApproximateBytesUsed(picture_.get());
163 } 164 }
164 165
165 bool Picture::HasText() const { 166 bool Picture::HasText() const {
166 DCHECK(picture_); 167 DCHECK(picture_);
167 return picture_->hasText(); 168 return picture_->hasText();
168 } 169 }
169 170
170 void Picture::Record(ContentLayerClient* painter, 171 void Picture::Record(ContentLayerClient* painter,
171 const gfx::Size& tile_grid_size, 172 const gfx::Size& tile_grid_size,
172 RecordingMode recording_mode) { 173 RecordingSource::RecordingMode recording_mode) {
173 TRACE_EVENT2("cc", 174 TRACE_EVENT2("cc",
174 "Picture::Record", 175 "Picture::Record",
175 "data", 176 "data",
176 AsTraceableRecordData(), 177 AsTraceableRecordData(),
177 "recording_mode", 178 "recording_mode",
178 recording_mode); 179 recording_mode);
179 180
180 DCHECK(!picture_); 181 DCHECK(!picture_);
181 DCHECK(!tile_grid_size.IsEmpty()); 182 DCHECK(!tile_grid_size.IsEmpty());
182 183
183 // TODO(mtklein): If SkRTree sticks, clean up tile_grid_info. skbug.com/3085 184 // TODO(mtklein): If SkRTree sticks, clean up tile_grid_info. skbug.com/3085
184 SkRTreeFactory factory; 185 SkRTreeFactory factory;
185 SkPictureRecorder recorder; 186 SkPictureRecorder recorder;
186 187
187 skia::RefPtr<SkCanvas> canvas; 188 skia::RefPtr<SkCanvas> canvas;
188 canvas = skia::SharePtr(recorder.beginRecording( 189 canvas = skia::SharePtr(recorder.beginRecording(
189 layer_rect_.width(), layer_rect_.height(), &factory, 190 layer_rect_.width(), layer_rect_.height(), &factory,
190 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)); 191 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag));
191 192
192 ContentLayerClient::GraphicsContextStatus graphics_context_status = 193 ContentLayerClient::PaintingControlSetting painting_control =
193 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED; 194 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL;
194 195
195 switch (recording_mode) { 196 switch (recording_mode) {
196 case RECORD_NORMALLY: 197 case RecordingSource::RECORD_NORMALLY:
197 // Already setup for normal recording. 198 // Already setup for normal recording.
198 break; 199 break;
199 case RECORD_WITH_SK_NULL_CANVAS: 200 case RecordingSource::RECORD_WITH_SK_NULL_CANVAS:
200 canvas = skia::AdoptRef(SkCreateNullCanvas()); 201 canvas = skia::AdoptRef(SkCreateNullCanvas());
201 break; 202 break;
202 case RECORD_WITH_PAINTING_DISABLED: 203 case RecordingSource::RECORD_WITH_PAINTING_DISABLED:
203 // We pass a disable flag through the paint calls when perfromance 204 // We pass a disable flag through the paint calls when perfromance
204 // testing (the only time this case should ever arise) when we want to 205 // testing (the only time this case should ever arise) when we want to
205 // prevent the Blink GraphicsContext object from consuming any compute 206 // prevent the Blink GraphicsContext object from consuming any compute
206 // time. 207 // time.
207 canvas = skia::AdoptRef(SkCreateNullCanvas()); 208 canvas = skia::AdoptRef(SkCreateNullCanvas());
208 graphics_context_status = ContentLayerClient::GRAPHICS_CONTEXT_DISABLED; 209 painting_control = ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED;
210 break;
211 case RecordingSource::RECORD_WITH_CACHING_DISABLED:
212 // This mode should give the same results as RECORD_NORMALLY.
213 painting_control = ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED;
209 break; 214 break;
210 default: 215 default:
211 NOTREACHED(); 216 NOTREACHED();
212 } 217 }
213 218
214 canvas->save(); 219 canvas->save();
215 canvas->translate(SkFloatToScalar(-layer_rect_.x()), 220 canvas->translate(SkFloatToScalar(-layer_rect_.x()),
216 SkFloatToScalar(-layer_rect_.y())); 221 SkFloatToScalar(-layer_rect_.y()));
217 222
218 SkRect layer_skrect = SkRect::MakeXYWH(layer_rect_.x(), 223 SkRect layer_skrect = SkRect::MakeXYWH(layer_rect_.x(),
219 layer_rect_.y(), 224 layer_rect_.y(),
220 layer_rect_.width(), 225 layer_rect_.width(),
221 layer_rect_.height()); 226 layer_rect_.height());
222 canvas->clipRect(layer_skrect); 227 canvas->clipRect(layer_skrect);
223 228
224 painter->PaintContents(canvas.get(), layer_rect_, graphics_context_status); 229 painter->PaintContents(canvas.get(), layer_rect_, painting_control);
225 230
226 canvas->restore(); 231 canvas->restore();
227 picture_ = skia::AdoptRef(recorder.endRecording()); 232 picture_ = skia::AdoptRef(recorder.endRecording());
228 DCHECK(picture_); 233 DCHECK(picture_);
229 234
230 EmitTraceSnapshot(); 235 EmitTraceSnapshot();
231 } 236 }
232 237
233 void Picture::GatherPixelRefs(const gfx::Size& tile_grid_size) { 238 void Picture::GatherPixelRefs(const gfx::Size& tile_grid_size) {
234 TRACE_EVENT2("cc", "Picture::GatherPixelRefs", 239 TRACE_EVENT2("cc", "Picture::GatherPixelRefs",
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 scoped_refptr<base::debug::ConvertableToTraceFormat> 473 scoped_refptr<base::debug::ConvertableToTraceFormat>
469 Picture::AsTraceableRecordData() const { 474 Picture::AsTraceableRecordData() const {
470 scoped_refptr<base::debug::TracedValue> record_data = 475 scoped_refptr<base::debug::TracedValue> record_data =
471 new base::debug::TracedValue(); 476 new base::debug::TracedValue();
472 TracedValue::SetIDRef(this, record_data.get(), "picture_id"); 477 TracedValue::SetIDRef(this, record_data.get(), "picture_id");
473 MathUtil::AddToTracedValue("layer_rect", layer_rect_, record_data.get()); 478 MathUtil::AddToTracedValue("layer_rect", layer_rect_, record_data.get());
474 return record_data; 479 return record_data;
475 } 480 }
476 481
477 } // namespace cc 482 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/picture.h ('k') | cc/resources/picture_layer_tiling.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698