Line data Source code
1 : /*
2 : * Copyright 2016 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 GrContextPriv_DEFINED
9 : #define GrContextPriv_DEFINED
10 :
11 : #include "GrContext.h"
12 : #include "GrSurfaceContext.h"
13 :
14 : class GrSemaphore;
15 : class GrSurfaceProxy;
16 : class GrPreFlushCallbackObject;
17 :
18 : /** Class that adds methods to GrContext that are only intended for use internal to Skia.
19 : This class is purely a privileged window into GrContext. It should never have additional
20 : data members or virtual methods. */
21 : class GrContextPriv {
22 : public:
23 0 : GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); }
24 :
25 : // Create a renderTargetContext that wraps an existing renderTarget
26 : sk_sp<GrRenderTargetContext> makeWrappedRenderTargetContext(sk_sp<GrRenderTarget>,
27 : sk_sp<SkColorSpace>,
28 : const SkSurfaceProps* = nullptr);
29 :
30 : // Create a surfaceContext that wraps an existing texture or renderTarget
31 : sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurface>);
32 :
33 : sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>, sk_sp<SkColorSpace>);
34 :
35 : sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc&,
36 : SkBackingFit,
37 : SkBudgeted);
38 :
39 : // TODO: Maybe add a 'surfaceProps' param (that is ignored for non-RTs) and remove
40 : // makeBackendTextureRenderTargetContext & makeBackendTextureAsRenderTargetRenderTargetContext
41 : sk_sp<GrSurfaceContext> makeBackendSurfaceContext(const GrBackendTextureDesc& desc,
42 : sk_sp<SkColorSpace> colorSpace);
43 :
44 : sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext(
45 : const GrBackendTextureDesc& desc,
46 : sk_sp<SkColorSpace> colorSpace,
47 : const SkSurfaceProps* = nullptr);
48 :
49 : sk_sp<GrRenderTargetContext> makeBackendRenderTargetRenderTargetContext(
50 : const GrBackendRenderTargetDesc& desc,
51 : sk_sp<SkColorSpace> colorSpace,
52 : const SkSurfaceProps* = nullptr);
53 :
54 : sk_sp<GrRenderTargetContext> makeBackendTextureAsRenderTargetRenderTargetContext(
55 : const GrBackendTextureDesc& desc,
56 : sk_sp<SkColorSpace> colorSpace,
57 : const SkSurfaceProps* = nullptr);
58 :
59 0 : bool disableGpuYUVConversion() const { return fContext->fDisableGpuYUVConversion; }
60 :
61 : /**
62 : * Call to ensure all drawing to the context has been issued to the
63 : * underlying 3D API.
64 : * The 'proxy' parameter is a hint. If it is supplied the context will guarantee that
65 : * the draws required for that proxy are flushed but it could do more. If no 'proxy' is
66 : * provided then all current work will be flushed.
67 : */
68 : void flush(GrSurfaceProxy*);
69 :
70 : /*
71 : * A ref will be taken on the preFlushCallbackObject which will be removed when the
72 : * context is destroyed.
73 : */
74 : void addPreFlushCallbackObject(sk_sp<GrPreFlushCallbackObject>);
75 :
76 : /**
77 : * After this returns any pending writes to the surface will have been issued to the
78 : * backend 3D API.
79 : */
80 : void flushSurfaceWrites(GrSurfaceProxy*);
81 :
82 : /**
83 : * After this returns any pending reads or writes to the surface will have been issued to the
84 : * backend 3D API.
85 : */
86 : void flushSurfaceIO(GrSurfaceProxy*);
87 :
88 : /**
89 : * Finalizes all pending reads and writes to the surface and also performs an MSAA resolve
90 : * if necessary.
91 : *
92 : * It is not necessary to call this before reading the render target via Skia/GrContext.
93 : * GrContext will detect when it must perform a resolve before reading pixels back from the
94 : * surface or using it as a texture.
95 : */
96 : void prepareSurfaceForExternalIO(GrSurfaceProxy*);
97 :
98 : /**
99 : * These flags can be used with the read/write pixels functions below.
100 : */
101 : enum PixelOpsFlags {
102 : /** The GrContext will not be flushed before the surface read or write. This means that
103 : the read or write may occur before previous draws have executed. */
104 : kDontFlush_PixelOpsFlag = 0x1,
105 : /** Any surface writes should be flushed to the backend 3D API after the surface operation
106 : is complete */
107 : kFlushWrites_PixelOp = 0x2,
108 : /** The src for write or dst read is unpremultiplied. This is only respected if both the
109 : config src and dst configs are an RGBA/BGRA 8888 format. */
110 : kUnpremul_PixelOpsFlag = 0x4,
111 : };
112 :
113 : /**
114 : * Reads a rectangle of pixels from a surface.
115 : * @param surface the surface to read from.
116 : * @param srcColorSpace color space of the surface
117 : * @param left left edge of the rectangle to read (inclusive)
118 : * @param top top edge of the rectangle to read (inclusive)
119 : * @param width width of rectangle to read in pixels.
120 : * @param height height of rectangle to read in pixels.
121 : * @param config the pixel config of the destination buffer
122 : * @param dstColorSpace color space of the destination buffer
123 : * @param buffer memory to read the rectangle into.
124 : * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly
125 : * packed.
126 : * @param pixelOpsFlags see PixelOpsFlags enum above.
127 : *
128 : * @return true if the read succeeded, false if not. The read can fail because of an unsupported
129 : * pixel configs
130 : */
131 : bool readSurfacePixels(GrSurfaceProxy* src, SkColorSpace* srcColorSpace,
132 : int left, int top, int width, int height,
133 : GrPixelConfig config, SkColorSpace* dstColorSpace, void* buffer,
134 : size_t rowBytes = 0,
135 : uint32_t pixelOpsFlags = 0);
136 :
137 : /**
138 : * Writes a rectangle of pixels to a surface.
139 : * @param dst the surface to write to.
140 : * @param dstColorSpace color space of the surface
141 : * @param left left edge of the rectangle to write (inclusive)
142 : * @param top top edge of the rectangle to write (inclusive)
143 : * @param width width of rectangle to write in pixels.
144 : * @param height height of rectangle to write in pixels.
145 : * @param config the pixel config of the source buffer
146 : * @param srcColorSpace color space of the source buffer
147 : * @param buffer memory to read pixels from
148 : * @param rowBytes number of bytes between consecutive rows. Zero
149 : * means rows are tightly packed.
150 : * @param pixelOpsFlags see PixelOpsFlags enum above.
151 : * @return true if the write succeeded, false if not. The write can fail because of an
152 : * unsupported combination of surface and src configs.
153 : */
154 : bool writeSurfacePixels(GrSurfaceProxy* dst, SkColorSpace* dstColorSpace,
155 : int left, int top, int width, int height,
156 : GrPixelConfig config, SkColorSpace* srcColorSpace, const void* buffer,
157 : size_t rowBytes,
158 : uint32_t pixelOpsFlags = 0);
159 :
160 : private:
161 0 : explicit GrContextPriv(GrContext* context) : fContext(context) {}
162 : GrContextPriv(const GrContextPriv&); // unimpl
163 : GrContextPriv& operator=(const GrContextPriv&); // unimpl
164 :
165 : // No taking addresses of this type.
166 : const GrContextPriv* operator&() const;
167 : GrContextPriv* operator&();
168 :
169 : GrContext* fContext;
170 :
171 : friend class GrContext; // to construct/copy this type.
172 : };
173 :
174 0 : inline GrContextPriv GrContext::contextPriv() { return GrContextPriv(this); }
175 :
176 : inline const GrContextPriv GrContext::contextPriv () const {
177 : return GrContextPriv(const_cast<GrContext*>(this));
178 : }
179 :
180 : #endif
|