1 /*
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 "GrPreFlushResourceProvider.h"
9 
10 #include "GrDrawingManager.h"
11 #include "GrSurfaceProxy.h"
12 
makeRenderTargetContext(const GrSurfaceDesc & desc,sk_sp<SkColorSpace> colorSpace,const SkSurfaceProps * props)13 sk_sp<GrRenderTargetContext> GrPreFlushResourceProvider::makeRenderTargetContext(
14                                                         const GrSurfaceDesc& desc,
15                                                         sk_sp<SkColorSpace> colorSpace,
16                                                         const SkSurfaceProps* props) {
17     GrSurfaceDesc tmpDesc = desc;
18     tmpDesc.fFlags |= kRenderTarget_GrSurfaceFlag;
19 
20     // Because this is being allocated at the start of a flush we must ensure the proxy
21     // will, when instantiated, have no pending IO.
22     // TODO: fold the kNoPendingIO_Flag into GrSurfaceFlags?
23     sk_sp<GrSurfaceProxy> proxy = GrSurfaceProxy::MakeDeferred(
24                                                     fDrawingMgr->getContext()->resourceProvider(),
25                                                     tmpDesc,
26                                                     SkBackingFit::kExact,
27                                                     SkBudgeted::kYes,
28                                                     GrResourceProvider::kNoPendingIO_Flag);
29     if (!proxy->asRenderTargetProxy()) {
30         return nullptr;
31     }
32 
33     sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList(
34                                                     proxy->asRenderTargetProxy(),
35                                                     fDrawingMgr->fContext->getGpu(),
36                                                     fDrawingMgr->fContext->resourceProvider(),
37                                                     fDrawingMgr->fContext->getAuditTrail(),
38                                                     fDrawingMgr->fOptionsForOpLists));
39     proxy->setLastOpList(opList.get());
40 
41     return fDrawingMgr->makeRenderTargetContext(std::move(proxy),
42                                                 std::move(colorSpace),
43                                                 props);
44 }
45 
46 // TODO: we only need this entry point as long as we have to pre-allocate the atlas.
47 // Remove it ASAP.
makeRenderTargetContext(sk_sp<GrSurfaceProxy> proxy,sk_sp<SkColorSpace> colorSpace,const SkSurfaceProps * props)48 sk_sp<GrRenderTargetContext> GrPreFlushResourceProvider::makeRenderTargetContext(
49                                                         sk_sp<GrSurfaceProxy> proxy,
50                                                         sk_sp<SkColorSpace> colorSpace,
51                                                         const SkSurfaceProps* props) {
52 
53     sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList(
54                                                     proxy->asRenderTargetProxy(),
55                                                     fDrawingMgr->fContext->getGpu(),
56                                                     fDrawingMgr->fContext->resourceProvider(),
57                                                     fDrawingMgr->fContext->getAuditTrail(),
58                                                     fDrawingMgr->fOptionsForOpLists));
59     proxy->setLastOpList(opList.get());
60 
61     return fDrawingMgr->makeRenderTargetContext(std::move(proxy),
62                                                 std::move(colorSpace),
63                                                 props);
64 }
65 
66