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