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 | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 12 | |
| 13 | /** |
| 14 | * The DDL Context is the one in effect during DDL Recording. It isn't backed by a GrGPU and |
| 15 | * cannot allocate any GPU resources. |
| 16 | */ |
| 17 | class SK_API GrDDLContext : public GrContext { |
| 18 | public: |
| 19 | GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy) |
Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 20 | : INHERITED(proxy->priv().backend(), proxy->priv().contextUniqueID()) { |
| 21 | fCaps = proxy->priv().refCaps(); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 22 | fThreadSafeProxy = std::move(proxy); |
| 23 | } |
| 24 | |
| 25 | ~GrDDLContext() override { |
| 26 | // The GrDDLContext doesn't actually own the fRestrictedAtlasManager so don't delete it |
| 27 | } |
| 28 | |
| 29 | void abandonContext() override { |
| 30 | SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense |
| 31 | INHERITED::abandonContext(); |
| 32 | } |
| 33 | |
| 34 | void releaseResourcesAndAbandonContext() override { |
| 35 | SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense |
| 36 | INHERITED::releaseResourcesAndAbandonContext(); |
| 37 | } |
| 38 | |
| 39 | void freeGpuResources() override { |
| 40 | SkASSERT(0); // freeing resources in a DDL Recorder doesn't make a whole lot of sense |
| 41 | INHERITED::freeGpuResources(); |
| 42 | } |
| 43 | |
| 44 | protected: |
| 45 | bool init(const GrContextOptions& options) override { |
| 46 | SkASSERT(fCaps); // should've been set in ctor |
| 47 | SkASSERT(fThreadSafeProxy); // should've been set in the ctor |
| 48 | |
| 49 | if (!INHERITED::initCommon(options)) { |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | return true; |
| 54 | } |
| 55 | |
| 56 | GrAtlasManager* onGetAtlasManager() override { |
| 57 | SkASSERT(0); // the DDL Recorders should never invoke this |
| 58 | return nullptr; |
| 59 | } |
| 60 | |
| 61 | private: |
| 62 | typedef GrContext INHERITED; |
| 63 | }; |
| 64 | |
Kevin Lubick | b5502b2 | 2018-03-12 10:17:06 -0400 | [diff] [blame] | 65 | sk_sp<GrContext> GrContextPriv::MakeDDL(const sk_sp<GrContextThreadSafeProxy>& proxy) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 66 | sk_sp<GrContext> context(new GrDDLContext(proxy)); |
| 67 | |
| 68 | // Note: we aren't creating a Gpu here. This causes the resource provider & cache to |
| 69 | // also not be created |
Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 70 | if (!context->init(proxy->priv().contextOptions())) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 71 | return nullptr; |
| 72 | } |
| 73 | return context; |
| 74 | } |