Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrTextureContext.h" |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 9 | |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 10 | #include "src/gpu/GrAuditTrail.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrContextPriv.h" |
| 12 | #include "src/gpu/GrDrawingManager.h" |
| 13 | #include "src/gpu/GrTextureOpList.h" |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 14 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 15 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 16 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 17 | #define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; } |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 18 | |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 19 | GrTextureContext::GrTextureContext(GrRecordingContext* context, |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 20 | sk_sp<GrTextureProxy> textureProxy, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 21 | GrColorType colorType, |
| 22 | SkAlphaType alphaType, |
Robert Phillips | 0d075de | 2019-03-04 11:08:13 -0500 | [diff] [blame] | 23 | sk_sp<SkColorSpace> colorSpace) |
Brian Salomon | bd3d8d3 | 2019-07-02 09:16:28 -0400 | [diff] [blame^] | 24 | : GrSurfaceContext(context, colorType, alphaType, std::move(colorSpace)) |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 25 | , fTextureProxy(std::move(textureProxy)) |
| 26 | , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) { |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 27 | SkDEBUGCODE(this->validate();) |
| 28 | } |
| 29 | |
| 30 | #ifdef SK_DEBUG |
| 31 | void GrTextureContext::validate() const { |
| 32 | SkASSERT(fTextureProxy); |
| 33 | fTextureProxy->validate(fContext); |
| 34 | |
| 35 | if (fOpList && !fOpList->isClosed()) { |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 36 | SkASSERT(fTextureProxy->getLastOpList() == fOpList.get()); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | #endif |
| 40 | |
| 41 | GrTextureContext::~GrTextureContext() { |
| 42 | ASSERT_SINGLE_OWNER |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 43 | } |
| 44 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 45 | GrRenderTargetProxy* GrTextureContext::asRenderTargetProxy() { |
| 46 | // If the proxy can return an RTProxy it should've been wrapped in a RTContext |
| 47 | SkASSERT(!fTextureProxy->asRenderTargetProxy()); |
| 48 | return nullptr; |
| 49 | } |
| 50 | |
| 51 | sk_sp<GrRenderTargetProxy> GrTextureContext::asRenderTargetProxyRef() { |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 52 | // If the proxy can return an RTProxy it should've been wrapped in a RTContext |
| 53 | SkASSERT(!fTextureProxy->asRenderTargetProxy()); |
| 54 | return nullptr; |
| 55 | } |
| 56 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 57 | GrOpList* GrTextureContext::getOpList() { |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 58 | ASSERT_SINGLE_OWNER |
| 59 | SkDEBUGCODE(this->validate();) |
| 60 | |
| 61 | if (!fOpList || fOpList->isClosed()) { |
Robert Phillips | 831a293 | 2019-04-12 17:18:39 -0400 | [diff] [blame] | 62 | fOpList = this->drawingManager()->newTextureOpList(fTextureProxy); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 63 | } |
| 64 | |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 65 | return fOpList.get(); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 66 | } |