• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "GrOnFlushResourceProvider.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> GrOnFlushResourceProvider::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<GrRenderTargetContext> renderTargetContext(
34         fDrawingMgr->makeRenderTargetContext(std::move(proxy),
35                                              std::move(colorSpace),
36                                              props, false));
37 
38     if (!renderTargetContext) {
39         return nullptr;
40     }
41 
42     renderTargetContext->discard();
43 
44     return renderTargetContext;
45 }
46 
47 // TODO: we only need this entry point as long as we have to pre-allocate the atlas.
48 // Remove it ASAP.
makeRenderTargetContext(sk_sp<GrSurfaceProxy> proxy,sk_sp<SkColorSpace> colorSpace,const SkSurfaceProps * props)49 sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext(
50                                                         sk_sp<GrSurfaceProxy> proxy,
51                                                         sk_sp<SkColorSpace> colorSpace,
52                                                         const SkSurfaceProps* props) {
53     sk_sp<GrRenderTargetContext> renderTargetContext(
54         fDrawingMgr->makeRenderTargetContext(std::move(proxy),
55                                              std::move(colorSpace),
56                                              props, false));
57 
58     if (!renderTargetContext) {
59         return nullptr;
60     }
61 
62     renderTargetContext->discard();
63 
64     return renderTargetContext;
65 }
66 
makeBuffer(GrBufferType intendedType,size_t size,const void * data)67 sk_sp<GrBuffer> GrOnFlushResourceProvider::makeBuffer(GrBufferType intendedType, size_t size,
68                                                       const void* data) {
69     GrResourceProvider* rp = fDrawingMgr->getContext()->resourceProvider();
70     return sk_sp<GrBuffer>(rp->createBuffer(size, intendedType, kDynamic_GrAccessPattern,
71                                             GrResourceProvider::kNoPendingIO_Flag,
72                                             data));
73 }
74 
findOrMakeStaticBuffer(const GrUniqueKey & key,GrBufferType intendedType,size_t size,const void * data)75 sk_sp<GrBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer(const GrUniqueKey& key,
76                                                                   GrBufferType intendedType,
77                                                                   size_t size, const void* data) {
78     GrResourceProvider* rp = fDrawingMgr->getContext()->resourceProvider();
79     sk_sp<GrBuffer> buffer(rp->findAndRefTByUniqueKey<GrBuffer>(key));
80     if (!buffer) {
81         buffer.reset(rp->createBuffer(size, intendedType, kStatic_GrAccessPattern, 0, data));
82         if (!buffer) {
83             return nullptr;
84         }
85         SkASSERT(buffer->sizeInBytes() == size); // rp shouldn't bin and/or cache static buffers.
86         buffer->resourcePriv().setUniqueKey(key);
87     }
88     return buffer;
89 }
90 
caps() const91 const GrCaps* GrOnFlushResourceProvider::caps() const {
92     return fDrawingMgr->getContext()->caps();
93 }
94