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 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 11 | #include "../private/GrSurfaceProxy.h" |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 12 | #include "GrColorSpaceInfo.h" |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 13 | #include "SkRefCnt.h" |
| 14 | |
| 15 | class GrAuditTrail; |
| 16 | class GrContext; |
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 | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 19 | class GrRenderTargetContext; |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 20 | class GrRenderTargetProxy; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 21 | class GrSingleOwner; |
| 22 | class GrSurface; |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 23 | class GrSurfaceContextPriv; |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 24 | class GrSurfaceProxy; |
| 25 | class GrTextureProxy; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 26 | struct SkIPoint; |
| 27 | struct SkIRect; |
| 28 | |
| 29 | /** |
| 30 | * A helper object to orchestrate commands for a particular surface |
| 31 | */ |
| 32 | class SK_API GrSurfaceContext : public SkRefCnt { |
| 33 | public: |
| 34 | ~GrSurfaceContext() override {} |
| 35 | |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 36 | const GrColorSpaceInfo& colorSpaceInfo() const { return fColorSpaceInfo; } |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 37 | |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 38 | // 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] | 39 | int width() const { return this->asSurfaceProxy()->width(); } |
| 40 | int height() const { return this->asSurfaceProxy()->height(); } |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 41 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 42 | /* |
| 43 | * Copy 'src' into the proxy backing this context |
| 44 | * @param src src of pixels |
| 45 | * @param srcRect the subset of 'src' to copy |
| 46 | * @param dstPoint the origin of the 'srcRect' in the destination coordinate space |
| 47 | * @return true if the copy succeeded; false otherwise |
| 48 | * |
| 49 | * Note: Notionally, 'srcRect' is clipped to 'src's extent with 'dstPoint' being adjusted. |
| 50 | * Then the 'srcRect' offset by 'dstPoint' is clipped against the dst's extent. |
| 51 | * The end result is only valid src pixels and dst pixels will be touched but the copied |
| 52 | * regions will not be shifted. |
| 53 | */ |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 54 | bool copy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint); |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 55 | |
| 56 | bool copy(GrSurfaceProxy* src) { |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 57 | return this->copy(src, |
| 58 | SkIRect::MakeWH(src->width(), src->height()), |
| 59 | SkIPoint::Make(0, 0)); |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 60 | } |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 61 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 62 | /** |
| 63 | * Reads a rectangle of pixels from the render target context. |
| 64 | * @param dstInfo image info for the destination |
| 65 | * @param dstBuffer destination pixels for the read |
| 66 | * @param dstRowBytes bytes in a row of 'dstBuffer' |
| 67 | * @param x x offset w/in the render target context from which to read |
| 68 | * @param y y offset w/in the render target context from which to read |
| 69 | * |
| 70 | * @return true if the read succeeded, false if not. The read can fail because of an |
| 71 | * unsupported pixel config. |
| 72 | */ |
| 73 | bool readPixels(const SkImageInfo& dstInfo, void* dstBuffer, size_t dstRowBytes, |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 74 | int x, int y, uint32_t flags = 0); |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 75 | |
| 76 | /** |
Robert Phillips | b726d58 | 2017-03-09 16:36:32 -0500 | [diff] [blame] | 77 | * Writes a rectangle of pixels [srcInfo, srcBuffer, srcRowbytes] into the |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 78 | * renderTargetContext at the specified position. |
| 79 | * @param srcInfo image info for the source pixels |
| 80 | * @param srcBuffer source for the write |
| 81 | * @param srcRowBytes bytes in a row of 'srcBuffer' |
| 82 | * @param x x offset w/in the render target context at which to write |
| 83 | * @param y y offset w/in the render target context at which to write |
| 84 | * |
| 85 | * @return true if the write succeeded, false if not. The write can fail because of an |
| 86 | * unsupported pixel config. |
| 87 | */ |
| 88 | bool writePixels(const SkImageInfo& srcInfo, const void* srcBuffer, size_t srcRowBytes, |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 89 | int x, int y, uint32_t flags = 0); |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 90 | |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 91 | // 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] | 92 | virtual GrSurfaceProxy* asSurfaceProxy() = 0; |
| 93 | virtual const GrSurfaceProxy* asSurfaceProxy() const = 0; |
| 94 | virtual sk_sp<GrSurfaceProxy> asSurfaceProxyRef() = 0; |
| 95 | |
| 96 | virtual GrTextureProxy* asTextureProxy() = 0; |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 97 | virtual const GrTextureProxy* asTextureProxy() const = 0; |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 98 | virtual sk_sp<GrTextureProxy> asTextureProxyRef() = 0; |
| 99 | |
| 100 | virtual GrRenderTargetProxy* asRenderTargetProxy() = 0; |
| 101 | virtual sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() = 0; |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 102 | |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 103 | virtual GrRenderTargetContext* asRenderTargetContext() { return nullptr; } |
| 104 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 105 | GrAuditTrail* auditTrail() { return fAuditTrail; } |
| 106 | |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 107 | // Provides access to functions that aren't part of the public API. |
| 108 | GrSurfaceContextPriv surfPriv(); |
| 109 | const GrSurfaceContextPriv surfPriv() const; |
| 110 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 111 | protected: |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 112 | friend class GrSurfaceContextPriv; |
| 113 | |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 114 | GrSurfaceContext(GrContext*, GrDrawingManager*, GrPixelConfig, sk_sp<SkColorSpace>, |
| 115 | GrAuditTrail*, GrSingleOwner*); |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 116 | |
| 117 | GrDrawingManager* drawingManager() { return fDrawingManager; } |
| 118 | const GrDrawingManager* drawingManager() const { return fDrawingManager; } |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 119 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 120 | virtual GrOpList* getOpList() = 0; |
| 121 | SkDEBUGCODE(virtual void validate() const = 0;) |
| 122 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 123 | SkDEBUGCODE(GrSingleOwner* singleOwner() { return fSingleOwner; }) |
| 124 | |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 125 | GrContext* fContext; |
| 126 | GrAuditTrail* fAuditTrail; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 127 | |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 128 | private: |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 129 | GrColorSpaceInfo fColorSpaceInfo; |
| 130 | |
| 131 | GrDrawingManager* fDrawingManager; |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 132 | |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 133 | // In debug builds we guard against improper thread handling |
| 134 | SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;) |
| 135 | |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 136 | typedef SkRefCnt INHERITED; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | #endif |