• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 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 SkCanvasPriv_DEFINED
9 #define SkCanvasPriv_DEFINED
10 
11 #include "include/core/SkCanvas.h"
12 #include "include/private/base/SkNoncopyable.h"
13 
14 class SkReadBuffer;
15 class SkWriteBuffer;
16 
17 #if GR_TEST_UTILS && defined(SK_GANESH)
18 namespace skgpu::v1 {
19     class SurfaceDrawContext;
20     class SurfaceFillContext;
21 }
22 #endif
23 
24 // This declaration must match the one in SkDeferredDisplayList.h
25 #if defined(SK_GANESH)
26 class GrRenderTargetProxy;
27 #else
28 using GrRenderTargetProxy = SkRefCnt;
29 #endif // defined(SK_GANESH)
30 
31 #if GRAPHITE_TEST_UTILS
32 namespace skgpu::graphite {
33     class TextureProxy;
34 }
35 #endif
36 
37 class SkAutoCanvasMatrixPaint : SkNoncopyable {
38 public:
39     SkAutoCanvasMatrixPaint(SkCanvas*, const SkMatrix*, const SkPaint*, const SkRect& bounds);
40     ~SkAutoCanvasMatrixPaint();
41 
42 private:
43     SkCanvas*   fCanvas;
44     int         fSaveCount;
45 };
46 
47 class SkCanvasPriv {
48 public:
49     // The lattice has pointers directly into the readbuffer
50     static bool ReadLattice(SkReadBuffer&, SkCanvas::Lattice*);
51 
52     static void WriteLattice(SkWriteBuffer&, const SkCanvas::Lattice&);
53 
54     // return the byte-size of the lattice, even if the buffer is null
55     // storage must be 4-byte aligned
56     static size_t WriteLattice(void* storage, const SkCanvas::Lattice&);
57 
SaveBehind(SkCanvas * canvas,const SkRect * subset)58     static int SaveBehind(SkCanvas* canvas, const SkRect* subset) {
59         return canvas->only_axis_aligned_saveBehind(subset);
60     }
DrawBehind(SkCanvas * canvas,const SkPaint & paint)61     static void DrawBehind(SkCanvas* canvas, const SkPaint& paint) {
62         canvas->drawClippedToSaveBehind(paint);
63     }
64 
65     // Exposed for testing on non-Android framework builds
ResetClip(SkCanvas * canvas)66     static void ResetClip(SkCanvas* canvas) {
67         canvas->internal_private_resetClip();
68     }
69 
TopDevice(SkCanvas * canvas)70     static SkBaseDevice* TopDevice(SkCanvas* canvas) {
71         return canvas->topDevice();
72     }
73 
74 #if GR_TEST_UTILS && defined(SK_GANESH)
75     static skgpu::v1::SurfaceDrawContext* TopDeviceSurfaceDrawContext(SkCanvas*);
76     static skgpu::v1::SurfaceFillContext* TopDeviceSurfaceFillContext(SkCanvas*);
77 #endif
78     static GrRenderTargetProxy* TopDeviceTargetProxy(SkCanvas*);
79 
80 #if GRAPHITE_TEST_UTILS
81     static skgpu::graphite::TextureProxy* TopDeviceGraphiteTargetProxy(SkCanvas*);
82 #endif
83 
84     // The experimental_DrawEdgeAAImageSet API accepts separate dstClips and preViewMatrices arrays,
85     // where entries refer into them, but no explicit size is provided. Given a set of entries,
86     // computes the minimum length for these arrays that would provide index access errors.
87     static void GetDstClipAndMatrixCounts(const SkCanvas::ImageSetEntry set[], int count,
88                                           int* totalDstClipCount, int* totalMatrixCount);
89 
ScaledBackdropLayer(const SkRect * bounds,const SkPaint * paint,const SkImageFilter * backdrop,SkScalar backdropScale,SkCanvas::SaveLayerFlags saveLayerFlags)90     static SkCanvas::SaveLayerRec ScaledBackdropLayer(const SkRect* bounds,
91                                                       const SkPaint* paint,
92                                                       const SkImageFilter* backdrop,
93                                                       SkScalar backdropScale,
94                                                       SkCanvas::SaveLayerFlags saveLayerFlags) {
95         return SkCanvas::SaveLayerRec(bounds, paint, backdrop, backdropScale, saveLayerFlags);
96     }
97 
GetBackdropScaleFactor(const SkCanvas::SaveLayerRec & rec)98     static SkScalar GetBackdropScaleFactor(const SkCanvas::SaveLayerRec& rec) {
99         return rec.fExperimentalBackdropScale;
100     }
101 
SetBackdropScaleFactor(SkCanvas::SaveLayerRec * rec,SkScalar scale)102     static void SetBackdropScaleFactor(SkCanvas::SaveLayerRec* rec, SkScalar scale) {
103         rec->fExperimentalBackdropScale = scale;
104     }
105 };
106 
107 /**
108  *  This constant is trying to balance the speed of ref'ing a subpicture into a parent picture,
109  *  against the playback cost of recursing into the subpicture to get at its actual ops.
110  *
111  *  For now we pick a conservatively small value, though measurement (and other heuristics like
112  *  the type of ops contained) may justify changing this value.
113  */
114 constexpr int kMaxPictureOpsToUnrollInsteadOfRef = 1;
115 
116 #endif
117