• 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 class SkAutoCanvasMatrixPaint : SkNoncopyable {
18 public:
19     SkAutoCanvasMatrixPaint(SkCanvas*, const SkMatrix*, const SkPaint*, const SkRect& bounds);
20     ~SkAutoCanvasMatrixPaint();
21 
22 private:
23     SkCanvas*   fCanvas;
24     int         fSaveCount;
25 };
26 
27 class SkCanvasPriv {
28 public:
29     // The lattice has pointers directly into the readbuffer
30     static bool ReadLattice(SkReadBuffer&, SkCanvas::Lattice*);
31 
32     static void WriteLattice(SkWriteBuffer&, const SkCanvas::Lattice&);
33 
34     // return the byte-size of the lattice, even if the buffer is null
35     // storage must be 4-byte aligned
36     static size_t WriteLattice(void* storage, const SkCanvas::Lattice&);
37 
SaveBehind(SkCanvas * canvas,const SkRect * subset)38     static int SaveBehind(SkCanvas* canvas, const SkRect* subset) {
39         return canvas->only_axis_aligned_saveBehind(subset);
40     }
DrawBehind(SkCanvas * canvas,const SkPaint & paint)41     static void DrawBehind(SkCanvas* canvas, const SkPaint& paint) {
42         canvas->drawClippedToSaveBehind(paint);
43     }
44 
45     // Exposed for testing on non-Android framework builds
ReplaceClip(SkCanvas * canvas,const SkIRect & rect)46     static void ReplaceClip(SkCanvas* canvas, const SkIRect& rect) {
47         canvas->androidFramework_replaceClip(rect);
48     }
49 
TopDeviceSurfaceDrawContext(SkCanvas * canvas)50     static GrSurfaceDrawContext* TopDeviceSurfaceDrawContext(SkCanvas* canvas) {
51         return canvas->topDeviceSurfaceDrawContext();
52     }
53 
54     // The experimental_DrawEdgeAAImageSet API accepts separate dstClips and preViewMatrices arrays,
55     // where entries refer into them, but no explicit size is provided. Given a set of entries,
56     // computes the minimum length for these arrays that would provide index access errors.
57     static void GetDstClipAndMatrixCounts(const SkCanvas::ImageSetEntry set[], int count,
58                                           int* totalDstClipCount, int* totalMatrixCount);
59 
60     // Checks that the marker name is an identifier ([a-zA-Z][a-zA-Z0-9_]*)
61     // Identifiers with leading underscores are reserved (not allowed).
62     static bool ValidateMarker(const char*);
63 };
64 
65 /**
66  *  This constant is trying to balance the speed of ref'ing a subpicture into a parent picture,
67  *  against the playback cost of recursing into the subpicture to get at its actual ops.
68  *
69  *  For now we pick a conservatively small value, though measurement (and other heuristics like
70  *  the type of ops contained) may justify changing this value.
71  */
72 constexpr int kMaxPictureOpsToUnrollInsteadOfRef = 1;
73 
74 #endif
75