robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 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" |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 12 | #include "GrSurfaceContext.h" |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 13 | #include "text/GrAtlasManager.h" |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 14 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 15 | class GrBackendRenderTarget; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 16 | class GrOnFlushCallbackObject; |
Greg Daniel | d85f97d | 2017-03-07 13:37:21 -0500 | [diff] [blame] | 17 | class GrSemaphore; |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 18 | class GrSurfaceProxy; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 19 | class GrTextureContext; |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 20 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 21 | class SkDeferredDisplayList; |
| 22 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 23 | /** 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. */ |
| 26 | class GrContextPriv { |
| 27 | public: |
Robert Phillips | e42edcc | 2017-12-13 11:50:22 -0500 | [diff] [blame] | 28 | /** |
| 29 | * Create a GrContext without a resource cache |
| 30 | */ |
| 31 | static sk_sp<GrContext> MakeDDL(GrContextThreadSafeProxy*); |
| 32 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 33 | GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); } |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 34 | |
Robert Phillips | d5f9cdd | 2018-01-31 09:29:48 -0500 | [diff] [blame] | 35 | sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>, |
| 36 | sk_sp<SkColorSpace> = nullptr, |
| 37 | const SkSurfaceProps* = nullptr); |
Robert Phillips | 31c2608 | 2016-12-14 15:12:15 -0500 | [diff] [blame] | 38 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 39 | sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc&, |
Greg Daniel | 65c7f66 | 2017-10-30 13:39:09 -0400 | [diff] [blame] | 40 | GrMipMapped, |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 41 | SkBackingFit, |
Brian Salomon | 366093f | 2018-02-13 09:25:22 -0500 | [diff] [blame] | 42 | SkBudgeted, |
| 43 | sk_sp<SkColorSpace> colorSpace = nullptr, |
| 44 | const SkSurfaceProps* = nullptr); |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 45 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 46 | sk_sp<GrTextureContext> makeBackendTextureContext(const GrBackendTexture& tex, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 47 | GrSurfaceOrigin origin, |
Brian Osman | c1e3705 | 2017-03-09 14:19:20 -0500 | [diff] [blame] | 48 | sk_sp<SkColorSpace> colorSpace); |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 49 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 50 | sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext( |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 51 | const GrBackendTexture& tex, |
| 52 | GrSurfaceOrigin origin, |
| 53 | int sampleCnt, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 54 | sk_sp<SkColorSpace> colorSpace, |
Brian Osman | c1e3705 | 2017-03-09 14:19:20 -0500 | [diff] [blame] | 55 | const SkSurfaceProps* = nullptr); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 56 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 57 | sk_sp<GrRenderTargetContext> makeBackendRenderTargetRenderTargetContext( |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 58 | const GrBackendRenderTarget&, |
| 59 | GrSurfaceOrigin origin, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 60 | sk_sp<SkColorSpace> colorSpace, |
| 61 | const SkSurfaceProps* = nullptr); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 62 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 63 | sk_sp<GrRenderTargetContext> makeBackendTextureAsRenderTargetRenderTargetContext( |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 64 | const GrBackendTexture& tex, |
| 65 | GrSurfaceOrigin origin, |
| 66 | int sampleCnt, |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 67 | sk_sp<SkColorSpace> colorSpace, |
| 68 | const SkSurfaceProps* = nullptr); |
| 69 | |
Brian Osman | 46da1cc | 2017-02-14 14:15:48 -0500 | [diff] [blame] | 70 | bool disableGpuYUVConversion() const { return fContext->fDisableGpuYUVConversion; } |
Brian Osman | 8a83ca4 | 2018-02-12 14:32:17 -0500 | [diff] [blame] | 71 | bool sharpenMipmappedTextures() const { return fContext->fSharpenMipmappedTextures; } |
Brian Osman | 46da1cc | 2017-02-14 14:15:48 -0500 | [diff] [blame] | 72 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 73 | /** |
| 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 Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 82 | /** |
| 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 Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 87 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 88 | void addOnFlushCallbackObject(GrOnFlushCallbackObject*); |
| 89 | |
| 90 | void testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject*); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 91 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 92 | /** |
| 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 Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 114 | /** |
| 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 Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 131 | * @param src the surface context to read from. |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 132 | * @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 Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 136 | * @param dstConfig the pixel config of the destination buffer |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 137 | * @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 Salomon | c320b15 | 2018-02-20 14:05:36 -0500 | [diff] [blame] | 146 | 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 Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 149 | |
| 150 | /** |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 151 | * 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 Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 155 | * @param dst the surface context to write to. |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 156 | * @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 Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 160 | * @param srcColorType the color type of the source buffer |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 161 | * @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 Salomon | c320b15 | 2018-02-20 14:05:36 -0500 | [diff] [blame] | 169 | 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 Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 172 | 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 Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 175 | |
Greg Daniel | fc978fd | 2017-04-13 09:54:12 -0400 | [diff] [blame] | 176 | GrBackend getBackend() const { return fContext->fBackend; } |
| 177 | |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 178 | SkTaskGroup* getTaskGroup() { return fContext->fTaskGroup.get(); } |
| 179 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 180 | GrProxyProvider* proxyProvider() { return fContext->fProxyProvider; } |
| 181 | const GrProxyProvider* proxyProvider() const { return fContext->fProxyProvider; } |
| 182 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 183 | GrResourceProvider* resourceProvider() { return fContext->fResourceProvider; } |
| 184 | const GrResourceProvider* resourceProvider() const { return fContext->fResourceProvider; } |
| 185 | |
| 186 | GrResourceCache* getResourceCache() { return fContext->fResourceCache; } |
| 187 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 188 | GrGpu* getGpu() { return fContext->fGpu.get(); } |
| 189 | const GrGpu* getGpu() const { return fContext->fGpu.get(); } |
| 190 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 191 | GrGlyphCache* getGlyphCache() { return fContext->fGlyphCache; } |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 192 | GrTextBlobCache* getTextBlobCache() { return fContext->fTextBlobCache.get(); } |
Robert Phillips | 1056eb8 | 2018-03-01 14:16:41 -0500 | [diff] [blame^] | 193 | |
| 194 | GrRestrictedAtlasManager* getRestrictedAtlasManager() { |
| 195 | return fContext->onGetRestrictedAtlasManager(); |
| 196 | } |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 197 | |
| 198 | // This accessor should only ever be called by the GrOpFlushState. |
| 199 | GrAtlasManager* getFullAtlasManager() { |
Robert Phillips | 1056eb8 | 2018-03-01 14:16:41 -0500 | [diff] [blame^] | 200 | return fContext->onGetFullAtlasManager(); |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 201 | } |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 202 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 203 | void moveOpListsToDDL(SkDeferredDisplayList*); |
| 204 | void copyOpListsFromDDL(const SkDeferredDisplayList*, GrRenderTargetProxy* newDest); |
| 205 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 206 | private: |
| 207 | explicit GrContextPriv(GrContext* context) : fContext(context) {} |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 208 | GrContextPriv(const GrContextPriv&); // unimpl |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 209 | 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 | |
| 220 | inline GrContextPriv GrContext::contextPriv() { return GrContextPriv(this); } |
| 221 | |
| 222 | inline const GrContextPriv GrContext::contextPriv () const { |
| 223 | return GrContextPriv(const_cast<GrContext*>(this)); |
| 224 | } |
| 225 | |
| 226 | #endif |