aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkDeferredDisplayListRecorder.cpp
blob: c47a79a77d9e3d744c4c444c4310bb1817df704d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkDeferredDisplayListRecorder.h"

#include "SkCanvas.h" // TODO: remove
#include "SkDeferredDisplayList.h"
#include "SkSurface.h" // TODO: remove

SkDeferredDisplayListRecorder::SkDeferredDisplayListRecorder(
                    const SkSurfaceCharacterization& characterization)
        : fCharacterization(characterization) {
}

SkCanvas* SkDeferredDisplayListRecorder::getCanvas() {
    if (!fSurface) {
        SkImageInfo ii = SkImageInfo::MakeN32(fCharacterization.width(),
                                              fCharacterization.height(),
                                              kOpaque_SkAlphaType);

        // Use raster right now to allow threading
        fSurface = SkSurface::MakeRaster(ii, nullptr);
    }

    return fSurface->getCanvas();
}

std::unique_ptr<SkDeferredDisplayList> SkDeferredDisplayListRecorder::detach() {
    sk_sp<SkImage> img = fSurface->makeImageSnapshot();
    fSurface.reset();

    // TODO: need to wrap the opLists associated with the deferred draws
    // in the SkDeferredDisplayList.
    return std::unique_ptr<SkDeferredDisplayList>(
                            new SkDeferredDisplayList(fCharacterization, std::move(img)));
}

// Placeholder. Ultimately, the SkSurface_Gpu will pass the wrapped opLists to its
// renderTargetContext.
void SkDeferredDisplayList::draw(SkSurface* surface) {
    surface->getCanvas()->drawImage(fImage.get(), 0, 0);
}