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) |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 26 | : GrSurfaceContext(context, drawingMgr, std::move(colorSpace), auditTrail, singleOwner) |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 27 | , fTextureProxy(std::move(textureProxy)) |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 28 | , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) { |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 29 | SkDEBUGCODE(this->validate();) |
| 30 | } |
| 31 | |
| 32 | #ifdef SK_DEBUG |
| 33 | void GrTextureContext::validate() const { |
| 34 | SkASSERT(fTextureProxy); |
| 35 | fTextureProxy->validate(fContext); |
| 36 | |
| 37 | if (fOpList && !fOpList->isClosed()) { |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 38 | SkASSERT(fTextureProxy->getLastOpList() == fOpList.get()); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | #endif |
| 42 | |
| 43 | GrTextureContext::~GrTextureContext() { |
| 44 | ASSERT_SINGLE_OWNER |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 45 | } |
| 46 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 47 | GrRenderTargetProxy* 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 | |
| 53 | sk_sp<GrRenderTargetProxy> GrTextureContext::asRenderTargetProxyRef() { |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 54 | // 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 Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 59 | GrTextureOpList* GrTextureContext::getOpList() { |
| 60 | ASSERT_SINGLE_OWNER |
| 61 | SkDEBUGCODE(this->validate();) |
| 62 | |
| 63 | if (!fOpList || fOpList->isClosed()) { |
Robert Phillips | b6deea8 | 2017-05-11 14:14:30 -0400 | [diff] [blame] | 64 | fOpList = this->drawingManager()->newTextureOpList(fTextureProxy.get()); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 65 | } |
| 66 | |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 67 | return fOpList.get(); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 68 | } |
| 69 | |
Robert Phillips | c84c030 | 2017-05-08 15:35:11 -0400 | [diff] [blame] | 70 | // MDB TODO: move this (and GrRenderTargetContext::copy) to GrSurfaceContext? |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 71 | bool GrTextureContext::onCopy(GrSurfaceProxy* srcProxy, |
| 72 | const SkIRect& srcRect, |
| 73 | const SkIPoint& dstPoint) { |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 74 | ASSERT_SINGLE_OWNER |
| 75 | RETURN_FALSE_IF_ABANDONED |
| 76 | SkDEBUGCODE(this->validate();) |
Robert Phillips | c84c030 | 2017-05-08 15:35:11 -0400 | [diff] [blame] | 77 | GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrTextureContext::onCopy"); |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 78 | |
Robert Phillips | a16f6cb | 2017-06-01 11:06:13 -0400 | [diff] [blame] | 79 | return this->getOpList()->copySurface(*fContext->caps(), |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 80 | fTextureProxy.get(), srcProxy, srcRect, dstPoint); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 81 | } |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 82 | |