blob: cdd04b4dbf2f9b578bec8cd6cffec610f3328955 [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 Danielbcf612b2017-05-01 13:50:58 +000014class GrBackendRenderTarget;
Brian Salomond17f6582017-07-19 18:28:58 -040015class GrOnFlushCallbackObject;
Greg Danield85f97d2017-03-07 13:37:21 -050016class GrSemaphore;
Robert Phillipse2f7d182016-12-15 09:23:05 -050017class GrSurfaceProxy;
Brian Salomond17f6582017-07-19 18:28:58 -040018class GrTextureContext;
Robert Phillipse2f7d182016-12-15 09:23:05 -050019
robertphillips4fd74ae2016-08-03 14:26:53 -070020/** 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. */
23class GrContextPriv {
24public:
bungeman6bd52842016-10-27 09:30:08 -070025 GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); }
csmartdaltonbde96c62016-08-31 12:54:46 -070026
Robert Phillipsbf25d432017-04-07 10:08:53 -040027 sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>, sk_sp<SkColorSpace>);
Robert Phillips31c26082016-12-14 15:12:15 -050028
Robert Phillipsbf25d432017-04-07 10:08:53 -040029 sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc&,
Greg Daniel65c7f662017-10-30 13:39:09 -040030 GrMipMapped,
Robert Phillipsbf25d432017-04-07 10:08:53 -040031 SkBackingFit,
32 SkBudgeted);
Robert Phillipse305cc1f2016-12-14 12:19:05 -050033
Brian Salomond17f6582017-07-19 18:28:58 -040034 sk_sp<GrTextureContext> makeBackendTextureContext(const GrBackendTexture& tex,
Greg Daniel7ef28f32017-04-20 16:41:55 +000035 GrSurfaceOrigin origin,
Brian Osmanc1e37052017-03-09 14:19:20 -050036 sk_sp<SkColorSpace> colorSpace);
Robert Phillipsd46697a2017-01-25 12:10:37 -050037
Brian Osman11052242016-10-27 14:47:55 -040038 sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext(
Greg Daniel7ef28f32017-04-20 16:41:55 +000039 const GrBackendTexture& tex,
40 GrSurfaceOrigin origin,
41 int sampleCnt,
Brian Osman11052242016-10-27 14:47:55 -040042 sk_sp<SkColorSpace> colorSpace,
Brian Osmanc1e37052017-03-09 14:19:20 -050043 const SkSurfaceProps* = nullptr);
robertphillips4fd74ae2016-08-03 14:26:53 -070044
Brian Osman11052242016-10-27 14:47:55 -040045 sk_sp<GrRenderTargetContext> makeBackendRenderTargetRenderTargetContext(
Greg Danielbcf612b2017-05-01 13:50:58 +000046 const GrBackendRenderTarget&,
47 GrSurfaceOrigin origin,
Brian Osman11052242016-10-27 14:47:55 -040048 sk_sp<SkColorSpace> colorSpace,
49 const SkSurfaceProps* = nullptr);
robertphillips4fd74ae2016-08-03 14:26:53 -070050
Brian Osman11052242016-10-27 14:47:55 -040051 sk_sp<GrRenderTargetContext> makeBackendTextureAsRenderTargetRenderTargetContext(
Greg Daniel7ef28f32017-04-20 16:41:55 +000052 const GrBackendTexture& tex,
53 GrSurfaceOrigin origin,
54 int sampleCnt,
robertphillips4fd74ae2016-08-03 14:26:53 -070055 sk_sp<SkColorSpace> colorSpace,
56 const SkSurfaceProps* = nullptr);
57
Brian Osman46da1cc2017-02-14 14:15:48 -050058 bool disableGpuYUVConversion() const { return fContext->fDisableGpuYUVConversion; }
59
Robert Phillips7ee385e2017-03-30 08:02:11 -040060 /**
61 * Call to ensure all drawing to the context has been issued to the
62 * underlying 3D API.
63 * The 'proxy' parameter is a hint. If it is supplied the context will guarantee that
64 * the draws required for that proxy are flushed but it could do more. If no 'proxy' is
65 * provided then all current work will be flushed.
66 */
67 void flush(GrSurfaceProxy*);
68
Chris Daltonfe199b72017-05-05 11:26:15 -040069 /**
70 * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
71 *
72 * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
73 * ensure its lifetime is tied to that of the context.
Robert Phillipseb35f4d2017-03-21 07:56:47 -040074 */
Chris Daltonfe199b72017-05-05 11:26:15 -040075 void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
76
77 void testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject*);
Robert Phillipseb35f4d2017-03-21 07:56:47 -040078
Robert Phillips7ee385e2017-03-30 08:02:11 -040079 /**
80 * After this returns any pending writes to the surface will have been issued to the
81 * backend 3D API.
82 */
83 void flushSurfaceWrites(GrSurfaceProxy*);
84
85 /**
86 * After this returns any pending reads or writes to the surface will have been issued to the
87 * backend 3D API.
88 */
89 void flushSurfaceIO(GrSurfaceProxy*);
90
91 /**
92 * Finalizes all pending reads and writes to the surface and also performs an MSAA resolve
93 * if necessary.
94 *
95 * It is not necessary to call this before reading the render target via Skia/GrContext.
96 * GrContext will detect when it must perform a resolve before reading pixels back from the
97 * surface or using it as a texture.
98 */
99 void prepareSurfaceForExternalIO(GrSurfaceProxy*);
100
Robert Phillipse78b7252017-04-06 07:59:41 -0400101 /**
102 * These flags can be used with the read/write pixels functions below.
103 */
104 enum PixelOpsFlags {
105 /** The GrContext will not be flushed before the surface read or write. This means that
106 the read or write may occur before previous draws have executed. */
107 kDontFlush_PixelOpsFlag = 0x1,
108 /** Any surface writes should be flushed to the backend 3D API after the surface operation
109 is complete */
110 kFlushWrites_PixelOp = 0x2,
111 /** The src for write or dst read is unpremultiplied. This is only respected if both the
112 config src and dst configs are an RGBA/BGRA 8888 format. */
113 kUnpremul_PixelOpsFlag = 0x4,
114 };
115
116 /**
117 * Reads a rectangle of pixels from a surface.
Robert Phillipsf41c22f2017-04-18 07:48:58 -0400118 * @param src the surface context to read from.
Robert Phillipse78b7252017-04-06 07:59:41 -0400119 * @param left left edge of the rectangle to read (inclusive)
120 * @param top top edge of the rectangle to read (inclusive)
121 * @param width width of rectangle to read in pixels.
122 * @param height height of rectangle to read in pixels.
Robert Phillipsf41c22f2017-04-18 07:48:58 -0400123 * @param dstConfig the pixel config of the destination buffer
Robert Phillipse78b7252017-04-06 07:59:41 -0400124 * @param dstColorSpace color space of the destination buffer
125 * @param buffer memory to read the rectangle into.
126 * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly
127 * packed.
128 * @param pixelOpsFlags see PixelOpsFlags enum above.
129 *
130 * @return true if the read succeeded, false if not. The read can fail because of an unsupported
131 * pixel configs
132 */
Robert Phillipsf41c22f2017-04-18 07:48:58 -0400133 bool readSurfacePixels(GrSurfaceContext* src,
Robert Phillipse78b7252017-04-06 07:59:41 -0400134 int left, int top, int width, int height,
Robert Phillipsf41c22f2017-04-18 07:48:58 -0400135 GrPixelConfig dstConfig, SkColorSpace* dstColorSpace, void* buffer,
Robert Phillipse78b7252017-04-06 07:59:41 -0400136 size_t rowBytes = 0,
137 uint32_t pixelOpsFlags = 0);
138
139 /**
140 * Writes a rectangle of pixels to a surface.
Robert Phillipsf41c22f2017-04-18 07:48:58 -0400141 * @param dst the surface context to write to.
Robert Phillipse78b7252017-04-06 07:59:41 -0400142 * @param left left edge of the rectangle to write (inclusive)
143 * @param top top edge of the rectangle to write (inclusive)
144 * @param width width of rectangle to write in pixels.
145 * @param height height of rectangle to write in pixels.
Robert Phillipsf41c22f2017-04-18 07:48:58 -0400146 * @param srcConfig the pixel config of the source buffer
Robert Phillipse78b7252017-04-06 07:59:41 -0400147 * @param srcColorSpace color space of the source buffer
148 * @param buffer memory to read pixels from
149 * @param rowBytes number of bytes between consecutive rows. Zero
150 * means rows are tightly packed.
151 * @param pixelOpsFlags see PixelOpsFlags enum above.
152 * @return true if the write succeeded, false if not. The write can fail because of an
153 * unsupported combination of surface and src configs.
154 */
Robert Phillipsf41c22f2017-04-18 07:48:58 -0400155 bool writeSurfacePixels(GrSurfaceContext* dst,
Robert Phillipse78b7252017-04-06 07:59:41 -0400156 int left, int top, int width, int height,
Robert Phillipsf41c22f2017-04-18 07:48:58 -0400157 GrPixelConfig srcConfig, SkColorSpace* srcColorSpace, const void* buffer,
Robert Phillipse78b7252017-04-06 07:59:41 -0400158 size_t rowBytes,
159 uint32_t pixelOpsFlags = 0);
160
Greg Danielfc978fd2017-04-13 09:54:12 -0400161 GrBackend getBackend() const { return fContext->fBackend; }
162
Brian Osman51279982017-08-23 10:12:00 -0400163 SkTaskGroup* getTaskGroup() { return fContext->fTaskGroup.get(); }
164
robertphillips4fd74ae2016-08-03 14:26:53 -0700165private:
166 explicit GrContextPriv(GrContext* context) : fContext(context) {}
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400167 GrContextPriv(const GrContextPriv&); // unimpl
robertphillips4fd74ae2016-08-03 14:26:53 -0700168 GrContextPriv& operator=(const GrContextPriv&); // unimpl
169
170 // No taking addresses of this type.
171 const GrContextPriv* operator&() const;
172 GrContextPriv* operator&();
173
174 GrContext* fContext;
175
176 friend class GrContext; // to construct/copy this type.
177};
178
179inline GrContextPriv GrContext::contextPriv() { return GrContextPriv(this); }
180
181inline const GrContextPriv GrContext::contextPriv () const {
182 return GrContextPriv(const_cast<GrContext*>(this));
183}
184
185#endif