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 | |
| 8 | #include "GrTextureContext.h" |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 9 | |
| 10 | #include "GrContextPriv.h" |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 11 | #include "GrDrawingManager.h" |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 12 | #include "GrTextureOpList.h" |
| 13 | |
| 14 | #include "../private/GrAuditTrail.h" |
| 15 | |
| 16 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 17 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 18 | #define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; } |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 19 | |
| 20 | GrTextureContext::GrTextureContext(GrContext* context, |
| 21 | GrDrawingManager* drawingMgr, |
| 22 | sk_sp<GrTextureProxy> textureProxy, |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 23 | sk_sp<SkColorSpace> colorSpace, |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 24 | GrAuditTrail* auditTrail, |
| 25 | GrSingleOwner* singleOwner) |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 26 | : GrSurfaceContext(context, drawingMgr, textureProxy->config(), std::move(colorSpace), |
| 27 | auditTrail, singleOwner) |
| 28 | , fTextureProxy(std::move(textureProxy)) |
| 29 | , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) { |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 30 | SkDEBUGCODE(this->validate();) |
| 31 | } |
| 32 | |
| 33 | #ifdef SK_DEBUG |
| 34 | void GrTextureContext::validate() const { |
| 35 | SkASSERT(fTextureProxy); |
| 36 | fTextureProxy->validate(fContext); |
| 37 | |
| 38 | if (fOpList && !fOpList->isClosed()) { |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 39 | SkASSERT(fTextureProxy->getLastOpList() == fOpList.get()); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 40 | } |
| 41 | } |
| 42 | #endif |
| 43 | |
| 44 | GrTextureContext::~GrTextureContext() { |
| 45 | ASSERT_SINGLE_OWNER |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 46 | } |
| 47 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 48 | GrRenderTargetProxy* 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 | |
| 54 | sk_sp<GrRenderTargetProxy> GrTextureContext::asRenderTargetProxyRef() { |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 55 | // 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 Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 60 | GrOpList* GrTextureContext::getOpList() { |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 61 | ASSERT_SINGLE_OWNER |
| 62 | SkDEBUGCODE(this->validate();) |
| 63 | |
| 64 | if (!fOpList || fOpList->isClosed()) { |
Robert Phillips | b6deea8 | 2017-05-11 14:14:30 -0400 | [diff] [blame] | 65 | fOpList = this->drawingManager()->newTextureOpList(fTextureProxy.get()); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 66 | } |
| 67 | |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 68 | return fOpList.get(); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 69 | } |