Home | History | Annotate | Download | only in private
      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 GrRecordingContext_DEFINED
      9 #define GrRecordingContext_DEFINED
     10 
     11 #include "GrAuditTrail.h"
     12 #include "GrImageContext.h"
     13 #include "SkRefCnt.h"
     14 
     15 class GrDrawingManager;
     16 class GrOnFlushCallbackObject;
     17 class GrOpMemoryPool;
     18 class GrRecordingContextPriv;
     19 class GrStrikeCache;
     20 class GrTextBlobCache;
     21 
     22 class SK_API GrRecordingContext : public GrImageContext {
     23 public:
     24     ~GrRecordingContext() override;
     25 
     26     // Provides access to functions that aren't part of the public API.
     27     GrRecordingContextPriv priv();
     28     const GrRecordingContextPriv priv() const;
     29 
     30 protected:
     31     friend class GrRecordingContextPriv; // for hidden functions
     32 
     33     GrRecordingContext(GrBackendApi, const GrContextOptions&, uint32_t contextID);
     34     bool init(sk_sp<const GrCaps>, sk_sp<GrSkSLFPFactoryCache>) override;
     35     void setupDrawingManager(bool explicitlyAllocate, bool sortOpLists);
     36 
     37     void abandonContext() override;
     38 
     39     GrDrawingManager* drawingManager();
     40 
     41     sk_sp<GrOpMemoryPool> refOpMemoryPool();
     42     GrOpMemoryPool* opMemoryPool();
     43 
     44     GrStrikeCache* getGrStrikeCache() { return fStrikeCache.get(); }
     45     GrTextBlobCache* getTextBlobCache();
     46     const GrTextBlobCache* getTextBlobCache() const;
     47 
     48     /**
     49      * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
     50      *
     51      * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
     52      * ensure its lifetime is tied to that of the context.
     53      */
     54     void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
     55 
     56     sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>,
     57                                                       sk_sp<SkColorSpace> = nullptr,
     58                                                       const SkSurfaceProps* = nullptr);
     59 
     60     sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrBackendFormat&,
     61                                                        const GrSurfaceDesc&,
     62                                                        GrSurfaceOrigin,
     63                                                        GrMipMapped,
     64                                                        SkBackingFit,
     65                                                        SkBudgeted,
     66                                                        sk_sp<SkColorSpace> colorSpace = nullptr,
     67                                                        const SkSurfaceProps* = nullptr);
     68 
     69     /*
     70      * Create a new render target context backed by a deferred-style
     71      * GrRenderTargetProxy. We guarantee that "asTextureProxy" will succeed for
     72      * renderTargetContexts created via this entry point.
     73      */
     74     sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContext(
     75                                             const GrBackendFormat& format,
     76                                             SkBackingFit fit,
     77                                             int width, int height,
     78                                             GrPixelConfig config,
     79                                             sk_sp<SkColorSpace> colorSpace,
     80                                             int sampleCnt = 1,
     81                                             GrMipMapped = GrMipMapped::kNo,
     82                                             GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
     83                                             const SkSurfaceProps* surfaceProps = nullptr,
     84                                             SkBudgeted = SkBudgeted::kYes);
     85 
     86     /*
     87      * This method will attempt to create a renderTargetContext that has, at least, the number of
     88      * channels and precision per channel as requested in 'config' (e.g., A8 and 888 can be
     89      * converted to 8888). It may also swizzle the channels (e.g., BGRA -> RGBA).
     90      * SRGB-ness will be preserved.
     91      */
     92     sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContextWithFallback(
     93                                             const GrBackendFormat& format,
     94                                             SkBackingFit fit,
     95                                             int width, int height,
     96                                             GrPixelConfig config,
     97                                             sk_sp<SkColorSpace> colorSpace,
     98                                             int sampleCnt = 1,
     99                                             GrMipMapped = GrMipMapped::kNo,
    100                                             GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
    101                                             const SkSurfaceProps* surfaceProps = nullptr,
    102                                             SkBudgeted budgeted = SkBudgeted::kYes);
    103 
    104     GrAuditTrail* auditTrail() { return &fAuditTrail; }
    105 
    106     GrRecordingContext* asRecordingContext() override { return this; }
    107 
    108 private:
    109     std::unique_ptr<GrDrawingManager> fDrawingManager;
    110     // All the GrOp-derived classes use this pool.
    111     sk_sp<GrOpMemoryPool>             fOpMemoryPool;
    112 
    113     std::unique_ptr<GrStrikeCache>    fStrikeCache;
    114     std::unique_ptr<GrTextBlobCache>  fTextBlobCache;
    115 
    116     GrAuditTrail                      fAuditTrail;
    117 
    118     typedef GrImageContext INHERITED;
    119 };
    120 
    121 #endif
    122