| 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, | 18 RecordPaintCanvas::RecordPaintCanvas(PaintOpBuffer* buffer) : buffer_(buffer) { |
| 19 const SkRect& bounds) | |
| 20 : buffer_(buffer), recording_bounds_(bounds) { | |
| 21 DCHECK(buffer_); | 19 DCHECK(buffer_); |
| 22 } | 20 } |
| 23 | 21 |
| 24 RecordPaintCanvas::~RecordPaintCanvas() = default; | 22 RecordPaintCanvas::~RecordPaintCanvas() = default; |
| 25 | 23 |
| 26 SkMetaData& RecordPaintCanvas::getMetaData() { | 24 SkMetaData& RecordPaintCanvas::getMetaData() { |
| 27 // This could just be SkMetaData owned by RecordPaintCanvas, but since | 25 // This could just be SkMetaData owned by RecordPaintCanvas, but since |
| 28 // SkCanvas already has one, we might as well use it directly. | 26 // SkCanvas already has one, we might as well use it directly. |
| 29 return GetCanvas()->getMetaData(); | 27 return GetCanvas()->getMetaData(); |
| 30 } | 28 } |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 } | 345 } |
| 348 | 346 |
| 349 const SkNoDrawCanvas* RecordPaintCanvas::GetCanvas() const { | 347 const SkNoDrawCanvas* RecordPaintCanvas::GetCanvas() const { |
| 350 return const_cast<RecordPaintCanvas*>(this)->GetCanvas(); | 348 return const_cast<RecordPaintCanvas*>(this)->GetCanvas(); |
| 351 } | 349 } |
| 352 | 350 |
| 353 SkNoDrawCanvas* RecordPaintCanvas::GetCanvas() { | 351 SkNoDrawCanvas* RecordPaintCanvas::GetCanvas() { |
| 354 if (canvas_) | 352 if (canvas_) |
| 355 return &*canvas_; | 353 return &*canvas_; |
| 356 | 354 |
| 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 recording_bounds_ makes a canvas of size (width x height) instead | 366 // with the cull_rect 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 |