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 "src/gpu/GrTextureContext.h"
9
10 #include "src/gpu/GrAuditTrail.h"
11 #include "src/gpu/GrContextPriv.h"
12 #include "src/gpu/GrDrawingManager.h"
13 #include "src/gpu/GrTextureOpList.h"
14
15 #define ASSERT_SINGLE_OWNER \
16 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
17 #define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; }
18
GrTextureContext(GrRecordingContext * context,sk_sp<GrTextureProxy> textureProxy,GrColorType colorType,SkAlphaType alphaType,sk_sp<SkColorSpace> colorSpace)19 GrTextureContext::GrTextureContext(GrRecordingContext* context,
20 sk_sp<GrTextureProxy> textureProxy,
21 GrColorType colorType,
22 SkAlphaType alphaType,
23 sk_sp<SkColorSpace> colorSpace)
24 : GrSurfaceContext(context, colorType, alphaType, std::move(colorSpace))
25 , fTextureProxy(std::move(textureProxy))
26 , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) {
27 SkDEBUGCODE(this->validate();)
28 }
29
30 #ifdef SK_DEBUG
validate() const31 void GrTextureContext::validate() const {
32 SkASSERT(fTextureProxy);
33 fTextureProxy->validate(fContext);
34
35 if (fOpList && !fOpList->isClosed()) {
36 SkASSERT(fTextureProxy->getLastRenderTask() == fOpList.get());
37 }
38 }
39 #endif
40
~GrTextureContext()41 GrTextureContext::~GrTextureContext() {
42 ASSERT_SINGLE_OWNER
43 }
44
asRenderTargetProxy()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
asRenderTargetProxyRef()51 sk_sp<GrRenderTargetProxy> GrTextureContext::asRenderTargetProxyRef() {
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
getOpList()57 GrOpList* GrTextureContext::getOpList() {
58 ASSERT_SINGLE_OWNER
59 SkDEBUGCODE(this->validate();)
60
61 if (!fOpList || fOpList->isClosed()) {
62 fOpList = this->drawingManager()->newTextureOpList(fTextureProxy);
63 }
64
65 return fOpList.get();
66 }
67