• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/SkImageInfo.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/core/SkSurfaceCharacterization.h"
15 #include "include/core/SkTypes.h"
16 
17 class GrBackendFormat;
18 class GrBackendTexture;
19 class GrRecordingContext;
20 class GrYUVABackendTextureInfo;
21 class SkCanvas;
22 class SkImage;
23 class SkPromiseImageTexture;
24 class SkSurface;
25 
26 /*
27  * This class is intended to be used as:
28  *   Get an SkSurfaceCharacterization representing the intended gpu-backed destination SkSurface
29  *   Create one of these (an SkDeferredDisplayListRecorder) on the stack
30  *   Get the canvas and render into it
31  *   Snap off and hold on to an SkDeferredDisplayList
32  *   Once your app actually needs the pixels, call SkSurface::draw(SkDeferredDisplayList*)
33  *
34  * This class never accesses the GPU but performs all the cpu work it can. It
35  * is thread-safe (i.e., one can break a scene into tiles and perform their cpu-side
36  * work in parallel ahead of time).
37  */
38 class SK_API SkDeferredDisplayListRecorder {
39 public:
40     SkDeferredDisplayListRecorder(const SkSurfaceCharacterization&);
41     ~SkDeferredDisplayListRecorder();
42 
characterization()43     const SkSurfaceCharacterization& characterization() const {
44         return fCharacterization;
45     }
46 
47     // The backing canvas will become invalid (and this entry point will return
48     // null) once 'detach' is called.
49     // Note: ownership of the SkCanvas is not transferred via this call.
50     SkCanvas* getCanvas();
51 
52     sk_sp<SkDeferredDisplayList> detach();
53 
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
79 
80 private:
81     SkDeferredDisplayListRecorder(const SkDeferredDisplayListRecorder&) = delete;
82     SkDeferredDisplayListRecorder& operator=(const SkDeferredDisplayListRecorder&) = delete;
83 
84     bool init();
85 
86     const SkSurfaceCharacterization             fCharacterization;
87 
88 #if SK_SUPPORT_GPU
89     sk_sp<GrRecordingContext>                   fContext;
90     sk_sp<GrRenderTargetProxy>                  fTargetProxy;
91     sk_sp<SkDeferredDisplayList::LazyProxyData> fLazyProxyData;
92     sk_sp<SkSurface>                            fSurface;
93 #endif
94 };
95 
96 #endif
97