OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/paint/record_paint_canvas.h" | 5 #include "cc/paint/record_paint_canvas.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "cc/paint/display_item_list.h" | 8 #include "cc/paint/display_item_list.h" |
9 #include "cc/paint/paint_op_buffer.h" | 9 #include "cc/paint/paint_op_buffer.h" |
10 #include "cc/paint/paint_record.h" | 10 #include "cc/paint/paint_record.h" |
11 #include "cc/paint/paint_recorder.h" | 11 #include "cc/paint/paint_recorder.h" |
12 #include "third_party/skia/include/core/SkAnnotation.h" | 12 #include "third_party/skia/include/core/SkAnnotation.h" |
13 #include "third_party/skia/include/core/SkMetaData.h" | 13 #include "third_party/skia/include/core/SkMetaData.h" |
14 #include "third_party/skia/include/utils/SkNWayCanvas.h" | 14 #include "third_party/skia/include/utils/SkNWayCanvas.h" |
15 | 15 |
16 namespace cc { | 16 namespace cc { |
17 | 17 |
18 RecordPaintCanvas::RecordPaintCanvas(PaintOpBuffer* buffer) : buffer_(buffer) { | 18 RecordPaintCanvas::RecordPaintCanvas(PaintOpBuffer* buffer, |
| 19 const SkRect& bounds) |
| 20 : buffer_(buffer), recording_bounds_(bounds) { |
19 DCHECK(buffer_); | 21 DCHECK(buffer_); |
20 } | 22 } |
21 | 23 |
22 RecordPaintCanvas::~RecordPaintCanvas() = default; | 24 RecordPaintCanvas::~RecordPaintCanvas() = default; |
23 | 25 |
24 SkMetaData& RecordPaintCanvas::getMetaData() { | 26 SkMetaData& RecordPaintCanvas::getMetaData() { |
25 // This could just be SkMetaData owned by RecordPaintCanvas, but since | 27 // This could just be SkMetaData owned by RecordPaintCanvas, but since |
26 // SkCanvas already has one, we might as well use it directly. | 28 // SkCanvas already has one, we might as well use it directly. |
27 return GetCanvas()->getMetaData(); | 29 return GetCanvas()->getMetaData(); |
28 } | 30 } |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } | 347 } |
346 | 348 |
347 const SkNoDrawCanvas* RecordPaintCanvas::GetCanvas() const { | 349 const SkNoDrawCanvas* RecordPaintCanvas::GetCanvas() const { |
348 return const_cast<RecordPaintCanvas*>(this)->GetCanvas(); | 350 return const_cast<RecordPaintCanvas*>(this)->GetCanvas(); |
349 } | 351 } |
350 | 352 |
351 SkNoDrawCanvas* RecordPaintCanvas::GetCanvas() { | 353 SkNoDrawCanvas* RecordPaintCanvas::GetCanvas() { |
352 if (canvas_) | 354 if (canvas_) |
353 return &*canvas_; | 355 return &*canvas_; |
354 | 356 |
355 SkRect recording_bounds = buffer_->cullRect(); | |
356 | |
357 // Size the canvas to be large enough to contain the |recording_bounds|, which | 357 // Size the canvas to be large enough to contain the |recording_bounds|, which |
358 // may not be positioned at th origin. | 358 // may not be positioned at th origin. |
359 SkIRect enclosing_rect = recording_bounds.roundOut(); | 359 SkIRect enclosing_rect = recording_bounds_.roundOut(); |
360 canvas_.emplace(enclosing_rect.right(), enclosing_rect.bottom()); | 360 canvas_.emplace(enclosing_rect.right(), enclosing_rect.bottom()); |
361 | 361 |
362 // This is part of the "recording canvases have a size, but why" dance. | 362 // This is part of the "recording canvases have a size, but why" dance. |
363 // By creating a canvas of size (right x bottom) and then clipping it, | 363 // By creating a canvas of size (right x bottom) and then clipping it, |
364 // It makes getDeviceClipBounds return the original cull rect, which code | 364 // It makes getDeviceClipBounds return the original cull rect, which code |
365 // in GraphicsContextCanvas on Mac expects. (Just creating an SkNoDrawCanvas | 365 // in GraphicsContextCanvas on Mac expects. (Just creating an SkNoDrawCanvas |
366 // with the cull_rect makes a canvas of size (width x height) instead | 366 // with the recording_bounds_ makes a canvas of size (width x height) instead |
367 // which is incorrect. SkRecorder cheats with private resetForNextCanvas. | 367 // which is incorrect. SkRecorder cheats with private resetForNextCanvas. |
368 canvas_->clipRect(recording_bounds, SkClipOp::kIntersect, false); | 368 canvas_->clipRect(recording_bounds_, SkClipOp::kIntersect, false); |
369 return &*canvas_; | 369 return &*canvas_; |
370 } | 370 } |
371 | 371 |
372 } // namespace cc | 372 } // namespace cc |
OLD | NEW |