blob: 95df8eacc96a3d035ae0c88d7e4bd741f951f343 [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
Robert Phillipsbf25d432017-04-07 10:08:53 -040026 sk_sp<GrRenderTargetContext> makeWrappedRenderTargetContext(sk_sp<GrRenderTarget>,
27 sk_sp<SkColorSpace>,
Brian Osman11052242016-10-27 14:47:55 -040028 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
Robert Phillipsbf25d432017-04-07 10:08:53 -040031 sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurface>);
Brian Osman45580d32016-11-23 09:37:01 -050032
Robert Phillipsbf25d432017-04-07 10:08:53 -040033 sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>, sk_sp<SkColorSpace>);
Robert Phillips31c26082016-12-14 15:12:15 -050034
Robert Phillipsbf25d432017-04-07 10:08:53 -040035 sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc&,
36 SkBackingFit,
37 SkBudgeted);
Robert Phillipse305cc1f2016-12-14 12:19:05 -050038
Robert Phillips26caf892017-01-27 10:58:31 -050039 // TODO: Maybe add a 'surfaceProps' param (that is ignored for non-RTs) and remove
40 // makeBackendTextureRenderTargetContext & makeBackendTextureAsRenderTargetRenderTargetContext
41 sk_sp<GrSurfaceContext> makeBackendSurfaceContext(const GrBackendTextureDesc& desc,
Brian Osmanc1e37052017-03-09 14:19:20 -050042 sk_sp<SkColorSpace> colorSpace);
Robert Phillipsd46697a2017-01-25 12:10:37 -050043
Brian Osman11052242016-10-27 14:47:55 -040044 sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext(
45 const GrBackendTextureDesc& desc,
46 sk_sp<SkColorSpace> colorSpace,
Brian Osmanc1e37052017-03-09 14:19:20 -050047 const SkSurfaceProps* = nullptr);
robertphillips4fd74ae2016-08-03 14:26:53 -070048
Brian Osman11052242016-10-27 14:47:55 -040049 sk_sp<GrRenderTargetContext> makeBackendRenderTargetRenderTargetContext(
50 const GrBackendRenderTargetDesc& desc,
51 sk_sp<SkColorSpace> colorSpace,
52 const SkSurfaceProps* = nullptr);
robertphillips4fd74ae2016-08-03 14:26:53 -070053
Brian Osman11052242016-10-27 14:47:55 -040054 sk_sp<GrRenderTargetContext> makeBackendTextureAsRenderTargetRenderTargetContext(
robertphillips4fd74ae2016-08-03 14:26:53 -070055 const GrBackendTextureDesc& desc,
56 sk_sp<SkColorSpace> colorSpace,
57 const SkSurfaceProps* = nullptr);
58
Brian Osman46da1cc2017-02-14 14:15:48 -050059 bool disableGpuYUVConversion() const { return fContext->fDisableGpuYUVConversion; }
60
Robert Phillips7ee385e2017-03-30 08:02:11 -040061 /**
62 * Call to ensure all drawing to the context has been issued to the
63 * underlying 3D API.
64 * The 'proxy' parameter is a hint. If it is supplied the context will guarantee that
65 * the draws required for that proxy are flushed but it could do more. If no 'proxy' is
66 * provided then all current work will be flushed.
67 */
68 void flush(GrSurfaceProxy*);
69
Robert Phillipseb35f4d2017-03-21 07:56:47 -040070 /*
71 * A ref will be taken on the preFlushCallbackObject which will be removed when the
72 * context is destroyed.
73 */
74 void addPreFlushCallbackObject(sk_sp<GrPreFlushCallbackObject>);
75
Robert Phillips7ee385e2017-03-30 08:02:11 -040076 /**
77 * After this returns any pending writes to the surface will have been issued to the
78 * backend 3D API.
79 */
80 void flushSurfaceWrites(GrSurfaceProxy*);
81
82 /**
83 * After this returns any pending reads or writes to the surface will have been issued to the
84 * backend 3D API.
85 */
86 void flushSurfaceIO(GrSurfaceProxy*);
87
88 /**
89 * Finalizes all pending reads and writes to the surface and also performs an MSAA resolve
90 * if necessary.
91 *
92 * It is not necessary to call this before reading the render target via Skia/GrContext.
93 * GrContext will detect when it must perform a resolve before reading pixels back from the
94 * surface or using it as a texture.
95 */
96 void prepareSurfaceForExternalIO(GrSurfaceProxy*);
97
Robert Phillipse78b7252017-04-06 07:59:41 -040098 /**
99 * These flags can be used with the read/write pixels functions below.
100 */
101 enum PixelOpsFlags {
102 /** The GrContext will not be flushed before the surface read or write. This means that
103 the read or write may occur before previous draws have executed. */
104 kDontFlush_PixelOpsFlag = 0x1,
105 /** Any surface writes should be flushed to the backend 3D API after the surface operation
106 is complete */
107 kFlushWrites_PixelOp = 0x2,
108 /** The src for write or dst read is unpremultiplied. This is only respected if both the
109 config src and dst configs are an RGBA/BGRA 8888 format. */
110 kUnpremul_PixelOpsFlag = 0x4,
111 };
112
113 /**
114 * Reads a rectangle of pixels from a surface.
115 * @param surface the surface to read from.
116 * @param srcColorSpace color space of the surface
117 * @param left left edge of the rectangle to read (inclusive)
118 * @param top top edge of the rectangle to read (inclusive)
119 * @param width width of rectangle to read in pixels.
120 * @param height height of rectangle to read in pixels.
121 * @param config the pixel config of the destination buffer
122 * @param dstColorSpace color space of the destination buffer
123 * @param buffer memory to read the rectangle into.
124 * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly
125 * packed.
126 * @param pixelOpsFlags see PixelOpsFlags enum above.
127 *
128 * @return true if the read succeeded, false if not. The read can fail because of an unsupported
129 * pixel configs
130 */
131 bool readSurfacePixels(GrSurfaceProxy* src, SkColorSpace* srcColorSpace,
132 int left, int top, int width, int height,
133 GrPixelConfig config, SkColorSpace* dstColorSpace, void* buffer,
134 size_t rowBytes = 0,
135 uint32_t pixelOpsFlags = 0);
136
137 /**
138 * Writes a rectangle of pixels to a surface.
Robert Phillips1119dc32017-04-11 12:54:57 -0400139 * @param dst the surface to write to.
Robert Phillipse78b7252017-04-06 07:59:41 -0400140 * @param dstColorSpace color space of the surface
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.
145 * @param config the pixel config of the source buffer
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 Phillips1119dc32017-04-11 12:54:57 -0400154 bool writeSurfacePixels(GrSurfaceProxy* dst, SkColorSpace* dstColorSpace,
Robert Phillipse78b7252017-04-06 07:59:41 -0400155 int left, int top, int width, int height,
156 GrPixelConfig config, SkColorSpace* srcColorSpace, const void* buffer,
157 size_t rowBytes,
158 uint32_t pixelOpsFlags = 0);
159
robertphillips4fd74ae2016-08-03 14:26:53 -0700160private:
161 explicit GrContextPriv(GrContext* context) : fContext(context) {}
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400162 GrContextPriv(const GrContextPriv&); // unimpl
robertphillips4fd74ae2016-08-03 14:26:53 -0700163 GrContextPriv& operator=(const GrContextPriv&); // unimpl
164
165 // No taking addresses of this type.
166 const GrContextPriv* operator&() const;
167 GrContextPriv* operator&();
168
169 GrContext* fContext;
170
171 friend class GrContext; // to construct/copy this type.
172};
173
174inline GrContextPriv GrContext::contextPriv() { return GrContextPriv(this); }
175
176inline const GrContextPriv GrContext::contextPriv () const {
177 return GrContextPriv(const_cast<GrContext*>(this));
178}
179
180#endif