Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/gpu/GrContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "src/gpu/GrCaps.h" |
| 10 | #include "src/gpu/GrContextPriv.h" |
| 11 | #include "src/gpu/GrContextThreadSafeProxyPriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrSkSLFPFactoryCache.h" |
Robert Phillips | 7f11fb5 | 2019-12-03 13:35:19 -0500 | [diff] [blame^] | 13 | #include "src/gpu/effects/GrSkSLFP.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 14 | |
| 15 | /** |
| 16 | * The DDL Context is the one in effect during DDL Recording. It isn't backed by a GrGPU and |
| 17 | * cannot allocate any GPU resources. |
| 18 | */ |
Jim Van Verth | 861ac61 | 2019-11-27 09:41:43 -0500 | [diff] [blame] | 19 | class GrDDLContext final : public GrContext { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 20 | public: |
| 21 | GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy) |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 22 | : INHERITED(proxy->backend(), proxy->priv().options(), proxy->priv().contextID()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 23 | fThreadSafeProxy = std::move(proxy); |
| 24 | } |
| 25 | |
Brian Salomon | 161c8ed | 2019-11-27 09:12:47 -0500 | [diff] [blame] | 26 | ~GrDDLContext() override {} |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 27 | |
Brian Salomon | 161c8ed | 2019-11-27 09:12:47 -0500 | [diff] [blame] | 28 | void abandonContext() override { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 29 | SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense |
| 30 | INHERITED::abandonContext(); |
| 31 | } |
| 32 | |
Brian Salomon | 161c8ed | 2019-11-27 09:12:47 -0500 | [diff] [blame] | 33 | void releaseResourcesAndAbandonContext() override { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 34 | SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense |
| 35 | INHERITED::releaseResourcesAndAbandonContext(); |
| 36 | } |
| 37 | |
Brian Salomon | 161c8ed | 2019-11-27 09:12:47 -0500 | [diff] [blame] | 38 | void freeGpuResources() override { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 39 | SkASSERT(0); // freeing resources in a DDL Recorder doesn't make a whole lot of sense |
| 40 | INHERITED::freeGpuResources(); |
| 41 | } |
| 42 | |
Robert Phillips | 933484f | 2019-11-26 09:38:55 -0500 | [diff] [blame] | 43 | private: |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 44 | // TODO: Here we're pretending this isn't derived from GrContext. Switch this to be derived from |
| 45 | // GrRecordingContext! |
Brian Salomon | 161c8ed | 2019-11-27 09:12:47 -0500 | [diff] [blame] | 46 | GrContext* asDirectContext() override { return nullptr; } |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 47 | |
Brian Salomon | 161c8ed | 2019-11-27 09:12:47 -0500 | [diff] [blame] | 48 | bool init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) override { |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 49 | SkASSERT(caps && FPFactoryCache); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 50 | SkASSERT(fThreadSafeProxy); // should've been set in the ctor |
| 51 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 52 | if (!INHERITED::init(std::move(caps), std::move(FPFactoryCache))) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 53 | return false; |
| 54 | } |
| 55 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 56 | // DDL contexts/drawing managers always sort the oplists and attempt to reduce opsTask |
Robert Phillips | 6db27c2 | 2019-05-01 10:43:56 -0400 | [diff] [blame] | 57 | // splitting. |
| 58 | this->setupDrawingManager(true, true); |
Robert Phillips | 56181ba | 2019-03-08 12:00:45 -0500 | [diff] [blame] | 59 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 60 | SkASSERT(this->caps()); |
| 61 | |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 62 | return true; |
| 63 | } |
| 64 | |
Brian Salomon | 161c8ed | 2019-11-27 09:12:47 -0500 | [diff] [blame] | 65 | GrAtlasManager* onGetAtlasManager() override { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 66 | SkASSERT(0); // the DDL Recorders should never invoke this |
| 67 | return nullptr; |
| 68 | } |
| 69 | |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 70 | typedef GrContext INHERITED; |
| 71 | }; |
| 72 | |
Kevin Lubick | b5502b2 | 2018-03-12 10:17:06 -0400 | [diff] [blame] | 73 | sk_sp<GrContext> GrContextPriv::MakeDDL(const sk_sp<GrContextThreadSafeProxy>& proxy) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 74 | sk_sp<GrContext> context(new GrDDLContext(proxy)); |
| 75 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 76 | if (!context->init(proxy->priv().refCaps(), proxy->priv().fpFactoryCache())) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 77 | return nullptr; |
| 78 | } |
| 79 | return context; |
| 80 | } |