GrTextureContext.cpp revision bc8ee52d4649afdc972599e5ef2a2a543867985d
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"
9
10#include "GrContextPriv.h"
11#include "GrDrawingManager.h"
12#include "GrResourceProvider.h"
13#include "GrTextureOpList.h"
14
15#include "../private/GrAuditTrail.h"
16
17#define ASSERT_SINGLE_OWNER \
18    SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
19#define RETURN_FALSE_IF_ABANDONED  if (this->drawingManager()->wasAbandoned()) { return false; }
20
21GrTextureContext::GrTextureContext(GrContext* context,
22                                   GrDrawingManager* drawingMgr,
23                                   sk_sp<GrTextureProxy> textureProxy,
24                                   sk_sp<SkColorSpace> colorSpace,
25                                   GrAuditTrail* auditTrail,
26                                   GrSingleOwner* singleOwner)
27    : GrSurfaceContext(context, drawingMgr, std::move(colorSpace), auditTrail, singleOwner)
28    , fTextureProxy(std::move(textureProxy))
29    , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) {
30    SkDEBUGCODE(this->validate();)
31}
32
33#ifdef SK_DEBUG
34void GrTextureContext::validate() const {
35    SkASSERT(fTextureProxy);
36    fTextureProxy->validate(fContext);
37
38    if (fOpList && !fOpList->isClosed()) {
39        SkASSERT(fTextureProxy->getLastOpList() == fOpList.get());
40    }
41}
42#endif
43
44GrTextureContext::~GrTextureContext() {
45    ASSERT_SINGLE_OWNER
46}
47
48GrRenderTargetProxy* 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
54sk_sp<GrRenderTargetProxy> GrTextureContext::asRenderTargetProxyRef() {
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
60GrTextureOpList* GrTextureContext::getOpList() {
61    ASSERT_SINGLE_OWNER
62    SkDEBUGCODE(this->validate();)
63
64    if (!fOpList || fOpList->isClosed()) {
65        fOpList = this->drawingManager()->newTextureOpList(fTextureProxy);
66    }
67
68    return fOpList.get();
69}
70
71// MDB TODO: move this (and GrRenderTargetContext::copy) to GrSurfaceContext?
72bool GrTextureContext::onCopy(GrSurfaceProxy* srcProxy,
73                              const SkIRect& srcRect,
74                              const SkIPoint& dstPoint) {
75    ASSERT_SINGLE_OWNER
76    RETURN_FALSE_IF_ABANDONED
77    SkDEBUGCODE(this->validate();)
78    GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrTextureContext::onCopy");
79
80    return this->getOpList()->copySurface(fContext->resourceProvider(),
81                                          fTextureProxy.get(), srcProxy, srcRect, dstPoint);
82}
83
84