Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [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 GrSurfaceContext_DEFINED |
| 9 | #define GrSurfaceContext_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkRefCnt.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/gpu/GrColorSpaceInfo.h" |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrDataUtils.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrSurfaceProxy.h" |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 15 | |
| 16 | class GrAuditTrail; |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 17 | class GrDrawingManager; |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 18 | class GrOpList; |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 19 | class GrRecordingContext; |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 20 | class GrRenderTargetContext; |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 21 | class GrRenderTargetProxy; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 22 | class GrSingleOwner; |
| 23 | class GrSurface; |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 24 | class GrSurfaceContextPriv; |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 25 | class GrSurfaceProxy; |
| 26 | class GrTextureProxy; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 27 | struct SkIPoint; |
| 28 | struct SkIRect; |
| 29 | |
| 30 | /** |
| 31 | * A helper object to orchestrate commands for a particular surface |
| 32 | */ |
| 33 | class SK_API GrSurfaceContext : public SkRefCnt { |
| 34 | public: |
| 35 | ~GrSurfaceContext() override {} |
| 36 | |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 37 | const GrColorSpaceInfo& colorSpaceInfo() const { return fColorSpaceInfo; } |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 38 | |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 39 | // TODO: these two calls would be way cooler if this object had a GrSurfaceProxy pointer |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 40 | int width() const { return this->asSurfaceProxy()->width(); } |
| 41 | int height() const { return this->asSurfaceProxy()->height(); } |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 42 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 43 | /** |
| 44 | * Reads a rectangle of pixels from the render target context. |
| 45 | * @param dstInfo image info for the destination |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 46 | * @param dst destination pixels for the read |
| 47 | * @param rowBytes bytes in a row of 'dst' |
| 48 | * @param srcPt offset w/in the surface context from which to read |
| 49 | * @param direct The direct context to use. If null will use our GrRecordingContext if it |
| 50 | * is a GrDirectContext and fail otherwise. |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 51 | */ |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 52 | bool readPixels(const GrPixelInfo& dstInfo, void* dst, size_t rowBytes, SkIPoint srcPt, |
| 53 | GrContext* direct = nullptr); |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 54 | |
| 55 | /** |
Robert Phillips | b726d58 | 2017-03-09 16:36:32 -0500 | [diff] [blame] | 56 | * Writes a rectangle of pixels [srcInfo, srcBuffer, srcRowbytes] into the |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 57 | * renderTargetContext at the specified position. |
| 58 | * @param srcInfo image info for the source pixels |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 59 | * @param src source for the write |
| 60 | * @param rowBytes bytes in a row of 'src' |
| 61 | * @param dstPt offset w/in the surface context at which to write |
| 62 | * @param direct The direct context to use. If null will use our GrRecordingContext if it |
| 63 | * is a GrDirectContext and fail otherwise. |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 64 | */ |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 65 | bool writePixels(const GrPixelInfo& srcInfo, const void* src, size_t rowBytes, SkIPoint dstPt, |
| 66 | GrContext* direct = nullptr); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 67 | |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 68 | // TODO: this is virtual b.c. this object doesn't have a pointer to the wrapped GrSurfaceProxy? |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 69 | virtual GrSurfaceProxy* asSurfaceProxy() = 0; |
| 70 | virtual const GrSurfaceProxy* asSurfaceProxy() const = 0; |
| 71 | virtual sk_sp<GrSurfaceProxy> asSurfaceProxyRef() = 0; |
| 72 | |
| 73 | virtual GrTextureProxy* asTextureProxy() = 0; |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 74 | virtual const GrTextureProxy* asTextureProxy() const = 0; |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 75 | virtual sk_sp<GrTextureProxy> asTextureProxyRef() = 0; |
| 76 | |
| 77 | virtual GrRenderTargetProxy* asRenderTargetProxy() = 0; |
| 78 | virtual sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() = 0; |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 79 | |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 80 | virtual GrRenderTargetContext* asRenderTargetContext() { return nullptr; } |
| 81 | |
Robert Phillips | 0d075de | 2019-03-04 11:08:13 -0500 | [diff] [blame] | 82 | GrAuditTrail* auditTrail(); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 83 | |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 84 | // Provides access to functions that aren't part of the public API. |
| 85 | GrSurfaceContextPriv surfPriv(); |
| 86 | const GrSurfaceContextPriv surfPriv() const; |
| 87 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 88 | #if GR_TEST_UTILS |
| 89 | bool testCopy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) { |
| 90 | return this->copy(src, srcRect, dstPoint); |
| 91 | } |
| 92 | |
| 93 | bool testCopy(GrSurfaceProxy* src) { |
| 94 | return this->copy(src); |
| 95 | } |
| 96 | #endif |
| 97 | |
| 98 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 99 | protected: |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 100 | friend class GrSurfaceContextPriv; |
| 101 | |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 102 | GrSurfaceContext(GrRecordingContext*, |
| 103 | GrColorType, |
| 104 | SkAlphaType, |
| 105 | sk_sp<SkColorSpace>, |
| 106 | GrPixelConfig); |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 107 | |
Robert Phillips | 0d075de | 2019-03-04 11:08:13 -0500 | [diff] [blame] | 108 | GrDrawingManager* drawingManager(); |
| 109 | const GrDrawingManager* drawingManager() const; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 110 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 111 | virtual GrOpList* getOpList() = 0; |
| 112 | SkDEBUGCODE(virtual void validate() const = 0;) |
| 113 | |
Robert Phillips | 0d075de | 2019-03-04 11:08:13 -0500 | [diff] [blame] | 114 | SkDEBUGCODE(GrSingleOwner* singleOwner();) |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 115 | |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 116 | GrRecordingContext* fContext; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 117 | |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 118 | private: |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 119 | friend class GrSurfaceProxy; // for copy |
| 120 | |
| 121 | /** |
| 122 | * Copy 'src' into the proxy backing this context. This call will not do any draw fallback. |
| 123 | * Currently only writePixels and replaceRenderTarget call this directly. All other copies |
| 124 | * should go through GrSurfaceProxy::Copy. |
| 125 | * @param src src of pixels |
| 126 | * @param srcRect the subset of 'src' to copy |
| 127 | * @param dstPoint the origin of the 'srcRect' in the destination coordinate space |
| 128 | * @return true if the copy succeeded; false otherwise |
| 129 | * |
| 130 | * Note: Notionally, 'srcRect' is clipped to 'src's extent with 'dstPoint' being adjusted. |
| 131 | * Then the 'srcRect' offset by 'dstPoint' is clipped against the dst's extent. |
| 132 | * The end result is only valid src pixels and dst pixels will be touched but the copied |
| 133 | * regions will not be shifted. The 'src' must have the same origin as the backing proxy |
| 134 | * of fSurfaceContext. |
| 135 | */ |
| 136 | bool copy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint); |
| 137 | |
| 138 | bool copy(GrSurfaceProxy* src) { |
| 139 | return this->copy(src, SkIRect::MakeWH(src->width(), src->height()), SkIPoint::Make(0, 0)); |
| 140 | } |
| 141 | |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 142 | GrColorSpaceInfo fColorSpaceInfo; |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 143 | |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 144 | typedef SkRefCnt INHERITED; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | #endif |