Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 1 | /* |
| 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 Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 10 | #include "GrCaps.h" |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame^] | 11 | #include "GrDrawingManager.h" |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 12 | #include "GrMemoryPool.h" |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame^] | 13 | #include "GrProxyProvider.h" |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 14 | #include "GrRecordingContextPriv.h" |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame^] | 15 | #include "GrRenderTargetContext.h" |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 16 | #include "GrSkSLFPFactoryCache.h" |
| 17 | |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 18 | GrRecordingContext::GrRecordingContext(GrBackendApi backend, |
| 19 | const GrContextOptions& options, |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 20 | uint32_t contextID) |
| 21 | : INHERITED(backend, options, contextID) { |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | GrRecordingContext::~GrRecordingContext() { } |
| 25 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 26 | void GrRecordingContext::abandonContext() { |
| 27 | INHERITED::abandonContext(); |
| 28 | } |
| 29 | |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 30 | sk_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 | |
| 42 | GrOpMemoryPool* GrRecordingContext::opMemoryPool() { |
| 43 | return this->refOpMemoryPool().get(); |
| 44 | } |
| 45 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame^] | 46 | sk_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 Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 93 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 94 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 95 | sk_sp<const GrCaps> GrRecordingContextPriv::refCaps() const { |
| 96 | return fContext->refCaps(); |
| 97 | } |
| 98 | |
| 99 | sk_sp<GrSkSLFPFactoryCache> GrRecordingContextPriv::fpFactoryCache() { |
| 100 | return fContext->fpFactoryCache(); |
| 101 | } |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 102 | |
| 103 | sk_sp<GrOpMemoryPool> GrRecordingContextPriv::refOpMemoryPool() { |
| 104 | return fContext->refOpMemoryPool(); |
| 105 | } |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame^] | 106 | |
| 107 | sk_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 | } |