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