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 ScaledBackdropLayer(const SkRect * bounds,const SkPaint * paint,const SkImageFilter * backdrop,SkScalar backdropScale,SkCanvas::SaveLayerFlags saveLayerFlags)80 static SkCanvas::SaveLayerRec ScaledBackdropLayer(const SkRect* bounds, 81 const SkPaint* paint, 82 const SkImageFilter* backdrop, 83 SkScalar backdropScale, 84 SkCanvas::SaveLayerFlags saveLayerFlags) { 85 return SkCanvas::SaveLayerRec(bounds, paint, backdrop, backdropScale, saveLayerFlags); 86 } 87 GetBackdropScaleFactor(const SkCanvas::SaveLayerRec & rec)88 static SkScalar GetBackdropScaleFactor(const SkCanvas::SaveLayerRec& rec) { 89 return rec.fExperimentalBackdropScale; 90 } 91 SetBackdropScaleFactor(SkCanvas::SaveLayerRec * rec,SkScalar scale)92 static void SetBackdropScaleFactor(SkCanvas::SaveLayerRec* rec, SkScalar scale) { 93 rec->fExperimentalBackdropScale = scale; 94 } 95 96 static void DrawCustomMesh(SkCanvas*, 97 SkCustomMesh cm, 98 sk_sp<SkBlender> blender, 99 const SkPaint& paint); 100 }; 101 102 /** 103 * This constant is trying to balance the speed of ref'ing a subpicture into a parent picture, 104 * against the playback cost of recursing into the subpicture to get at its actual ops. 105 * 106 * For now we pick a conservatively small value, though measurement (and other heuristics like 107 * the type of ops contained) may justify changing this value. 108 */ 109 constexpr int kMaxPictureOpsToUnrollInsteadOfRef = 1; 110 111 #endif 112