blob: c47a79a77d9e3d744c4c444c4310bb1817df704d [file] [log] [blame]
Robert Phillipsad8a43f2017-08-30 12:06:35 -04001/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkDeferredDisplayListRecorder.h"
9
10#include "SkCanvas.h" // TODO: remove
11#include "SkDeferredDisplayList.h"
12#include "SkSurface.h" // TODO: remove
13
14SkDeferredDisplayListRecorder::SkDeferredDisplayListRecorder(
15 const SkSurfaceCharacterization& characterization)
16 : fCharacterization(characterization) {
17}
18
19SkCanvas* SkDeferredDisplayListRecorder::getCanvas() {
20 if (!fSurface) {
21 SkImageInfo ii = SkImageInfo::MakeN32(fCharacterization.width(),
22 fCharacterization.height(),
23 kOpaque_SkAlphaType);
24
25 // Use raster right now to allow threading
26 fSurface = SkSurface::MakeRaster(ii, nullptr);
27 }
28
29 return fSurface->getCanvas();
30}
31
32std::unique_ptr<SkDeferredDisplayList> SkDeferredDisplayListRecorder::detach() {
33 sk_sp<SkImage> img = fSurface->makeImageSnapshot();
34 fSurface.reset();
35
36 // TODO: need to wrap the opLists associated with the deferred draws
37 // in the SkDeferredDisplayList.
38 return std::unique_ptr<SkDeferredDisplayList>(
39 new SkDeferredDisplayList(fCharacterization, std::move(img)));
40}
41
42// Placeholder. Ultimately, the SkSurface_Gpu will pass the wrapped opLists to its
43// renderTargetContext.
44void SkDeferredDisplayList::draw(SkSurface* surface) {
45 surface->getCanvas()->drawImage(fImage.get(), 0, 0);
46}