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" |
| 12 | |
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 | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 17 | class GrRenderTargetProxy; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 18 | class GrSingleOwner; |
| 19 | class GrSurface; |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 20 | class GrSurfaceContextPriv; |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 21 | class GrSurfaceProxy; |
| 22 | class GrTextureProxy; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 23 | struct SkIPoint; |
| 24 | struct SkIRect; |
| 25 | |
| 26 | /** |
| 27 | * A helper object to orchestrate commands for a particular surface |
| 28 | */ |
| 29 | class SK_API GrSurfaceContext : public SkRefCnt { |
| 30 | public: |
| 31 | ~GrSurfaceContext() override {} |
| 32 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 33 | /* |
| 34 | * Copy 'src' into the proxy backing this context |
| 35 | * @param src src of pixels |
| 36 | * @param srcRect the subset of 'src' to copy |
| 37 | * @param dstPoint the origin of the 'srcRect' in the destination coordinate space |
| 38 | * @return true if the copy succeeded; false otherwise |
| 39 | * |
| 40 | * Note: Notionally, 'srcRect' is clipped to 'src's extent with 'dstPoint' being adjusted. |
| 41 | * Then the 'srcRect' offset by 'dstPoint' is clipped against the dst's extent. |
| 42 | * The end result is only valid src pixels and dst pixels will be touched but the copied |
| 43 | * regions will not be shifted. |
| 44 | */ |
| 45 | bool copy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) { |
| 46 | return this->onCopy(src, srcRect, dstPoint); |
| 47 | } |
| 48 | |
| 49 | bool copy(GrSurfaceProxy* src) { |
| 50 | return this->onCopy(src, |
| 51 | SkIRect::MakeWH(src->width(), src->height()), |
| 52 | SkIPoint::Make(0, 0)); |
| 53 | } |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 54 | |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 55 | // TODO: this is virtual b.c. this object doesn't have a pointer to the wrapped GrSurfaceProxy? |
| 56 | virtual GrSurfaceProxy* asDeferredSurface() = 0; |
| 57 | virtual GrTextureProxy* asDeferredTexture() = 0; |
| 58 | virtual GrRenderTargetProxy* asDeferredRenderTarget() = 0; |
| 59 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 60 | GrAuditTrail* auditTrail() { return fAuditTrail; } |
| 61 | |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 62 | // Provides access to functions that aren't part of the public API. |
| 63 | GrSurfaceContextPriv surfPriv(); |
| 64 | const GrSurfaceContextPriv surfPriv() const; |
| 65 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 66 | protected: |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 67 | friend class GrSurfaceContextPriv; |
| 68 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 69 | GrSurfaceContext(GrContext*, GrAuditTrail*, GrSingleOwner*); |
| 70 | |
| 71 | SkDEBUGCODE(GrSingleOwner* singleOwner() { return fSingleOwner; }) |
| 72 | |
| 73 | GrContext* fContext; |
| 74 | GrAuditTrail* fAuditTrail; |
| 75 | |
| 76 | // In debug builds we guard against improper thread handling |
| 77 | SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;) |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 78 | |
| 79 | private: |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 80 | virtual bool onCopy(GrSurfaceProxy* src, |
| 81 | const SkIRect& srcRect, |
| 82 | const SkIPoint& dstPoint) = 0; |
| 83 | |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 84 | typedef SkRefCnt INHERITED; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | #endif |