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" |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 13 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 14 | class GrBackendRenderTarget; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 15 | class GrOnFlushCallbackObject; |
Greg Daniel | d85f97d | 2017-03-07 13:37:21 -0500 | [diff] [blame] | 16 | class GrSemaphore; |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 17 | class GrSurfaceProxy; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 18 | class GrTextureContext; |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 19 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 20 | /** Class that adds methods to GrContext that are only intended for use internal to Skia. |
| 21 | This class is purely a privileged window into GrContext. It should never have additional |
| 22 | data members or virtual methods. */ |
| 23 | class GrContextPriv { |
| 24 | public: |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 25 | GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); } |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 26 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 27 | sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>, sk_sp<SkColorSpace>); |
Robert Phillips | 31c2608 | 2016-12-14 15:12:15 -0500 | [diff] [blame] | 28 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 29 | sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc&, |
| 30 | SkBackingFit, |
| 31 | SkBudgeted); |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 32 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 33 | sk_sp<GrTextureContext> makeBackendTextureContext(const GrBackendTexture& tex, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 34 | GrSurfaceOrigin origin, |
Brian Osman | c1e3705 | 2017-03-09 14:19:20 -0500 | [diff] [blame] | 35 | sk_sp<SkColorSpace> colorSpace); |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 36 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 37 | sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext( |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 38 | const GrBackendTexture& tex, |
| 39 | GrSurfaceOrigin origin, |
| 40 | int sampleCnt, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 41 | sk_sp<SkColorSpace> colorSpace, |
Brian Osman | c1e3705 | 2017-03-09 14:19:20 -0500 | [diff] [blame] | 42 | const SkSurfaceProps* = nullptr); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 43 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 44 | sk_sp<GrRenderTargetContext> makeBackendRenderTargetRenderTargetContext( |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 45 | const GrBackendRenderTarget&, |
| 46 | GrSurfaceOrigin origin, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 47 | sk_sp<SkColorSpace> colorSpace, |
| 48 | const SkSurfaceProps* = nullptr); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 49 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 50 | sk_sp<GrRenderTargetContext> makeBackendTextureAsRenderTargetRenderTargetContext( |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 51 | const GrBackendTexture& tex, |
| 52 | GrSurfaceOrigin origin, |
| 53 | int sampleCnt, |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 54 | sk_sp<SkColorSpace> colorSpace, |
| 55 | const SkSurfaceProps* = nullptr); |
| 56 | |
Brian Osman | 46da1cc | 2017-02-14 14:15:48 -0500 | [diff] [blame] | 57 | bool disableGpuYUVConversion() const { return fContext->fDisableGpuYUVConversion; } |
| 58 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 59 | /** |
| 60 | * Call to ensure all drawing to the context has been issued to the |
| 61 | * underlying 3D API. |
| 62 | * The 'proxy' parameter is a hint. If it is supplied the context will guarantee that |
| 63 | * the draws required for that proxy are flushed but it could do more. If no 'proxy' is |
| 64 | * provided then all current work will be flushed. |
| 65 | */ |
| 66 | void flush(GrSurfaceProxy*); |
| 67 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 68 | /** |
| 69 | * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.) |
| 70 | * |
| 71 | * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to |
| 72 | * ensure its lifetime is tied to that of the context. |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 73 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 74 | void addOnFlushCallbackObject(GrOnFlushCallbackObject*); |
| 75 | |
| 76 | void testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject*); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 77 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 78 | /** |
| 79 | * After this returns any pending writes to the surface will have been issued to the |
| 80 | * backend 3D API. |
| 81 | */ |
| 82 | void flushSurfaceWrites(GrSurfaceProxy*); |
| 83 | |
| 84 | /** |
| 85 | * After this returns any pending reads or writes to the surface will have been issued to the |
| 86 | * backend 3D API. |
| 87 | */ |
| 88 | void flushSurfaceIO(GrSurfaceProxy*); |
| 89 | |
| 90 | /** |
| 91 | * Finalizes all pending reads and writes to the surface and also performs an MSAA resolve |
| 92 | * if necessary. |
| 93 | * |
| 94 | * It is not necessary to call this before reading the render target via Skia/GrContext. |
| 95 | * GrContext will detect when it must perform a resolve before reading pixels back from the |
| 96 | * surface or using it as a texture. |
| 97 | */ |
| 98 | void prepareSurfaceForExternalIO(GrSurfaceProxy*); |
| 99 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 100 | /** |
| 101 | * These flags can be used with the read/write pixels functions below. |
| 102 | */ |
| 103 | enum PixelOpsFlags { |
| 104 | /** The GrContext will not be flushed before the surface read or write. This means that |
| 105 | the read or write may occur before previous draws have executed. */ |
| 106 | kDontFlush_PixelOpsFlag = 0x1, |
| 107 | /** Any surface writes should be flushed to the backend 3D API after the surface operation |
| 108 | is complete */ |
| 109 | kFlushWrites_PixelOp = 0x2, |
| 110 | /** The src for write or dst read is unpremultiplied. This is only respected if both the |
| 111 | config src and dst configs are an RGBA/BGRA 8888 format. */ |
| 112 | kUnpremul_PixelOpsFlag = 0x4, |
| 113 | }; |
| 114 | |
| 115 | /** |
| 116 | * Reads a rectangle of pixels from a surface. |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 117 | * @param src the surface context to read from. |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 118 | * @param left left edge of the rectangle to read (inclusive) |
| 119 | * @param top top edge of the rectangle to read (inclusive) |
| 120 | * @param width width of rectangle to read in pixels. |
| 121 | * @param height height of rectangle to read in pixels. |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 122 | * @param dstConfig the pixel config of the destination buffer |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 123 | * @param dstColorSpace color space of the destination buffer |
| 124 | * @param buffer memory to read the rectangle into. |
| 125 | * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly |
| 126 | * packed. |
| 127 | * @param pixelOpsFlags see PixelOpsFlags enum above. |
| 128 | * |
| 129 | * @return true if the read succeeded, false if not. The read can fail because of an unsupported |
| 130 | * pixel configs |
| 131 | */ |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 132 | bool readSurfacePixels(GrSurfaceContext* src, |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 133 | int left, int top, int width, int height, |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 134 | GrPixelConfig dstConfig, SkColorSpace* dstColorSpace, void* buffer, |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 135 | size_t rowBytes = 0, |
| 136 | uint32_t pixelOpsFlags = 0); |
| 137 | |
| 138 | /** |
| 139 | * Writes a rectangle of pixels to a surface. |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 140 | * @param dst the surface context to write to. |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 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. |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 145 | * @param srcConfig the pixel config of the source buffer |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 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 | */ |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 154 | bool writeSurfacePixels(GrSurfaceContext* dst, |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 155 | int left, int top, int width, int height, |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 156 | GrPixelConfig srcConfig, SkColorSpace* srcColorSpace, const void* buffer, |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 157 | size_t rowBytes, |
| 158 | uint32_t pixelOpsFlags = 0); |
| 159 | |
Greg Daniel | fc978fd | 2017-04-13 09:54:12 -0400 | [diff] [blame] | 160 | GrBackend getBackend() const { return fContext->fBackend; } |
| 161 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 162 | private: |
| 163 | explicit GrContextPriv(GrContext* context) : fContext(context) {} |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 164 | GrContextPriv(const GrContextPriv&); // unimpl |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 165 | GrContextPriv& operator=(const GrContextPriv&); // unimpl |
| 166 | |
| 167 | // No taking addresses of this type. |
| 168 | const GrContextPriv* operator&() const; |
| 169 | GrContextPriv* operator&(); |
| 170 | |
| 171 | GrContext* fContext; |
| 172 | |
| 173 | friend class GrContext; // to construct/copy this type. |
| 174 | }; |
| 175 | |
| 176 | inline GrContextPriv GrContext::contextPriv() { return GrContextPriv(this); } |
| 177 | |
| 178 | inline const GrContextPriv GrContext::contextPriv () const { |
| 179 | return GrContextPriv(const_cast<GrContext*>(this)); |
| 180 | } |
| 181 | |
| 182 | #endif |