blob: eb5ed29e6b26d3d2d1e81d6c8cf7d78b511c47e2 [file] [log] [blame]
Robert Phillipsa3457b82018-03-08 11:30:12 -05001/*
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 Salomonc7fe0f72018-05-11 10:14:21 -04009#include "GrCaps.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050010#include "GrContextPriv.h"
Brian Salomon52aacd62018-05-10 12:57:17 -040011#include "GrContextThreadSafeProxyPriv.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050012
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 */
17class SK_API GrDDLContext : public GrContext {
18public:
19 GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy)
Brian Salomon52aacd62018-05-10 12:57:17 -040020 : INHERITED(proxy->priv().backend(), proxy->priv().contextUniqueID()) {
21 fCaps = proxy->priv().refCaps();
Ethan Nicholas00543112018-07-31 09:44:36 -040022 fFPFactoryCache = proxy->priv().fpFactoryCache();
23 SkASSERT(fFPFactoryCache);
Robert Phillipsa3457b82018-03-08 11:30:12 -050024 fThreadSafeProxy = std::move(proxy);
25 }
26
27 ~GrDDLContext() override {
28 // The GrDDLContext doesn't actually own the fRestrictedAtlasManager so don't delete it
29 }
30
31 void abandonContext() override {
32 SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense
33 INHERITED::abandonContext();
34 }
35
36 void releaseResourcesAndAbandonContext() override {
37 SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense
38 INHERITED::releaseResourcesAndAbandonContext();
39 }
40
41 void freeGpuResources() override {
42 SkASSERT(0); // freeing resources in a DDL Recorder doesn't make a whole lot of sense
43 INHERITED::freeGpuResources();
44 }
45
46protected:
47 bool init(const GrContextOptions& options) override {
48 SkASSERT(fCaps); // should've been set in ctor
49 SkASSERT(fThreadSafeProxy); // should've been set in the ctor
50
51 if (!INHERITED::initCommon(options)) {
52 return false;
53 }
54
55 return true;
56 }
57
58 GrAtlasManager* onGetAtlasManager() override {
59 SkASSERT(0); // the DDL Recorders should never invoke this
60 return nullptr;
61 }
62
63private:
64 typedef GrContext INHERITED;
65};
66
Kevin Lubickb5502b22018-03-12 10:17:06 -040067sk_sp<GrContext> GrContextPriv::MakeDDL(const sk_sp<GrContextThreadSafeProxy>& proxy) {
Robert Phillipsa3457b82018-03-08 11:30:12 -050068 sk_sp<GrContext> context(new GrDDLContext(proxy));
69
70 // Note: we aren't creating a Gpu here. This causes the resource provider & cache to
71 // also not be created
Brian Salomon52aacd62018-05-10 12:57:17 -040072 if (!context->init(proxy->priv().contextOptions())) {
Robert Phillipsa3457b82018-03-08 11:30:12 -050073 return nullptr;
74 }
75 return context;
76}