1/*
2 * Copyright 2019 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#ifndef GrImageContext_DEFINED
9#define GrImageContext_DEFINED
10
11#include "include/private/GrContext_Base.h"
12#include "include/private/GrSingleOwner.h"
13
14class GrImageContextPriv;
15
16// This is now just a view on a ThreadSafeProxy, that SkImages can attempt to
17// downcast to a GrDirectContext as a backdoor to some operations. Once we remove the backdoors,
18// this goes away and SkImages just hold ThreadSafeProxies.
19class GrImageContext : public GrContext_Base {
20public:
21    ~GrImageContext() override;
22
23    // Provides access to functions that aren't part of the public API.
24    GrImageContextPriv priv();
25    const GrImageContextPriv priv() const;  // NOLINT(readability-const-return-type)
26
27protected:
28    friend class GrImageContextPriv; // for hidden functions
29
30    GrImageContext(sk_sp<GrContextThreadSafeProxy>);
31
32    SK_API virtual void abandonContext();
33    SK_API virtual bool abandoned();
34
35    /** This is only useful for debug purposes */
36    GrSingleOwner* singleOwner() const { return &fSingleOwner; }
37
38    GrImageContext* asImageContext() override { return this; }
39
40private:
41    // When making promise images, we currently need a placeholder GrImageContext instance to give
42    // to the SkImage that has no real power, just a wrapper around the ThreadSafeProxy.
43    // TODO: De-power SkImage to ThreadSafeProxy or at least figure out a way to share one instance.
44    static sk_sp<GrImageContext> MakeForPromiseImage(sk_sp<GrContextThreadSafeProxy>);
45
46    // In debug builds we guard against improper thread handling
47    // This guard is passed to the GrDrawingManager and, from there to all the
48    // GrSurfaceDrawContexts.  It is also passed to the GrResourceProvider and SkGpuDevice.
49    // TODO: Move this down to GrRecordingContext.
50    mutable GrSingleOwner            fSingleOwner;
51
52    using INHERITED = GrContext_Base;
53};
54
55#endif
56