• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, std::move(colorSpace), auditTrail, singleOwner)
27     , fTextureProxy(std::move(textureProxy))
28     , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) {
29     SkDEBUGCODE(this->validate();)
30 }
31 
32 #ifdef SK_DEBUG
validate() const33 void GrTextureContext::validate() const {
34     SkASSERT(fTextureProxy);
35     fTextureProxy->validate(fContext);
36 
37     if (fOpList && !fOpList->isClosed()) {
38         SkASSERT(fTextureProxy->getLastOpList() == fOpList.get());
39     }
40 }
41 #endif
42 
~GrTextureContext()43 GrTextureContext::~GrTextureContext() {
44     ASSERT_SINGLE_OWNER
45 }
46 
asRenderTargetProxy()47 GrRenderTargetProxy* GrTextureContext::asRenderTargetProxy() {
48     // If the proxy can return an RTProxy it should've been wrapped in a RTContext
49     SkASSERT(!fTextureProxy->asRenderTargetProxy());
50     return nullptr;
51 }
52 
asRenderTargetProxyRef()53 sk_sp<GrRenderTargetProxy> GrTextureContext::asRenderTargetProxyRef() {
54     // If the proxy can return an RTProxy it should've been wrapped in a RTContext
55     SkASSERT(!fTextureProxy->asRenderTargetProxy());
56     return nullptr;
57 }
58 
getOpList()59 GrOpList* GrTextureContext::getOpList() {
60     ASSERT_SINGLE_OWNER
61     SkDEBUGCODE(this->validate();)
62 
63     if (!fOpList || fOpList->isClosed()) {
64         fOpList = this->drawingManager()->newTextureOpList(fTextureProxy.get());
65     }
66 
67     return fOpList.get();
68 }
69