blob: 1372a2033674619ebeadd962c4103d6fab7e3509 [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"
Brian Osman45580d32016-11-23 09:37:01 -050013
Brian Osman45580d32016-11-23 09:37:01 -050014#define ASSERT_SINGLE_OWNER \
Robert Phillipsa90aa2b2017-04-10 08:19:26 -040015 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
Robert Phillips72152832017-01-25 17:31:35 -050016#define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; }
Brian Osman45580d32016-11-23 09:37:01 -050017
Robert Phillips69893702019-02-22 11:16:30 -050018GrTextureContext::GrTextureContext(GrRecordingContext* context,
Brian Osman45580d32016-11-23 09:37:01 -050019 sk_sp<GrTextureProxy> textureProxy,
Brian Salomond6287472019-06-24 15:50:07 -040020 GrColorType colorType,
21 SkAlphaType alphaType,
Robert Phillips0d075de2019-03-04 11:08:13 -050022 sk_sp<SkColorSpace> colorSpace)
Brian Salomonbd3d8d32019-07-02 09:16:28 -040023 : GrSurfaceContext(context, colorType, alphaType, std::move(colorSpace))
Greg Daniel5abfff22019-08-22 10:35:14 -040024 , fTextureProxy(std::move(textureProxy)) {
Brian Osman45580d32016-11-23 09:37:01 -050025 SkDEBUGCODE(this->validate();)
26}
27
28#ifdef SK_DEBUG
29void GrTextureContext::validate() const {
30 SkASSERT(fTextureProxy);
31 fTextureProxy->validate(fContext);
Brian Osman45580d32016-11-23 09:37:01 -050032}
33#endif
34
35GrTextureContext::~GrTextureContext() {
36 ASSERT_SINGLE_OWNER
Brian Osman45580d32016-11-23 09:37:01 -050037}
38
Robert Phillipsf200a902017-01-30 13:27:37 -050039GrRenderTargetProxy* GrTextureContext::asRenderTargetProxy() {
40 // If the proxy can return an RTProxy it should've been wrapped in a RTContext
41 SkASSERT(!fTextureProxy->asRenderTargetProxy());
42 return nullptr;
43}
44
45sk_sp<GrRenderTargetProxy> GrTextureContext::asRenderTargetProxyRef() {
Robert Phillips27341362016-12-14 08:46:47 -050046 // If the proxy can return an RTProxy it should've been wrapped in a RTContext
47 SkASSERT(!fTextureProxy->asRenderTargetProxy());
48 return nullptr;
49}