blob: 0021c23da1c42c12187e748bbbb2454906755700 [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"
12#include "GrResourceProvider.h"
13#include "GrTextureOpList.h"
14
15#include "../private/GrAuditTrail.h"
16
17#define ASSERT_SINGLE_OWNER \
Robert Phillipsa90aa2b2017-04-10 08:19:26 -040018 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
Robert Phillips72152832017-01-25 17:31:35 -050019#define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; }
Brian Osman45580d32016-11-23 09:37:01 -050020
21GrTextureContext::GrTextureContext(GrContext* context,
22 GrDrawingManager* drawingMgr,
23 sk_sp<GrTextureProxy> textureProxy,
Robert Phillips2c862492017-01-18 10:08:39 -050024 sk_sp<SkColorSpace> colorSpace,
Brian Osman45580d32016-11-23 09:37:01 -050025 GrAuditTrail* auditTrail,
26 GrSingleOwner* singleOwner)
Robert Phillips72152832017-01-25 17:31:35 -050027 : GrSurfaceContext(context, drawingMgr, std::move(colorSpace), auditTrail, singleOwner)
Brian Osman45580d32016-11-23 09:37:01 -050028 , fTextureProxy(std::move(textureProxy))
Robert Phillipsdc83b892017-04-13 12:23:54 -040029 , 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
Brian Osman45580d32016-11-23 09:37:01 -050060GrTextureOpList* GrTextureContext::getOpList() {
61 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}
70
Robert Phillipsc84c0302017-05-08 15:35:11 -040071// MDB TODO: move this (and GrRenderTargetContext::copy) to GrSurfaceContext?
Robert Phillipse2f7d182016-12-15 09:23:05 -050072bool GrTextureContext::onCopy(GrSurfaceProxy* srcProxy,
73 const SkIRect& srcRect,
74 const SkIPoint& dstPoint) {
Brian Osman45580d32016-11-23 09:37:01 -050075 ASSERT_SINGLE_OWNER
76 RETURN_FALSE_IF_ABANDONED
77 SkDEBUGCODE(this->validate();)
Robert Phillipsc84c0302017-05-08 15:35:11 -040078 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrTextureContext::onCopy");
Robert Phillipse2f7d182016-12-15 09:23:05 -050079
Robert Phillips6cdc22c2017-05-11 16:29:14 -040080 return this->getOpList()->copySurface(fContext->resourceProvider(),
81 fTextureProxy.get(), srcProxy, srcRect, dstPoint);
Brian Osman45580d32016-11-23 09:37:01 -050082}
Robert Phillips2c862492017-01-18 10:08:39 -050083