blob: 1ae640c3e3c95cfe321b857de11bfedd3d64f00a [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();
Robert Phillipsa3457b82018-03-08 11:30:12 -050022 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
44protected:
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
61private:
62 typedef GrContext INHERITED;
63};
64
Kevin Lubickb5502b22018-03-12 10:17:06 -040065sk_sp<GrContext> GrContextPriv::MakeDDL(const sk_sp<GrContextThreadSafeProxy>& proxy) {
Robert Phillipsa3457b82018-03-08 11:30:12 -050066 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 Salomon52aacd62018-05-10 12:57:17 -040070 if (!context->init(proxy->priv().contextOptions())) {
Robert Phillipsa3457b82018-03-08 11:30:12 -050071 return nullptr;
72 }
73 return context;
74}