blob: 12142c33de78b291a6f0414c268d64597e6c4e22 [file] [log] [blame]
Robert Phillips4217ea72019-01-30 13:08:28 -05001/*
2 * Copyright 2019 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 "GrRecordingContext.h"
9
Robert Phillipsa41c6852019-02-07 10:44:10 -050010#include "GrCaps.h"
Robert Phillipsb97da532019-02-12 15:24:12 -050011#include "GrDrawingManager.h"
Robert Phillipsd6841482019-02-08 10:29:20 -050012#include "GrMemoryPool.h"
Robert Phillipsb97da532019-02-12 15:24:12 -050013#include "GrProxyProvider.h"
Robert Phillipsa41c6852019-02-07 10:44:10 -050014#include "GrRecordingContextPriv.h"
Robert Phillipsb97da532019-02-12 15:24:12 -050015#include "GrRenderTargetContext.h"
Robert Phillipsa41c6852019-02-07 10:44:10 -050016#include "GrSkSLFPFactoryCache.h"
17
Robert Phillipsc1541ae2019-02-04 12:05:37 -050018GrRecordingContext::GrRecordingContext(GrBackendApi backend,
19 const GrContextOptions& options,
Robert Phillipsa41c6852019-02-07 10:44:10 -050020 uint32_t contextID)
21 : INHERITED(backend, options, contextID) {
Robert Phillips4217ea72019-01-30 13:08:28 -050022}
23
24GrRecordingContext::~GrRecordingContext() { }
25
Robert Phillipsa9162df2019-02-11 14:12:03 -050026void GrRecordingContext::abandonContext() {
27 INHERITED::abandonContext();
28}
29
Robert Phillipsd6841482019-02-08 10:29:20 -050030sk_sp<GrOpMemoryPool> GrRecordingContext::refOpMemoryPool() {
31 if (!fOpMemoryPool) {
32 // DDL TODO: should the size of the memory pool be decreased in DDL mode? CPU-side memory
33 // consumed in DDL mode vs. normal mode for a single skp might be a good metric of wasted
34 // memory.
35 fOpMemoryPool = sk_sp<GrOpMemoryPool>(new GrOpMemoryPool(16384, 16384));
36 }
37
38 SkASSERT(fOpMemoryPool);
39 return fOpMemoryPool;
40}
41
42GrOpMemoryPool* GrRecordingContext::opMemoryPool() {
43 return this->refOpMemoryPool().get();
44}
45
Robert Phillipsb97da532019-02-12 15:24:12 -050046sk_sp<GrRenderTargetContext> GrRecordingContext::makeDeferredRenderTargetContext(
47 const GrBackendFormat& format,
48 SkBackingFit fit,
49 int width, int height,
50 GrPixelConfig config,
51 sk_sp<SkColorSpace> colorSpace,
52 int sampleCnt,
53 GrMipMapped mipMapped,
54 GrSurfaceOrigin origin,
55 const SkSurfaceProps* surfaceProps,
56 SkBudgeted budgeted) {
57 SkASSERT(sampleCnt > 0);
58 if (this->abandoned()) {
59 return nullptr;
60 }
61
62 GrSurfaceDesc desc;
63 desc.fFlags = kRenderTarget_GrSurfaceFlag;
64 desc.fWidth = width;
65 desc.fHeight = height;
66 desc.fConfig = config;
67 desc.fSampleCnt = sampleCnt;
68
69 sk_sp<GrTextureProxy> rtp;
70 if (GrMipMapped::kNo == mipMapped) {
71 rtp = this->proxyProvider()->createProxy(format, desc, origin, fit, budgeted);
72 } else {
73 rtp = this->proxyProvider()->createMipMapProxy(format, desc, origin, budgeted);
74 }
75 if (!rtp) {
76 return nullptr;
77 }
78
79 // CONTEXT TODO: move GrDrawingManager to GrRecordingContext for real
80 auto drawingManager = this->drawingManager();
81
82 sk_sp<GrRenderTargetContext> renderTargetContext =
83 drawingManager->makeRenderTargetContext(std::move(rtp), std::move(colorSpace),
84 surfaceProps);
85 if (!renderTargetContext) {
86 return nullptr;
87 }
88
89 renderTargetContext->discard();
90
91 return renderTargetContext;
92}
Robert Phillipsd6841482019-02-08 10:29:20 -050093
Robert Phillipsa41c6852019-02-07 10:44:10 -050094///////////////////////////////////////////////////////////////////////////////////////////////////
95sk_sp<const GrCaps> GrRecordingContextPriv::refCaps() const {
96 return fContext->refCaps();
97}
98
99sk_sp<GrSkSLFPFactoryCache> GrRecordingContextPriv::fpFactoryCache() {
100 return fContext->fpFactoryCache();
101}
Robert Phillipsd6841482019-02-08 10:29:20 -0500102
103sk_sp<GrOpMemoryPool> GrRecordingContextPriv::refOpMemoryPool() {
104 return fContext->refOpMemoryPool();
105}
Robert Phillipsb97da532019-02-12 15:24:12 -0500106
107sk_sp<GrRenderTargetContext> GrRecordingContextPriv::makeDeferredRenderTargetContext(
108 const GrBackendFormat& format,
109 SkBackingFit fit,
110 int width, int height,
111 GrPixelConfig config,
112 sk_sp<SkColorSpace> colorSpace,
113 int sampleCnt,
114 GrMipMapped mipMapped,
115 GrSurfaceOrigin origin,
116 const SkSurfaceProps* surfaceProps,
117 SkBudgeted budgeted) {
118 return fContext->makeDeferredRenderTargetContext(format, fit, width, height, config,
119 std::move(colorSpace), sampleCnt, mipMapped,
120 origin, surfaceProps, budgeted);
121}