1 /* 2 * Copyright 2017 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 SkDeferredDisplayListRecorder_DEFINED 9 #define SkDeferredDisplayListRecorder_DEFINED 10 11 #include "include/core/SkDeferredDisplayList.h" 12 #include "include/core/SkImage.h" 13 #include "include/core/SkImageInfo.h" 14 #include "include/core/SkRefCnt.h" 15 #include "include/core/SkSurfaceCharacterization.h" 16 #include "include/core/SkTypes.h" 17 18 class GrBackendFormat; 19 class GrBackendTexture; 20 class GrRecordingContext; 21 class GrYUVABackendTextureInfo; 22 class SkCanvas; 23 class SkSurface; 24 25 /* 26 * This class is intended to be used as: 27 * Get an SkSurfaceCharacterization representing the intended gpu-backed destination SkSurface 28 * Create one of these (an SkDeferredDisplayListRecorder) on the stack 29 * Get the canvas and render into it 30 * Snap off and hold on to an SkDeferredDisplayList 31 * Once your app actually needs the pixels, call SkSurface::draw(SkDeferredDisplayList*) 32 * 33 * This class never accesses the GPU but performs all the cpu work it can. It 34 * is thread-safe (i.e., one can break a scene into tiles and perform their cpu-side 35 * work in parallel ahead of time). 36 */ 37 class SK_API SkDeferredDisplayListRecorder { 38 public: 39 SkDeferredDisplayListRecorder(const SkSurfaceCharacterization&); 40 ~SkDeferredDisplayListRecorder(); 41 characterization()42 const SkSurfaceCharacterization& characterization() const { 43 return fCharacterization; 44 } 45 46 // The backing canvas will become invalid (and this entry point will return 47 // null) once 'detach' is called. 48 // Note: ownership of the SkCanvas is not transferred via this call. 49 SkCanvas* getCanvas(); 50 51 sk_sp<SkDeferredDisplayList> detach(); 52 53 #if defined(SK_GANESH) 54 using PromiseImageTextureContext = SkImage::PromiseImageTextureContext; 55 using PromiseImageTextureFulfillProc = SkImage::PromiseImageTextureFulfillProc; 56 using PromiseImageTextureReleaseProc = SkImage::PromiseImageTextureReleaseProc; 57 58 #ifndef SK_MAKE_PROMISE_TEXTURE_DISABLE_LEGACY_API 59 /** Deprecated: Use SkImage::MakePromiseTexture instead. */ 60 sk_sp<SkImage> makePromiseTexture(const GrBackendFormat& backendFormat, 61 int width, 62 int height, 63 GrMipmapped mipmapped, 64 GrSurfaceOrigin origin, 65 SkColorType colorType, 66 SkAlphaType alphaType, 67 sk_sp<SkColorSpace> colorSpace, 68 PromiseImageTextureFulfillProc textureFulfillProc, 69 PromiseImageTextureReleaseProc textureReleaseProc, 70 PromiseImageTextureContext textureContext); 71 72 /** Deprecated: Use SkImage::MakePromiseYUVATexture instead. */ 73 sk_sp<SkImage> makeYUVAPromiseTexture(const GrYUVABackendTextureInfo& yuvaBackendTextureInfo, 74 sk_sp<SkColorSpace> imageColorSpace, 75 PromiseImageTextureFulfillProc textureFulfillProc, 76 PromiseImageTextureReleaseProc textureReleaseProc, 77 PromiseImageTextureContext textureContexts[]); 78 #endif // SK_MAKE_PROMISE_TEXTURE_DISABLE_LEGACY_API 79 #endif // defined(SK_GANESH) 80 81 private: 82 SkDeferredDisplayListRecorder(const SkDeferredDisplayListRecorder&) = delete; 83 SkDeferredDisplayListRecorder& operator=(const SkDeferredDisplayListRecorder&) = delete; 84 85 bool init(); 86 87 const SkSurfaceCharacterization fCharacterization; 88 89 #if defined(SK_GANESH) 90 sk_sp<GrRecordingContext> fContext; 91 sk_sp<GrRenderTargetProxy> fTargetProxy; 92 sk_sp<SkDeferredDisplayList::LazyProxyData> fLazyProxyData; 93 sk_sp<SkSurface> fSurface; 94 #endif 95 }; 96 97 #endif 98