blob: a8fda09efeba53d6c4cc0d6a9ba50af59df382b4 [file] [log] [blame]
robertphillips4fd74ae2016-08-03 14:26:53 -07001/*
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"
Brian Osman45580d32016-11-23 09:37:01 -050012#include "GrSurfaceContext.h"
Robert Phillipsc4039ea2018-03-01 11:36:45 -050013#include "text/GrAtlasManager.h"
robertphillips4fd74ae2016-08-03 14:26:53 -070014
Greg Danielbcf612b2017-05-01 13:50:58 +000015class GrBackendRenderTarget;
Brian Salomond17f6582017-07-19 18:28:58 -040016class GrOnFlushCallbackObject;
Greg Danield85f97d2017-03-07 13:37:21 -050017class GrSemaphore;
Robert Phillipse2f7d182016-12-15 09:23:05 -050018class GrSurfaceProxy;
Brian Salomond17f6582017-07-19 18:28:58 -040019class GrTextureContext;
Robert Phillipse2f7d182016-12-15 09:23:05 -050020
Robert Phillips62000362018-02-01 09:10:04 -050021class SkDeferredDisplayList;
22
robertphillips4fd74ae2016-08-03 14:26:53 -070023/** Class that adds methods to GrContext that are only intended for use internal to Skia.
24 This class is purely a privileged window into GrContext. It should never have additional
25 data members or virtual methods. */
26class GrContextPriv {
27public:
Robert Phillipse42edcc2017-12-13 11:50:22 -050028 /**
29 * Create a GrContext without a resource cache
30 */
31 static sk_sp<GrContext> MakeDDL(GrContextThreadSafeProxy*);
32
bungeman6bd52842016-10-27 09:30:08 -070033 GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); }
csmartdaltonbde96c62016-08-31 12:54:46 -070034
Robert Phillipsd5f9cdd2018-01-31 09:29:48 -050035 sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>,
36 sk_sp<SkColorSpace> = nullptr,
37 const SkSurfaceProps* = nullptr);
Robert Phillips31c26082016-12-14 15:12:15 -050038
Robert Phillipsbf25d432017-04-07 10:08:53 -040039 sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc&,
Greg Daniel65c7f662017-10-30 13:39:09 -040040 GrMipMapped,
Robert Phillipsbf25d432017-04-07 10:08:53 -040041 SkBackingFit,
Brian Salomon366093f2018-02-13 09:25:22 -050042 SkBudgeted,
43 sk_sp<SkColorSpace> colorSpace = nullptr,
44 const SkSurfaceProps* = nullptr);
Robert Phillipse305cc1f2016-12-14 12:19:05 -050045
Brian Salomond17f6582017-07-19 18:28:58 -040046 sk_sp<GrTextureContext> makeBackendTextureContext(const GrBackendTexture& tex,
Greg Daniel7ef28f32017-04-20 16:41:55 +000047 GrSurfaceOrigin origin,
Brian Osmanc1e37052017-03-09 14:19:20 -050048 sk_sp<SkColorSpace> colorSpace);
Robert Phillipsd46697a2017-01-25 12:10:37 -050049
Brian Osman11052242016-10-27 14:47:55 -040050 sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext(
Greg Daniel7ef28f32017-04-20 16:41:55 +000051 const GrBackendTexture& tex,
52 GrSurfaceOrigin origin,
53 int sampleCnt,
Brian Osman11052242016-10-27 14:47:55 -040054 sk_sp<SkColorSpace> colorSpace,
Brian Osmanc1e37052017-03-09 14:19:20 -050055 const SkSurfaceProps* = nullptr);
robertphillips4fd74ae2016-08-03 14:26:53 -070056
Brian Osman11052242016-10-27 14:47:55 -040057 sk_sp<GrRenderTargetContext> makeBackendRenderTargetRenderTargetContext(
Greg Danielbcf612b2017-05-01 13:50:58 +000058 const GrBackendRenderTarget&,
59 GrSurfaceOrigin origin,
Brian Osman11052242016-10-27 14:47:55 -040060 sk_sp<SkColorSpace> colorSpace,
61 const SkSurfaceProps* = nullptr);
robertphillips4fd74ae2016-08-03 14:26:53 -070062
Brian Osman11052242016-10-27 14:47:55 -040063 sk_sp<GrRenderTargetContext> makeBackendTextureAsRenderTargetRenderTargetContext(
Greg Daniel7ef28f32017-04-20 16:41:55 +000064 const GrBackendTexture& tex,
65 GrSurfaceOrigin origin,
66 int sampleCnt,
robertphillips4fd74ae2016-08-03 14:26:53 -070067 sk_sp<SkColorSpace> colorSpace,
68 const SkSurfaceProps* = nullptr);
69
Brian Osman46da1cc2017-02-14 14:15:48 -050070 bool disableGpuYUVConversion() const { return fContext->fDisableGpuYUVConversion; }
Brian Osman8a83ca42018-02-12 14:32:17 -050071 bool sharpenMipmappedTextures() const { return fContext->fSharpenMipmappedTextures; }
Brian Osman46da1cc2017-02-14 14:15:48 -050072
Robert Phillips7ee385e2017-03-30 08:02:11 -040073 /**
74 * Call to ensure all drawing to the context has been issued to the
75 * underlying 3D API.
76 * The 'proxy' parameter is a hint. If it is supplied the context will guarantee that
77 * the draws required for that proxy are flushed but it could do more. If no 'proxy' is
78 * provided then all current work will be flushed.
79 */
80 void flush(GrSurfaceProxy*);
81
Chris Daltonfe199b72017-05-05 11:26:15 -040082 /**
83 * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
84 *
85 * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
86 * ensure its lifetime is tied to that of the context.
Robert Phillipseb35f4d2017-03-21 07:56:47 -040087 */
Chris Daltonfe199b72017-05-05 11:26:15 -040088 void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
89
90 void testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject*);
Robert Phillipseb35f4d2017-03-21 07:56:47 -040091
Robert Phillips7ee385e2017-03-30 08:02:11 -040092 /**
93 * After this returns any pending writes to the surface will have been issued to the
94 * backend 3D API.
95 */
96 void flushSurfaceWrites(GrSurfaceProxy*);
97
98 /**
99 * After this returns any pending reads or writes to the surface will have been issued to the
100 * backend 3D API.
101 */
102 void flushSurfaceIO(GrSurfaceProxy*);
103
104 /**
105 * Finalizes all pending reads and writes to the surface and also performs an MSAA resolve
106 * if necessary.
107 *
108 * It is not necessary to call this before reading the render target via Skia/GrContext.
109 * GrContext will detect when it must perform a resolve before reading pixels back from the
110 * surface or using it as a texture.
111 */
112 void prepareSurfaceForExternalIO(GrSurfaceProxy*);
113
Robert Phillipse78b7252017-04-06 07:59:41 -0400114 /**
115 * These flags can be used with the read/write pixels functions below.
116 */
117 enum PixelOpsFlags {
118 /** The GrContext will not be flushed before the surface read or write. This means that
119 the read or write may occur before previous draws have executed. */
120 kDontFlush_PixelOpsFlag = 0x1,
121 /** Any surface writes should be flushed to the backend 3D API after the surface operation
122 is complete */
123 kFlushWrites_PixelOp = 0x2,
124 /** The src for write or dst read is unpremultiplied. This is only respected if both the
125 config src and dst configs are an RGBA/BGRA 8888 format. */
126 kUnpremul_PixelOpsFlag = 0x4,
127 };
128
129 /**
130 * Reads a rectangle of pixels from a surface.
Robert Phillipsf41c22f2017-04-18 07:48:58 -0400131 * @param src the surface context to read from.
Robert Phillipse78b7252017-04-06 07:59:41 -0400132 * @param left left edge of the rectangle to read (inclusive)
133 * @param top top edge of the rectangle to read (inclusive)
134 * @param width width of rectangle to read in pixels.
135 * @param height height of rectangle to read in pixels.
Robert Phillipsf41c22f2017-04-18 07:48:58 -0400136 * @param dstConfig the pixel config of the destination buffer
Robert Phillipse78b7252017-04-06 07:59:41 -0400137 * @param dstColorSpace color space of the destination buffer
138 * @param buffer memory to read the rectangle into.
139 * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly
140 * packed.
141 * @param pixelOpsFlags see PixelOpsFlags enum above.
142 *
143 * @return true if the read succeeded, false if not. The read can fail because of an unsupported
144 * pixel configs
145 */
Brian Salomonc320b152018-02-20 14:05:36 -0500146 bool readSurfacePixels(GrSurfaceContext* src, int left, int top, int width, int height,
147 GrColorType dstColorType, SkColorSpace* dstColorSpace, void* buffer,
148 size_t rowBytes = 0, uint32_t pixelOpsFlags = 0);
Robert Phillipse78b7252017-04-06 07:59:41 -0400149
150 /**
Brian Salomon5f33a8c2018-02-26 14:32:39 -0500151 * Writes a rectangle of pixels to a surface. There are currently two versions of this.
152 * writeSurfacePixels() is the older version which will be replaced by the more robust and
153 * maintainable (but perhaps slower) writeSurfacePixels2().
154 *
Robert Phillipsf41c22f2017-04-18 07:48:58 -0400155 * @param dst the surface context to write to.
Robert Phillipse78b7252017-04-06 07:59:41 -0400156 * @param left left edge of the rectangle to write (inclusive)
157 * @param top top edge of the rectangle to write (inclusive)
158 * @param width width of rectangle to write in pixels.
159 * @param height height of rectangle to write in pixels.
Brian Salomon5f33a8c2018-02-26 14:32:39 -0500160 * @param srcColorType the color type of the source buffer
Robert Phillipse78b7252017-04-06 07:59:41 -0400161 * @param srcColorSpace color space of the source buffer
162 * @param buffer memory to read pixels from
163 * @param rowBytes number of bytes between consecutive rows. Zero
164 * means rows are tightly packed.
165 * @param pixelOpsFlags see PixelOpsFlags enum above.
166 * @return true if the write succeeded, false if not. The write can fail because of an
167 * unsupported combination of surface and src configs.
168 */
Brian Salomonc320b152018-02-20 14:05:36 -0500169 bool writeSurfacePixels(GrSurfaceContext* dst, int left, int top, int width, int height,
170 GrColorType srcColorType, SkColorSpace* srcColorSpace,
171 const void* buffer, size_t rowBytes, uint32_t pixelOpsFlags = 0);
Brian Salomon5f33a8c2018-02-26 14:32:39 -0500172 bool writeSurfacePixels2(GrSurfaceContext* dst, int left, int top, int width, int height,
173 GrColorType srcColorType, SkColorSpace* srcColorSpace,
174 const void* buffer, size_t rowBytes, uint32_t pixelOpsFlags = 0);
Robert Phillipse78b7252017-04-06 07:59:41 -0400175
Greg Danielfc978fd2017-04-13 09:54:12 -0400176 GrBackend getBackend() const { return fContext->fBackend; }
177
Brian Osman51279982017-08-23 10:12:00 -0400178 SkTaskGroup* getTaskGroup() { return fContext->fTaskGroup.get(); }
179
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500180 GrProxyProvider* proxyProvider() { return fContext->fProxyProvider; }
181 const GrProxyProvider* proxyProvider() const { return fContext->fProxyProvider; }
182
Robert Phillips6be756b2018-01-16 15:07:54 -0500183 GrResourceProvider* resourceProvider() { return fContext->fResourceProvider; }
184 const GrResourceProvider* resourceProvider() const { return fContext->fResourceProvider; }
185
186 GrResourceCache* getResourceCache() { return fContext->fResourceCache; }
187
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500188 GrGpu* getGpu() { return fContext->fGpu.get(); }
189 const GrGpu* getGpu() const { return fContext->fGpu.get(); }
190
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500191 GrGlyphCache* getGlyphCache() { return fContext->fGlyphCache; }
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500192 GrTextBlobCache* getTextBlobCache() { return fContext->fTextBlobCache.get(); }
Robert Phillips1056eb82018-03-01 14:16:41 -0500193
194 GrRestrictedAtlasManager* getRestrictedAtlasManager() {
195 return fContext->onGetRestrictedAtlasManager();
196 }
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500197
198 // This accessor should only ever be called by the GrOpFlushState.
199 GrAtlasManager* getFullAtlasManager() {
Robert Phillips1056eb82018-03-01 14:16:41 -0500200 return fContext->onGetFullAtlasManager();
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500201 }
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500202
Robert Phillips62000362018-02-01 09:10:04 -0500203 void moveOpListsToDDL(SkDeferredDisplayList*);
204 void copyOpListsFromDDL(const SkDeferredDisplayList*, GrRenderTargetProxy* newDest);
205
robertphillips4fd74ae2016-08-03 14:26:53 -0700206private:
207 explicit GrContextPriv(GrContext* context) : fContext(context) {}
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400208 GrContextPriv(const GrContextPriv&); // unimpl
robertphillips4fd74ae2016-08-03 14:26:53 -0700209 GrContextPriv& operator=(const GrContextPriv&); // unimpl
210
211 // No taking addresses of this type.
212 const GrContextPriv* operator&() const;
213 GrContextPriv* operator&();
214
215 GrContext* fContext;
216
217 friend class GrContext; // to construct/copy this type.
218};
219
220inline GrContextPriv GrContext::contextPriv() { return GrContextPriv(this); }
221
222inline const GrContextPriv GrContext::contextPriv () const {
223 return GrContextPriv(const_cast<GrContext*>(this));
224}
225
226#endif