| 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 |  | 
|  | 8 | #include "GrContext.h" | 
| Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 9 | #include "GrCaps.h" | 
| Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 10 | #include "GrContextPriv.h" | 
| Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 11 | #include "GrContextThreadSafeProxyPriv.h" | 
| Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 12 | #include "GrSkSLFPFactoryCache.h" | 
| Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 13 |  | 
|  | 14 | /** | 
|  | 15 | * The DDL Context is the one in effect during DDL Recording. It isn't backed by a GrGPU and | 
|  | 16 | * cannot allocate any GPU resources. | 
|  | 17 | */ | 
|  | 18 | class SK_API GrDDLContext : public GrContext { | 
|  | 19 | public: | 
|  | 20 | GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy) | 
| Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 21 | : INHERITED(proxy->backend(), proxy->priv().options(), proxy->priv().contextID()) { | 
| Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 22 | fThreadSafeProxy = std::move(proxy); | 
|  | 23 | } | 
|  | 24 |  | 
| Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 25 | ~GrDDLContext() override { } | 
| Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 26 |  | 
|  | 27 | void abandonContext() override { | 
|  | 28 | SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense | 
|  | 29 | INHERITED::abandonContext(); | 
|  | 30 | } | 
|  | 31 |  | 
|  | 32 | void releaseResourcesAndAbandonContext() override { | 
|  | 33 | SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense | 
|  | 34 | INHERITED::releaseResourcesAndAbandonContext(); | 
|  | 35 | } | 
|  | 36 |  | 
|  | 37 | void freeGpuResources() override { | 
|  | 38 | SkASSERT(0); // freeing resources in a DDL Recorder doesn't make a whole lot of sense | 
|  | 39 | INHERITED::freeGpuResources(); | 
|  | 40 | } | 
|  | 41 |  | 
|  | 42 | protected: | 
| Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 43 | // TODO: Here we're pretending this isn't derived from GrContext. Switch this to be derived from | 
|  | 44 | // GrRecordingContext! | 
|  | 45 | GrContext* asDirectContext() override { return nullptr; } | 
|  | 46 |  | 
| Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 47 | bool init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) override { | 
|  | 48 | SkASSERT(caps && FPFactoryCache); | 
| Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 49 | SkASSERT(fThreadSafeProxy); // should've been set in the ctor | 
|  | 50 |  | 
| Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 51 | if (!INHERITED::init(std::move(caps), std::move(FPFactoryCache))) { | 
| Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 52 | return false; | 
|  | 53 | } | 
|  | 54 |  | 
| Robert Phillips | 60dd62b | 2019-03-12 16:28:59 +0000 | [diff] [blame^] | 55 | // DDL contexts/drawing managers always sort the oplists. This, in turn, implies that | 
|  | 56 | // explicit resource allocation is always on (regardless of how Skia is compiled). | 
|  | 57 | this->setupDrawingManager(true, true); | 
| Robert Phillips | 56181ba | 2019-03-08 12:00:45 -0500 | [diff] [blame] | 58 |  | 
| Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 59 | SkASSERT(this->caps()); | 
|  | 60 |  | 
| Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 61 | return true; | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | GrAtlasManager* onGetAtlasManager() override { | 
|  | 65 | SkASSERT(0);   // the DDL Recorders should never invoke this | 
|  | 66 | return nullptr; | 
|  | 67 | } | 
|  | 68 |  | 
|  | 69 | private: | 
|  | 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 | } |