aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrPreFlushResourceProvider.cpp
blob: 01d948a3b07985762f6db0133eeed124b4060539 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * 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 "GrPreFlushResourceProvider.h"

#include "GrDrawingManager.h"
#include "GrSurfaceProxy.h"

sk_sp<GrRenderTargetContext> GrPreFlushResourceProvider::makeRenderTargetContext(
                                                        const GrSurfaceDesc& desc,
                                                        sk_sp<SkColorSpace> colorSpace,
                                                        const SkSurfaceProps* props) {
    GrSurfaceDesc tmpDesc = desc;
    tmpDesc.fFlags |= kRenderTarget_GrSurfaceFlag;

    // Because this is being allocated at the start of a flush we must ensure the proxy
    // will, when instantiated, have no pending IO.
    // TODO: fold the kNoPendingIO_Flag into GrSurfaceFlags?
    sk_sp<GrSurfaceProxy> proxy = GrSurfaceProxy::MakeDeferred(
                                                    fDrawingMgr->getContext()->resourceProvider(),
                                                    tmpDesc,
                                                    SkBackingFit::kExact,
                                                    SkBudgeted::kYes,
                                                    GrResourceProvider::kNoPendingIO_Flag);
    if (!proxy->asRenderTargetProxy()) {
        return nullptr;
    }

    // MDB TODO: This explicit resource creation is required in the pre-MDB world so that the
    // pre-Flush ops are placed in their own opList.
    sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList(
                                                    sk_ref_sp(proxy->asRenderTargetProxy()),
                                                    fDrawingMgr->fContext->getGpu(),
                                                    fDrawingMgr->fContext->resourceProvider(),
                                                    fDrawingMgr->fContext->getAuditTrail()));
    proxy->setLastOpList(opList.get());

    sk_sp<GrRenderTargetContext> renderTargetContext(
        fDrawingMgr->makeRenderTargetContext(std::move(proxy),
                                             std::move(colorSpace),
                                             props));

    if (!renderTargetContext) {
        return nullptr;
    }

    renderTargetContext->discard();

    return renderTargetContext;
}

// TODO: we only need this entry point as long as we have to pre-allocate the atlas.
// Remove it ASAP.
sk_sp<GrRenderTargetContext> GrPreFlushResourceProvider::makeRenderTargetContext(
                                                        sk_sp<GrSurfaceProxy> proxy,
                                                        sk_sp<SkColorSpace> colorSpace,
                                                        const SkSurfaceProps* props) {
    // MDB TODO: This explicit resource creation is required in the pre-MDB world so that the
    // pre-Flush ops are placed in their own opList.
    sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList(
                                                    sk_ref_sp(proxy->asRenderTargetProxy()),
                                                    fDrawingMgr->fContext->getGpu(),
                                                    fDrawingMgr->fContext->resourceProvider(),
                                                    fDrawingMgr->fContext->getAuditTrail()));
    proxy->setLastOpList(opList.get());

    sk_sp<GrRenderTargetContext> renderTargetContext(
        fDrawingMgr->makeRenderTargetContext(std::move(proxy),
                                             std::move(colorSpace),
                                             props));

    if (!renderTargetContext) {
        return nullptr;
    }

    renderTargetContext->discard();

    return renderTargetContext;
}