blob: a772d19c27283fc3b094d8cac4655720cee61064 [file] [log] [blame]
Brian Osman45580d32016-11-23 09:37:01 -05001/*
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 Phillipse2f7d182016-12-15 09:23:05 -050011#include "../private/GrSurfaceProxy.h"
12
Brian Osman45580d32016-11-23 09:37:01 -050013#include "SkRefCnt.h"
14
15class GrAuditTrail;
16class GrContext;
Robert Phillips27341362016-12-14 08:46:47 -050017class GrRenderTargetProxy;
Brian Osman45580d32016-11-23 09:37:01 -050018class GrSingleOwner;
19class GrSurface;
Robert Phillipse305cc1f2016-12-14 12:19:05 -050020class GrSurfaceContextPriv;
Robert Phillips27341362016-12-14 08:46:47 -050021class GrSurfaceProxy;
22class GrTextureProxy;
Brian Osman45580d32016-11-23 09:37:01 -050023struct SkIPoint;
24struct SkIRect;
25
26/**
27 * A helper object to orchestrate commands for a particular surface
28 */
29class SK_API GrSurfaceContext : public SkRefCnt {
30public:
31 ~GrSurfaceContext() override {}
32
Robert Phillipse2f7d182016-12-15 09:23:05 -050033 /*
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 Osman45580d32016-11-23 09:37:01 -050054
Robert Phillips27341362016-12-14 08:46:47 -050055 // 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 Osman45580d32016-11-23 09:37:01 -050060 GrAuditTrail* auditTrail() { return fAuditTrail; }
61
Robert Phillipse305cc1f2016-12-14 12:19:05 -050062 // Provides access to functions that aren't part of the public API.
63 GrSurfaceContextPriv surfPriv();
64 const GrSurfaceContextPriv surfPriv() const;
65
Brian Osman45580d32016-11-23 09:37:01 -050066protected:
Robert Phillipse305cc1f2016-12-14 12:19:05 -050067 friend class GrSurfaceContextPriv;
68
Brian Osman45580d32016-11-23 09:37:01 -050069 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 Phillipse305cc1f2016-12-14 12:19:05 -050078
79private:
Robert Phillipse2f7d182016-12-15 09:23:05 -050080 virtual bool onCopy(GrSurfaceProxy* src,
81 const SkIRect& srcRect,
82 const SkIPoint& dstPoint) = 0;
83
Robert Phillipse305cc1f2016-12-14 12:19:05 -050084 typedef SkRefCnt INHERITED;
Brian Osman45580d32016-11-23 09:37:01 -050085};
86
87#endif