• 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(GrRecordingContext * context,sk_sp<GrTextureProxy> textureProxy,sk_sp<SkColorSpace> colorSpace)20 GrTextureContext::GrTextureContext(GrRecordingContext* context,
21                                    sk_sp<GrTextureProxy> textureProxy,
22                                    sk_sp<SkColorSpace> colorSpace)
23         : GrSurfaceContext(context, textureProxy->config(), std::move(colorSpace))
24         , fTextureProxy(std::move(textureProxy))
25         , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) {
26     SkDEBUGCODE(this->validate();)
27 }
28 
29 #ifdef SK_DEBUG
validate() const30 void GrTextureContext::validate() const {
31     SkASSERT(fTextureProxy);
32     fTextureProxy->validate(fContext);
33 
34     if (fOpList && !fOpList->isClosed()) {
35         SkASSERT(fTextureProxy->getLastOpList() == fOpList.get());
36     }
37 }
38 #endif
39 
~GrTextureContext()40 GrTextureContext::~GrTextureContext() {
41     ASSERT_SINGLE_OWNER
42 }
43 
asRenderTargetProxy()44 GrRenderTargetProxy* GrTextureContext::asRenderTargetProxy() {
45     // If the proxy can return an RTProxy it should've been wrapped in a RTContext
46     SkASSERT(!fTextureProxy->asRenderTargetProxy());
47     return nullptr;
48 }
49 
asRenderTargetProxyRef()50 sk_sp<GrRenderTargetProxy> GrTextureContext::asRenderTargetProxyRef() {
51     // If the proxy can return an RTProxy it should've been wrapped in a RTContext
52     SkASSERT(!fTextureProxy->asRenderTargetProxy());
53     return nullptr;
54 }
55 
getOpList()56 GrOpList* GrTextureContext::getOpList() {
57     ASSERT_SINGLE_OWNER
58     SkDEBUGCODE(this->validate();)
59 
60     if (!fOpList || fOpList->isClosed()) {
61         fOpList = this->drawingManager()->newTextureOpList(fTextureProxy.get());
62     }
63 
64     return fOpList.get();
65 }
66