blob: c9e5fa5c94a7b48e3dbfb9c1e77bb17d2877b99f [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrTextureContext.h"
Robert Phillips7ee385e2017-03-30 08:02:11 -04009
Greg Danielf91aeb22019-06-18 09:58:02 -040010#include "src/gpu/GrAuditTrail.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrContextPriv.h"
12#include "src/gpu/GrDrawingManager.h"
13#include "src/gpu/GrTextureOpList.h"
Brian Osman45580d32016-11-23 09:37:01 -050014
Brian Osman45580d32016-11-23 09:37:01 -050015#define ASSERT_SINGLE_OWNER \
Robert Phillipsa90aa2b2017-04-10 08:19:26 -040016 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
Robert Phillips72152832017-01-25 17:31:35 -050017#define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; }
Brian Osman45580d32016-11-23 09:37:01 -050018
Robert Phillips69893702019-02-22 11:16:30 -050019GrTextureContext::GrTextureContext(GrRecordingContext* context,
Brian Osman45580d32016-11-23 09:37:01 -050020 sk_sp<GrTextureProxy> textureProxy,
Brian Salomond6287472019-06-24 15:50:07 -040021 GrColorType colorType,
22 SkAlphaType alphaType,
Robert Phillips0d075de2019-03-04 11:08:13 -050023 sk_sp<SkColorSpace> colorSpace)
Brian Salomond6287472019-06-24 15:50:07 -040024 : GrSurfaceContext(context,
25 colorType,
26 alphaType,
27 std::move(colorSpace),
28 textureProxy->config())
Brian Salomonf3569f02017-10-24 12:52:33 -040029 , fTextureProxy(std::move(textureProxy))
30 , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) {
Brian Osman45580d32016-11-23 09:37:01 -050031 SkDEBUGCODE(this->validate();)
32}
33
34#ifdef SK_DEBUG
35void GrTextureContext::validate() const {
36 SkASSERT(fTextureProxy);
37 fTextureProxy->validate(fContext);
38
39 if (fOpList && !fOpList->isClosed()) {
Robert Phillipsdc83b892017-04-13 12:23:54 -040040 SkASSERT(fTextureProxy->getLastOpList() == fOpList.get());
Brian Osman45580d32016-11-23 09:37:01 -050041 }
42}
43#endif
44
45GrTextureContext::~GrTextureContext() {
46 ASSERT_SINGLE_OWNER
Brian Osman45580d32016-11-23 09:37:01 -050047}
48
Robert Phillipsf200a902017-01-30 13:27:37 -050049GrRenderTargetProxy* GrTextureContext::asRenderTargetProxy() {
50 // If the proxy can return an RTProxy it should've been wrapped in a RTContext
51 SkASSERT(!fTextureProxy->asRenderTargetProxy());
52 return nullptr;
53}
54
55sk_sp<GrRenderTargetProxy> GrTextureContext::asRenderTargetProxyRef() {
Robert Phillips27341362016-12-14 08:46:47 -050056 // If the proxy can return an RTProxy it should've been wrapped in a RTContext
57 SkASSERT(!fTextureProxy->asRenderTargetProxy());
58 return nullptr;
59}
60
Robert Phillips2de8cfa2017-06-28 10:33:41 -040061GrOpList* GrTextureContext::getOpList() {
Brian Osman45580d32016-11-23 09:37:01 -050062 ASSERT_SINGLE_OWNER
63 SkDEBUGCODE(this->validate();)
64
65 if (!fOpList || fOpList->isClosed()) {
Robert Phillips831a2932019-04-12 17:18:39 -040066 fOpList = this->drawingManager()->newTextureOpList(fTextureProxy);
Brian Osman45580d32016-11-23 09:37:01 -050067 }
68
Robert Phillipsdc83b892017-04-13 12:23:54 -040069 return fOpList.get();
Brian Osman45580d32016-11-23 09:37:01 -050070}