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

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

Issue 862133002: Update from https://crrev.com/312398 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
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
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/debug/trace_event.h" 12 #include "base/debug/trace_event.h"
13 #include "base/debug/trace_event_argument.h" 13 #include "base/debug/trace_event_argument.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "cc/base/math_util.h" 15 #include "cc/base/math_util.h"
16 #include "cc/base/util.h" 16 #include "cc/base/util.h"
17 #include "cc/debug/picture_debug_util.h" 17 #include "cc/debug/picture_debug_util.h"
18 #include "cc/debug/traced_picture.h" 18 #include "cc/debug/traced_picture.h"
19 #include "cc/debug/traced_value.h" 19 #include "cc/debug/traced_value.h"
20 #include "cc/layers/content_layer_client.h" 20 #include "cc/layers/content_layer_client.h"
21 #include "skia/ext/pixel_ref_utils.h" 21 #include "skia/ext/pixel_ref_utils.h"
22 #include "third_party/skia/include/core/SkBBHFactory.h"
23 #include "third_party/skia/include/core/SkCanvas.h" 22 #include "third_party/skia/include/core/SkCanvas.h"
24 #include "third_party/skia/include/core/SkDrawPictureCallback.h" 23 #include "third_party/skia/include/core/SkDrawPictureCallback.h"
25 #include "third_party/skia/include/core/SkPaint.h" 24 #include "third_party/skia/include/core/SkPaint.h"
26 #include "third_party/skia/include/core/SkPictureRecorder.h" 25 #include "third_party/skia/include/core/SkPictureRecorder.h"
27 #include "third_party/skia/include/core/SkStream.h" 26 #include "third_party/skia/include/core/SkStream.h"
28 #include "third_party/skia/include/utils/SkNullCanvas.h" 27 #include "third_party/skia/include/utils/SkNullCanvas.h"
29 #include "third_party/skia/include/utils/SkPictureUtils.h" 28 #include "third_party/skia/include/utils/SkPictureUtils.h"
30 #include "ui/gfx/codec/jpeg_codec.h" 29 #include "ui/gfx/codec/jpeg_codec.h"
31 #include "ui/gfx/codec/png_codec.h" 30 #include "ui/gfx/codec/png_codec.h"
32 #include "ui/gfx/geometry/rect_conversions.h" 31 #include "ui/gfx/geometry/rect_conversions.h"
(...skipping 14 matching lines...) Expand all
47 scoped_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodec::Decode(data, size)); 46 scoped_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodec::Decode(data, size));
48 if (decoded_jpeg) { 47 if (decoded_jpeg) {
49 *bm = *decoded_jpeg; 48 *bm = *decoded_jpeg;
50 return true; 49 return true;
51 } 50 }
52 return false; 51 return false;
53 } 52 }
54 53
55 } // namespace 54 } // namespace
56 55
57 scoped_refptr<Picture> Picture::Create( 56 scoped_refptr<Picture> Picture::Create(const gfx::Rect& layer_rect,
58 const gfx::Rect& layer_rect, 57 ContentLayerClient* client,
59 ContentLayerClient* client, 58 const gfx::Size& tile_grid_size,
60 const SkTileGridFactory::TileGridInfo& tile_grid_info, 59 bool gather_pixel_refs,
61 bool gather_pixel_refs, 60 RecordingMode recording_mode) {
62 RecordingMode recording_mode) {
63 scoped_refptr<Picture> picture = make_scoped_refptr(new Picture(layer_rect)); 61 scoped_refptr<Picture> picture = make_scoped_refptr(new Picture(layer_rect));
64 62
65 picture->Record(client, tile_grid_info, recording_mode); 63 picture->Record(client, tile_grid_size, recording_mode);
66 if (gather_pixel_refs) 64 if (gather_pixel_refs)
67 picture->GatherPixelRefs(tile_grid_info); 65 picture->GatherPixelRefs(tile_grid_size);
68 66
69 return picture; 67 return picture;
70 } 68 }
71 69
72 Picture::Picture(const gfx::Rect& layer_rect) 70 Picture::Picture(const gfx::Rect& layer_rect)
73 : layer_rect_(layer_rect), 71 : layer_rect_(layer_rect),
74 cell_size_(layer_rect.size()) { 72 cell_size_(layer_rect.size()) {
75 // Instead of recording a trace event for object creation here, we wait for 73 // Instead of recording a trace event for object creation here, we wait for
76 // the picture to be recorded in Picture::Record. 74 // the picture to be recorded in Picture::Record.
77 } 75 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 DCHECK(picture_); 161 DCHECK(picture_);
164 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); 162 return SkPictureUtils::ApproximateBytesUsed(picture_.get());
165 } 163 }
166 164
167 bool Picture::HasText() const { 165 bool Picture::HasText() const {
168 DCHECK(picture_); 166 DCHECK(picture_);
169 return picture_->hasText(); 167 return picture_->hasText();
170 } 168 }
171 169
172 void Picture::Record(ContentLayerClient* painter, 170 void Picture::Record(ContentLayerClient* painter,
173 const SkTileGridFactory::TileGridInfo& tile_grid_info, 171 const gfx::Size& tile_grid_size,
174 RecordingMode recording_mode) { 172 RecordingMode recording_mode) {
175 TRACE_EVENT2("cc", 173 TRACE_EVENT2("cc",
176 "Picture::Record", 174 "Picture::Record",
177 "data", 175 "data",
178 AsTraceableRecordData(), 176 AsTraceableRecordData(),
179 "recording_mode", 177 "recording_mode",
180 recording_mode); 178 recording_mode);
181 179
182 DCHECK(!picture_); 180 DCHECK(!picture_);
183 DCHECK(!tile_grid_info.fTileInterval.isEmpty()); 181 DCHECK(!tile_grid_size.IsEmpty());
184 182
185 // TODO(mtklein): If SkRTree sticks, clean up tile_grid_info. skbug.com/3085 183 // TODO(mtklein): If SkRTree sticks, clean up tile_grid_info. skbug.com/3085
186 SkRTreeFactory factory; 184 SkRTreeFactory factory;
187 SkPictureRecorder recorder; 185 SkPictureRecorder recorder;
188 186
189 skia::RefPtr<SkCanvas> canvas; 187 skia::RefPtr<SkCanvas> canvas;
190 canvas = skia::SharePtr(recorder.beginRecording( 188 canvas = skia::SharePtr(recorder.beginRecording(
191 layer_rect_.width(), layer_rect_.height(), &factory, 189 layer_rect_.width(), layer_rect_.height(), &factory,
192 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)); 190 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag));
193 191
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 223
226 painter->PaintContents(canvas.get(), layer_rect_, graphics_context_status); 224 painter->PaintContents(canvas.get(), layer_rect_, graphics_context_status);
227 225
228 canvas->restore(); 226 canvas->restore();
229 picture_ = skia::AdoptRef(recorder.endRecording()); 227 picture_ = skia::AdoptRef(recorder.endRecording());
230 DCHECK(picture_); 228 DCHECK(picture_);
231 229
232 EmitTraceSnapshot(); 230 EmitTraceSnapshot();
233 } 231 }
234 232
235 void Picture::GatherPixelRefs( 233 void Picture::GatherPixelRefs(const gfx::Size& tile_grid_size) {
236 const SkTileGridFactory::TileGridInfo& tile_grid_info) {
237 TRACE_EVENT2("cc", "Picture::GatherPixelRefs", 234 TRACE_EVENT2("cc", "Picture::GatherPixelRefs",
238 "width", layer_rect_.width(), 235 "width", layer_rect_.width(),
239 "height", layer_rect_.height()); 236 "height", layer_rect_.height());
240 237
241 DCHECK(picture_); 238 DCHECK(picture_);
242 DCHECK(pixel_refs_.empty()); 239 DCHECK(pixel_refs_.empty());
243 if (!WillPlayBackBitmaps()) 240 if (!WillPlayBackBitmaps())
244 return; 241 return;
245 cell_size_ = gfx::Size( 242 cell_size_ = tile_grid_size;
246 tile_grid_info.fTileInterval.width() +
247 2 * tile_grid_info.fMargin.width(),
248 tile_grid_info.fTileInterval.height() +
249 2 * tile_grid_info.fMargin.height());
250 DCHECK_GT(cell_size_.width(), 0); 243 DCHECK_GT(cell_size_.width(), 0);
251 DCHECK_GT(cell_size_.height(), 0); 244 DCHECK_GT(cell_size_.height(), 0);
252 245
253 int min_x = std::numeric_limits<int>::max(); 246 int min_x = std::numeric_limits<int>::max();
254 int min_y = std::numeric_limits<int>::max(); 247 int min_y = std::numeric_limits<int>::max();
255 int max_x = 0; 248 int max_x = 0;
256 int max_y = 0; 249 int max_y = 0;
257 250
258 skia::DiscardablePixelRefList pixel_refs; 251 skia::DiscardablePixelRefList pixel_refs;
259 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture_.get(), &pixel_refs); 252 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture_.get(), &pixel_refs);
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 TracedValue::SetIDRef(this, raster_data.get(), "picture_id"); 463 TracedValue::SetIDRef(this, raster_data.get(), "picture_id");
471 raster_data->SetDouble("scale", scale); 464 raster_data->SetDouble("scale", scale);
472 return raster_data; 465 return raster_data;
473 } 466 }
474 467
475 scoped_refptr<base::debug::ConvertableToTraceFormat> 468 scoped_refptr<base::debug::ConvertableToTraceFormat>
476 Picture::AsTraceableRecordData() const { 469 Picture::AsTraceableRecordData() const {
477 scoped_refptr<base::debug::TracedValue> record_data = 470 scoped_refptr<base::debug::TracedValue> record_data =
478 new base::debug::TracedValue(); 471 new base::debug::TracedValue();
479 TracedValue::SetIDRef(this, record_data.get(), "picture_id"); 472 TracedValue::SetIDRef(this, record_data.get(), "picture_id");
480 record_data->BeginArray("layer_rect"); 473 MathUtil::AddToTracedValue("layer_rect", layer_rect_, record_data.get());
481 MathUtil::AddToTracedValue(layer_rect_, record_data.get());
482 record_data->EndArray();
483 return record_data; 474 return record_data;
484 } 475 }
485 476
486 } // namespace cc 477 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/picture.h ('k') | cc/resources/picture_layer_tiling.cc » ('j') | shell/BUILD.gn » ('J')

Powered by Google App Engine
This is Rietveld 408576698