From 53cf44cfaf16a5dd67181cb7cbd3ff6d728c918c Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Tue, 13 Oct 2020 17:40:21 -0400 Subject: [PATCH] Migrate GrContextPriv & ivars to GrDirectContext After this, GrContextPriv gets renamed and GrContext gets removed. Change-Id: I49b034e4669876becb50b93c5fe3af887481e1ba Reviewed-on: https://skia-review.googlesource.com/c/skia/+/326158 Reviewed-by: Robert Phillips Reviewed-by: Brian Salomon Commit-Queue: Brian Salomon Auto-Submit: Adlai Holler --- include/gpu/GrDirectContext.h | 37 +++++++++++++++++++++++++++++-- include/private/GrContext.h | 41 ----------------------------------- src/gpu/GrContextPriv.h | 15 +++++++------ tools/fiddle/fiddle_main.cpp | 2 +- 4 files changed, 44 insertions(+), 51 deletions(-) diff --git a/include/gpu/GrDirectContext.h b/include/gpu/GrDirectContext.h index 170b065a9a..11048cb1b0 100644 --- a/include/gpu/GrDirectContext.h +++ b/include/gpu/GrDirectContext.h @@ -15,14 +15,22 @@ // We shouldn't need this but currently Android is relying on this being include transitively. #include "include/core/SkUnPreMultiply.h" +class GrAtlasManager; class GrBackendSemaphore; +class GrClientMappedBufferManager; +class GrContextPriv; class GrContextThreadSafeProxy; struct GrD3DBackendContext; class GrFragmentProcessor; +class GrGpu; struct GrGLInterface; struct GrMockOptions; class GrPath; +class GrResourceCache; +class GrSmallPathAtlasMgr; class GrRenderTargetContext; +class GrResourceProvider; +class GrStrikeCache; class GrSurfaceProxy; class GrSwizzle; class GrTextureProxy; @@ -32,6 +40,7 @@ class SkImage; class SkString; class SkSurfaceCharacterization; class SkSurfaceProps; +class SkTaskGroup; class SkTraceMemoryDump; class SK_API GrDirectContext : public GrContext { @@ -708,21 +717,45 @@ public: SkString dump() const; #endif + // Provides access to functions that aren't part of the public API. + GrContextPriv priv(); + const GrContextPriv priv() const; // NOLINT(readability-const-return-type) + protected: GrDirectContext(GrBackendApi backend, const GrContextOptions& options); bool init() override; - GrAtlasManager* onGetAtlasManager() override { return fAtlasManager.get(); } - GrSmallPathAtlasMgr* onGetSmallPathAtlasMgr() override; + GrAtlasManager* onGetAtlasManager() { return fAtlasManager.get(); } + GrSmallPathAtlasMgr* onGetSmallPathAtlasMgr(); GrDirectContext* asDirectContext() override { return this; } private: + // fTaskGroup must appear before anything that uses it (e.g. fGpu), so that it is destroyed + // after all of its users. Clients of fTaskGroup will generally want to ensure that they call + // wait() on it as they are being destroyed, to avoid the possibility of pending tasks being + // invoked after objects they depend upon have already been destroyed. + std::unique_ptr fTaskGroup; + std::unique_ptr fStrikeCache; + sk_sp fGpu; + std::unique_ptr fResourceCache; + std::unique_ptr fResourceProvider; + + bool fDidTestPMConversions; + // true if the PM/UPM conversion succeeded; false otherwise + bool fPMUPMConversionsRoundTrip; + + GrContextOptions::PersistentCache* fPersistentCache; + GrContextOptions::ShaderErrorHandler* fShaderErrorHandler; + + std::unique_ptr fMappedBufferManager; std::unique_ptr fAtlasManager; std::unique_ptr fSmallPathAtlasMgr; + friend class GrContextPriv; + using INHERITED = GrContext; }; diff --git a/include/private/GrContext.h b/include/private/GrContext.h index 0e47bac5ec..220b00b939 100644 --- a/include/private/GrContext.h +++ b/include/private/GrContext.h @@ -9,19 +9,8 @@ #define GrContext_DEFINED #include "include/core/SkTypes.h" -#include "include/gpu/GrContextOptions.h" #include "include/gpu/GrRecordingContext.h" -class GrAtlasManager; -class GrClientMappedBufferManager; -class GrContextPriv; -class GrGpu; -class GrResourceCache; -class GrResourceProvider; -class GrSmallPathAtlasMgr; -class GrStrikeCache; -class SkTaskGroup; - /** * This deprecated class is being merged into GrDirectContext and removed. * Do not add new subclasses, new API, or attempt to instantiate one. @@ -32,40 +21,10 @@ class SK_API GrContext : public GrRecordingContext { public: ~GrContext() override; - // Provides access to functions that aren't part of the public API. - GrContextPriv priv(); - const GrContextPriv priv() const; // NOLINT(readability-const-return-type) protected: GrContext(sk_sp); - virtual GrAtlasManager* onGetAtlasManager() = 0; - virtual GrSmallPathAtlasMgr* onGetSmallPathAtlasMgr() = 0; - private: - friend class GrDirectContext; // for access to fGpu - - // fTaskGroup must appear before anything that uses it (e.g. fGpu), so that it is destroyed - // after all of its users. Clients of fTaskGroup will generally want to ensure that they call - // wait() on it as they are being destroyed, to avoid the possibility of pending tasks being - // invoked after objects they depend upon have already been destroyed. - std::unique_ptr fTaskGroup; - std::unique_ptr fStrikeCache; - sk_sp fGpu; - std::unique_ptr fResourceCache; - std::unique_ptr fResourceProvider; - - bool fDidTestPMConversions; - // true if the PM/UPM conversion succeeded; false otherwise - bool fPMUPMConversionsRoundTrip; - - GrContextOptions::PersistentCache* fPersistentCache; - GrContextOptions::ShaderErrorHandler* fShaderErrorHandler; - - std::unique_ptr fMappedBufferManager; - - // TODO: have the GrClipStackClip use renderTargetContexts and rm this friending - friend class GrContextPriv; - using INHERITED = GrRecordingContext; }; diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h index cbea45248e..5e6e2f737f 100644 --- a/src/gpu/GrContextPriv.h +++ b/src/gpu/GrContextPriv.h @@ -22,7 +22,8 @@ class GrSurfaceProxy; class SkDeferredDisplayList; class SkTaskGroup; -/** Class that adds methods to GrContext that are only intended for use internal to Skia. +/** TODO: Rename to GrDirectContextPriv. + Class that adds methods to GrDirectContext that are only intended for use internal to Skia. This class is purely a privileged window into GrContext. It should never have additional data members or virtual methods. */ class GrContextPriv { @@ -168,7 +169,7 @@ public: #endif private: - explicit GrContextPriv(GrContext* context) : fContext(context) {} + explicit GrContextPriv(GrDirectContext* context) : fContext(context) {} GrContextPriv(const GrContextPriv&) = delete; GrContextPriv& operator=(const GrContextPriv&) = delete; @@ -176,15 +177,15 @@ private: const GrContextPriv* operator&() const; GrContextPriv* operator&(); - GrContext* fContext; + GrDirectContext* fContext; - friend class GrContext; // to construct/copy this type. + friend class GrDirectContext; // to construct/copy this type. }; -inline GrContextPriv GrContext::priv() { return GrContextPriv(this); } +inline GrContextPriv GrDirectContext::priv() { return GrContextPriv(this); } -inline const GrContextPriv GrContext::priv() const { // NOLINT(readability-const-return-type) - return GrContextPriv(const_cast(this)); +inline const GrContextPriv GrDirectContext::priv() const { // NOLINT(readability-const-return-type) + return GrContextPriv(const_cast(this)); } #endif diff --git a/tools/fiddle/fiddle_main.cpp b/tools/fiddle/fiddle_main.cpp index fa08050713..e749d9d780 100644 --- a/tools/fiddle/fiddle_main.cpp +++ b/tools/fiddle/fiddle_main.cpp @@ -119,7 +119,7 @@ static SkCanvas* prepare_canvas(SkCanvas * canvas) { } #ifdef SK_GL -static bool setup_backend_objects(GrContext* context, +static bool setup_backend_objects(GrDirectContext* context, const SkBitmap& bm, const DrawOptions& options) { if (!context) {