blob: 0f77ec2d4c87b30f3ba4bce039d7c45cbaddd1e9 [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"
robertphillips4fd74ae2016-08-03 14:26:53 -070013
Greg Danield85f97d2017-03-07 13:37:21 -050014class GrSemaphore;
Robert Phillipse2f7d182016-12-15 09:23:05 -050015class GrSurfaceProxy;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040016class GrPreFlushCallbackObject;
Robert Phillipse2f7d182016-12-15 09:23:05 -050017
robertphillips4fd74ae2016-08-03 14:26:53 -070018/** 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. */
21class GrContextPriv {
22public:
bungeman6bd52842016-10-27 09:30:08 -070023 GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); }
csmartdaltonbde96c62016-08-31 12:54:46 -070024
Brian Osman11052242016-10-27 14:47:55 -040025 // 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);
robertphillips4fd74ae2016-08-03 14:26:53 -070029
Brian Osman45580d32016-11-23 09:37:01 -050030 // Create a surfaceContext that wraps an existing texture or renderTarget
31 sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurface> tex);
32
Robert Phillips2c862492017-01-18 10:08:39 -050033 sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy> proxy,
34 sk_sp<SkColorSpace>);
Robert Phillips31c26082016-12-14 15:12:15 -050035
Robert Phillipse305cc1f2016-12-14 12:19:05 -050036 sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc& dstDesc,
37 SkBackingFit dstFit,
38 SkBudgeted isDstBudgeted);
39
Robert Phillips26caf892017-01-27 10:58:31 -050040 // 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 Osmanc1e37052017-03-09 14:19:20 -050043 sk_sp<SkColorSpace> colorSpace);
Robert Phillipsd46697a2017-01-25 12:10:37 -050044
Brian Osman11052242016-10-27 14:47:55 -040045 sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext(
46 const GrBackendTextureDesc& desc,
47 sk_sp<SkColorSpace> colorSpace,
Brian Osmanc1e37052017-03-09 14:19:20 -050048 const SkSurfaceProps* = nullptr);
robertphillips4fd74ae2016-08-03 14:26:53 -070049
Brian Osman11052242016-10-27 14:47:55 -040050 sk_sp<GrRenderTargetContext> makeBackendRenderTargetRenderTargetContext(
51 const GrBackendRenderTargetDesc& desc,
52 sk_sp<SkColorSpace> colorSpace,
53 const SkSurfaceProps* = nullptr);
robertphillips4fd74ae2016-08-03 14:26:53 -070054
Brian Osman11052242016-10-27 14:47:55 -040055 sk_sp<GrRenderTargetContext> makeBackendTextureAsRenderTargetRenderTargetContext(
robertphillips4fd74ae2016-08-03 14:26:53 -070056 const GrBackendTextureDesc& desc,
57 sk_sp<SkColorSpace> colorSpace,
58 const SkSurfaceProps* = nullptr);
59
Brian Osman46da1cc2017-02-14 14:15:48 -050060 bool disableGpuYUVConversion() const { return fContext->fDisableGpuYUVConversion; }
61
Robert Phillips7ee385e2017-03-30 08:02:11 -040062 /**
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 Phillipseb35f4d2017-03-21 07:56:47 -040071 /*
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 Phillips7ee385e2017-03-30 08:02:11 -040077 /**
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
robertphillips4fd74ae2016-08-03 14:26:53 -070099private:
100 explicit GrContextPriv(GrContext* context) : fContext(context) {}
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400101 GrContextPriv(const GrContextPriv&); // unimpl
robertphillips4fd74ae2016-08-03 14:26:53 -0700102 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
113inline GrContextPriv GrContext::contextPriv() { return GrContextPriv(this); }
114
115inline const GrContextPriv GrContext::contextPriv () const {
116 return GrContextPriv(const_cast<GrContext*>(this));
117}
118
119#endif