blob: c5b320363691acf2846bba68f3d3f3a5e0208f69 [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
20GrTextureContext::GrTextureContext(GrContext* context,
21 GrDrawingManager* drawingMgr,
22 sk_sp<GrTextureProxy> textureProxy,
Robert Phillips2c862492017-01-18 10:08:39 -050023 sk_sp<SkColorSpace> colorSpace,
Brian Osman45580d32016-11-23 09:37:01 -050024 GrAuditTrail* auditTrail,
25 GrSingleOwner* singleOwner)
Brian Salomonf3569f02017-10-24 12:52:33 -040026 : GrSurfaceContext(context, drawingMgr, textureProxy->config(), std::move(colorSpace),
27 auditTrail, singleOwner)
28 , fTextureProxy(std::move(textureProxy))
29 , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) {
Brian Osman45580d32016-11-23 09:37:01 -050030 SkDEBUGCODE(this->validate();)
31}
32
33#ifdef SK_DEBUG
34void GrTextureContext::validate() const {
35 SkASSERT(fTextureProxy);
36 fTextureProxy->validate(fContext);
37
38 if (fOpList && !fOpList->isClosed()) {
Robert Phillipsdc83b892017-04-13 12:23:54 -040039 SkASSERT(fTextureProxy->getLastOpList() == fOpList.get());
Brian Osman45580d32016-11-23 09:37:01 -050040 }
41}
42#endif
43
44GrTextureContext::~GrTextureContext() {
45 ASSERT_SINGLE_OWNER
Brian Osman45580d32016-11-23 09:37:01 -050046}
47
Robert Phillipsf200a902017-01-30 13:27:37 -050048GrRenderTargetProxy* 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
54sk_sp<GrRenderTargetProxy> GrTextureContext::asRenderTargetProxyRef() {
Robert Phillips27341362016-12-14 08:46:47 -050055 // If the proxy can return an RTProxy it should've been wrapped in a RTContext
56 SkASSERT(!fTextureProxy->asRenderTargetProxy());
57 return nullptr;
58}
59
Robert Phillips2de8cfa2017-06-28 10:33:41 -040060GrOpList* GrTextureContext::getOpList() {
Brian Osman45580d32016-11-23 09:37:01 -050061 ASSERT_SINGLE_OWNER
62 SkDEBUGCODE(this->validate();)
63
64 if (!fOpList || fOpList->isClosed()) {
Robert Phillipsb6deea82017-05-11 14:14:30 -040065 fOpList = this->drawingManager()->newTextureOpList(fTextureProxy.get());
Brian Osman45580d32016-11-23 09:37:01 -050066 }
67
Robert Phillipsdc83b892017-04-13 12:23:54 -040068 return fOpList.get();
Brian Osman45580d32016-11-23 09:37:01 -050069}