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 #include "GrTextureContext.h"
9
10 #include "GrContextPriv.h"
11 #include "GrDrawingManager.h"
12 #include "GrTextureOpList.h"
13
14 #include "../private/GrAuditTrail.h"
15
16 #define ASSERT_SINGLE_OWNER \
17 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
18 #define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; }
19
GrTextureContext(GrContext * context,GrDrawingManager * drawingMgr,sk_sp<GrTextureProxy> textureProxy,sk_sp<SkColorSpace> colorSpace,GrAuditTrail * auditTrail,GrSingleOwner * singleOwner)20 GrTextureContext::GrTextureContext(GrContext* context,
21 GrDrawingManager* drawingMgr,
22 sk_sp<GrTextureProxy> textureProxy,
23 sk_sp<SkColorSpace> colorSpace,
24 GrAuditTrail* auditTrail,
25 GrSingleOwner* singleOwner)
26 : GrSurfaceContext(context, drawingMgr, textureProxy->config(), std::move(colorSpace),
27 auditTrail, singleOwner)
28 , fTextureProxy(std::move(textureProxy))
29 , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) {
30 SkDEBUGCODE(this->validate();)
31 }
32
33 #ifdef SK_DEBUG
validate() const34 void GrTextureContext::validate() const {
35 SkASSERT(fTextureProxy);
36 fTextureProxy->validate(fContext);
37
38 if (fOpList && !fOpList->isClosed()) {
39 SkASSERT(fTextureProxy->getLastOpList() == fOpList.get());
40 }
41 }
42 #endif
43
~GrTextureContext()44 GrTextureContext::~GrTextureContext() {
45 ASSERT_SINGLE_OWNER
46 }
47
asRenderTargetProxy()48 GrRenderTargetProxy* GrTextureContext::asRenderTargetProxy() {
49 // If the proxy can return an RTProxy it should've been wrapped in a RTContext
50 SkASSERT(!fTextureProxy->asRenderTargetProxy());
51 return nullptr;
52 }
53
asRenderTargetProxyRef()54 sk_sp<GrRenderTargetProxy> GrTextureContext::asRenderTargetProxyRef() {
55 // If the proxy can return an RTProxy it should've been wrapped in a RTContext
56 SkASSERT(!fTextureProxy->asRenderTargetProxy());
57 return nullptr;
58 }
59
getOpList()60 GrOpList* GrTextureContext::getOpList() {
61 ASSERT_SINGLE_OWNER
62 SkDEBUGCODE(this->validate();)
63
64 if (!fOpList || fOpList->isClosed()) {
65 fOpList = this->drawingManager()->newTextureOpList(fTextureProxy.get());
66 }
67
68 return fOpList.get();
69 }
70