blob: dca8984d6008632cea2a7bf75b8a13bdf2e1e20b [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)
Robert Phillips72152832017-01-25 17:31:35 -050026 : GrSurfaceContext(context, drawingMgr, std::move(colorSpace), auditTrail, singleOwner)
Brian Osman45580d32016-11-23 09:37:01 -050027 , fTextureProxy(std::move(textureProxy))
Robert Phillipsdc83b892017-04-13 12:23:54 -040028 , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) {
Brian Osman45580d32016-11-23 09:37:01 -050029 SkDEBUGCODE(this->validate();)
30}
31
32#ifdef SK_DEBUG
33void GrTextureContext::validate() const {
34 SkASSERT(fTextureProxy);
35 fTextureProxy->validate(fContext);
36
37 if (fOpList && !fOpList->isClosed()) {
Robert Phillipsdc83b892017-04-13 12:23:54 -040038 SkASSERT(fTextureProxy->getLastOpList() == fOpList.get());
Brian Osman45580d32016-11-23 09:37:01 -050039 }
40}
41#endif
42
43GrTextureContext::~GrTextureContext() {
44 ASSERT_SINGLE_OWNER
Brian Osman45580d32016-11-23 09:37:01 -050045}
46
Robert Phillipsf200a902017-01-30 13:27:37 -050047GrRenderTargetProxy* 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
53sk_sp<GrRenderTargetProxy> GrTextureContext::asRenderTargetProxyRef() {
Robert Phillips27341362016-12-14 08:46:47 -050054 // If the proxy can return an RTProxy it should've been wrapped in a RTContext
55 SkASSERT(!fTextureProxy->asRenderTargetProxy());
56 return nullptr;
57}
58
Brian Osman45580d32016-11-23 09:37:01 -050059GrTextureOpList* GrTextureContext::getOpList() {
60 ASSERT_SINGLE_OWNER
61 SkDEBUGCODE(this->validate();)
62
63 if (!fOpList || fOpList->isClosed()) {
Robert Phillipsb6deea82017-05-11 14:14:30 -040064 fOpList = this->drawingManager()->newTextureOpList(fTextureProxy.get());
Brian Osman45580d32016-11-23 09:37:01 -050065 }
66
Robert Phillipsdc83b892017-04-13 12:23:54 -040067 return fOpList.get();
Brian Osman45580d32016-11-23 09:37:01 -050068}
69
Robert Phillipsc84c0302017-05-08 15:35:11 -040070// MDB TODO: move this (and GrRenderTargetContext::copy) to GrSurfaceContext?
Robert Phillipse2f7d182016-12-15 09:23:05 -050071bool GrTextureContext::onCopy(GrSurfaceProxy* srcProxy,
72 const SkIRect& srcRect,
73 const SkIPoint& dstPoint) {
Brian Osman45580d32016-11-23 09:37:01 -050074 ASSERT_SINGLE_OWNER
75 RETURN_FALSE_IF_ABANDONED
76 SkDEBUGCODE(this->validate();)
Robert Phillipsc84c0302017-05-08 15:35:11 -040077 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrTextureContext::onCopy");
Robert Phillipse2f7d182016-12-15 09:23:05 -050078
Robert Phillipsa16f6cb2017-06-01 11:06:13 -040079 return this->getOpList()->copySurface(*fContext->caps(),
Robert Phillips6cdc22c2017-05-11 16:29:14 -040080 fTextureProxy.get(), srcProxy, srcRect, dstPoint);
Brian Osman45580d32016-11-23 09:37:01 -050081}
Robert Phillips2c862492017-01-18 10:08:39 -050082