blob: fb0e124041f56a140dd79f4d4cc5c8036a115ebe [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#include "GrTextureContext.h"
Robert Phillips7ee385e2017-03-30 08:02:11 -04009
10#include "GrContextPriv.h"
Brian Osman45580d32016-11-23 09:37:01 -050011#include "GrDrawingManager.h"
Brian Osman45580d32016-11-23 09:37:01 -050012#include "GrTextureOpList.h"
13
14#include "../private/GrAuditTrail.h"
15
16#define ASSERT_SINGLE_OWNER \
Robert Phillipsa90aa2b2017-04-10 08:19:26 -040017 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
Robert Phillips72152832017-01-25 17:31:35 -050018#define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; }
Brian Osman45580d32016-11-23 09:37:01 -050019
Robert Phillips69893702019-02-22 11:16:30 -050020GrTextureContext::GrTextureContext(GrRecordingContext* context,
Brian Osman45580d32016-11-23 09:37:01 -050021 sk_sp<GrTextureProxy> textureProxy,
Robert Phillips0d075de2019-03-04 11:08:13 -050022 sk_sp<SkColorSpace> colorSpace)
23 : GrSurfaceContext(context, textureProxy->config(), std::move(colorSpace))
Brian Salomonf3569f02017-10-24 12:52:33 -040024 , fTextureProxy(std::move(textureProxy))
25 , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) {
Brian Osman45580d32016-11-23 09:37:01 -050026 SkDEBUGCODE(this->validate();)
27}
28
29#ifdef SK_DEBUG
30void GrTextureContext::validate() const {
31 SkASSERT(fTextureProxy);
32 fTextureProxy->validate(fContext);
33
34 if (fOpList && !fOpList->isClosed()) {
Robert Phillipsdc83b892017-04-13 12:23:54 -040035 SkASSERT(fTextureProxy->getLastOpList() == fOpList.get());
Brian Osman45580d32016-11-23 09:37:01 -050036 }
37}
38#endif
39
40GrTextureContext::~GrTextureContext() {
41 ASSERT_SINGLE_OWNER
Brian Osman45580d32016-11-23 09:37:01 -050042}
43
Robert Phillipsf200a902017-01-30 13:27:37 -050044GrRenderTargetProxy* 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
50sk_sp<GrRenderTargetProxy> GrTextureContext::asRenderTargetProxyRef() {
Robert Phillips27341362016-12-14 08:46:47 -050051 // If the proxy can return an RTProxy it should've been wrapped in a RTContext
52 SkASSERT(!fTextureProxy->asRenderTargetProxy());
53 return nullptr;
54}
55
Robert Phillips2de8cfa2017-06-28 10:33:41 -040056GrOpList* GrTextureContext::getOpList() {
Brian Osman45580d32016-11-23 09:37:01 -050057 ASSERT_SINGLE_OWNER
58 SkDEBUGCODE(this->validate();)
59
60 if (!fOpList || fOpList->isClosed()) {
Robert Phillips831a2932019-04-12 17:18:39 -040061 fOpList = this->drawingManager()->newTextureOpList(fTextureProxy);
Brian Osman45580d32016-11-23 09:37:01 -050062 }
63
Robert Phillipsdc83b892017-04-13 12:23:54 -040064 return fOpList.get();
Brian Osman45580d32016-11-23 09:37:01 -050065}