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 | d85f97d | 2017-03-07 13:37:21 -0500 | [diff] [blame] | 14 | class GrSemaphore; |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 15 | class GrSurfaceProxy; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 16 | class GrPreFlushCallbackObject; |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 17 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 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: |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 23 | GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); } |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 24 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 25 | // Create a renderTargetContext that wraps an existing renderTarget |
| 26 | sk_sp<GrRenderTargetContext> makeWrappedRenderTargetContext(sk_sp<GrRenderTarget> rt, |
| 27 | sk_sp<SkColorSpace> colorSpace, |
| 28 | const SkSurfaceProps* = nullptr); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 29 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 30 | // Create a surfaceContext that wraps an existing texture or renderTarget |
| 31 | sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurface> tex); |
| 32 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 33 | sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy> proxy, |
| 34 | sk_sp<SkColorSpace>); |
Robert Phillips | 31c2608 | 2016-12-14 15:12:15 -0500 | [diff] [blame] | 35 | |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 36 | sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc& dstDesc, |
| 37 | SkBackingFit dstFit, |
| 38 | SkBudgeted isDstBudgeted); |
| 39 | |
Robert Phillips | 26caf89 | 2017-01-27 10:58:31 -0500 | [diff] [blame] | 40 | // TODO: Maybe add a 'surfaceProps' param (that is ignored for non-RTs) and remove |
| 41 | // makeBackendTextureRenderTargetContext & makeBackendTextureAsRenderTargetRenderTargetContext |
| 42 | sk_sp<GrSurfaceContext> makeBackendSurfaceContext(const GrBackendTextureDesc& desc, |
Brian Osman | c1e3705 | 2017-03-09 14:19:20 -0500 | [diff] [blame] | 43 | sk_sp<SkColorSpace> colorSpace); |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 44 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 45 | sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext( |
| 46 | const GrBackendTextureDesc& desc, |
| 47 | sk_sp<SkColorSpace> colorSpace, |
Brian Osman | c1e3705 | 2017-03-09 14:19:20 -0500 | [diff] [blame] | 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> makeBackendRenderTargetRenderTargetContext( |
| 51 | const GrBackendRenderTargetDesc& desc, |
| 52 | sk_sp<SkColorSpace> colorSpace, |
| 53 | const SkSurfaceProps* = nullptr); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 54 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 55 | sk_sp<GrRenderTargetContext> makeBackendTextureAsRenderTargetRenderTargetContext( |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 56 | const GrBackendTextureDesc& desc, |
| 57 | sk_sp<SkColorSpace> colorSpace, |
| 58 | const SkSurfaceProps* = nullptr); |
| 59 | |
Brian Osman | 46da1cc | 2017-02-14 14:15:48 -0500 | [diff] [blame] | 60 | bool disableGpuYUVConversion() const { return fContext->fDisableGpuYUVConversion; } |
| 61 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 62 | /** |
| 63 | * Call to ensure all drawing to the context has been issued to the |
| 64 | * underlying 3D API. |
| 65 | * The 'proxy' parameter is a hint. If it is supplied the context will guarantee that |
| 66 | * the draws required for that proxy are flushed but it could do more. If no 'proxy' is |
| 67 | * provided then all current work will be flushed. |
| 68 | */ |
| 69 | void flush(GrSurfaceProxy*); |
| 70 | |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 71 | /* |
| 72 | * A ref will be taken on the preFlushCallbackObject which will be removed when the |
| 73 | * context is destroyed. |
| 74 | */ |
| 75 | void addPreFlushCallbackObject(sk_sp<GrPreFlushCallbackObject>); |
| 76 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 77 | /** |
| 78 | * After this returns any pending writes to the surface will have been issued to the |
| 79 | * backend 3D API. |
| 80 | */ |
| 81 | void flushSurfaceWrites(GrSurfaceProxy*); |
| 82 | |
| 83 | /** |
| 84 | * After this returns any pending reads or writes to the surface will have been issued to the |
| 85 | * backend 3D API. |
| 86 | */ |
| 87 | void flushSurfaceIO(GrSurfaceProxy*); |
| 88 | |
| 89 | /** |
| 90 | * Finalizes all pending reads and writes to the surface and also performs an MSAA resolve |
| 91 | * if necessary. |
| 92 | * |
| 93 | * It is not necessary to call this before reading the render target via Skia/GrContext. |
| 94 | * GrContext will detect when it must perform a resolve before reading pixels back from the |
| 95 | * surface or using it as a texture. |
| 96 | */ |
| 97 | void prepareSurfaceForExternalIO(GrSurfaceProxy*); |
| 98 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 99 | private: |
| 100 | explicit GrContextPriv(GrContext* context) : fContext(context) {} |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 101 | GrContextPriv(const GrContextPriv&); // unimpl |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 102 | GrContextPriv& operator=(const GrContextPriv&); // unimpl |
| 103 | |
| 104 | // No taking addresses of this type. |
| 105 | const GrContextPriv* operator&() const; |
| 106 | GrContextPriv* operator&(); |
| 107 | |
| 108 | GrContext* fContext; |
| 109 | |
| 110 | friend class GrContext; // to construct/copy this type. |
| 111 | }; |
| 112 | |
| 113 | inline GrContextPriv GrContext::contextPriv() { return GrContextPriv(this); } |
| 114 | |
| 115 | inline const GrContextPriv GrContext::contextPriv () const { |
| 116 | return GrContextPriv(const_cast<GrContext*>(this)); |
| 117 | } |
| 118 | |
| 119 | #endif |