1 /* 2 * Copyright 2023 Google LLC 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 GrDeferredDisplayListRecorder_DEFINED 9 #define GrDeferredDisplayListRecorder_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "include/core/SkTypes.h" 13 #include "include/private/chromium/GrDeferredDisplayList.h" 14 #include "include/private/chromium/GrSurfaceCharacterization.h" 15 16 class GrRecordingContext; 17 class GrRenderTargetProxy; 18 class SkCanvas; 19 class SkSurface; 20 21 /* 22 * This class is intended to be used as: 23 * Get a GrSurfaceCharacterization representing the intended gpu-backed destination SkSurface 24 * Create one of these (a GrDeferredDisplayListRecorder) on the stack 25 * Get the canvas and render into it 26 * Snap off and hold on to a GrDeferredDisplayList 27 * Once your app actually needs the pixels, call skgpu::ganesh::DrawDDL(GrDeferredDisplayList*) 28 * 29 * This class never accesses the GPU but performs all the cpu work it can. It 30 * is thread-safe (i.e., one can break a scene into tiles and perform their cpu-side 31 * work in parallel ahead of time). 32 */ 33 class SK_API GrDeferredDisplayListRecorder { 34 public: 35 GrDeferredDisplayListRecorder(const GrSurfaceCharacterization&); 36 ~GrDeferredDisplayListRecorder(); 37 characterization()38 const GrSurfaceCharacterization& characterization() const { 39 return fCharacterization; 40 } 41 42 // The backing canvas will become invalid (and this entry point will return 43 // null) once 'detach' is called. 44 // Note: ownership of the SkCanvas is not transferred via this call. 45 SkCanvas* getCanvas(); 46 47 sk_sp<GrDeferredDisplayList> detach(); 48 49 private: 50 GrDeferredDisplayListRecorder(const GrDeferredDisplayListRecorder&) = delete; 51 GrDeferredDisplayListRecorder& operator=(const GrDeferredDisplayListRecorder&) = delete; 52 53 bool init(); 54 55 const GrSurfaceCharacterization fCharacterization; 56 sk_sp<GrRecordingContext> fContext; 57 sk_sp<GrRenderTargetProxy> fTargetProxy; 58 sk_sp<GrDeferredDisplayList::LazyProxyData> fLazyProxyData; 59 sk_sp<SkSurface> fSurface; 60 }; 61 62 #endif 63