blob: 8b031f4e32745122c2be13aec5eea2d03269730d [file] [log] [blame]
Robert Phillipseb35f4d2017-03-21 07:56:47 -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
Chris Daltonfe199b72017-05-05 11:26:15 -04008#include "GrOnFlushResourceProvider.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -04009
10#include "GrDrawingManager.h"
11#include "GrSurfaceProxy.h"
12
Chris Daltonfe199b72017-05-05 11:26:15 -040013sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext(
Robert Phillipseb35f4d2017-03-21 07:56:47 -040014 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
Robert Phillips1119dc32017-04-11 12:54:57 -040033 sk_sp<GrRenderTargetContext> renderTargetContext(
34 fDrawingMgr->makeRenderTargetContext(std::move(proxy),
35 std::move(colorSpace),
36 props));
37
38 if (!renderTargetContext) {
39 return nullptr;
40 }
41
42 renderTargetContext->discard();
43
44 return renderTargetContext;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040045}
46
47// TODO: we only need this entry point as long as we have to pre-allocate the atlas.
48// Remove it ASAP.
Chris Daltonfe199b72017-05-05 11:26:15 -040049sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext(
Robert Phillipseb35f4d2017-03-21 07:56:47 -040050 sk_sp<GrSurfaceProxy> proxy,
51 sk_sp<SkColorSpace> colorSpace,
52 const SkSurfaceProps* props) {
Robert Phillips1119dc32017-04-11 12:54:57 -040053 sk_sp<GrRenderTargetContext> renderTargetContext(
54 fDrawingMgr->makeRenderTargetContext(std::move(proxy),
55 std::move(colorSpace),
56 props));
57
58 if (!renderTargetContext) {
59 return nullptr;
60 }
61
62 renderTargetContext->discard();
63
64 return renderTargetContext;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040065}
66