blob: 66030f9ee00cc5cb95c138dd579878290eb95aa2 [file] [log] [blame]
Brian Osman45580d32016-11-23 09:37:01 -05001/*
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#include "GrDrawingManager.h"
10#include "GrResourceProvider.h"
11#include "GrTextureOpList.h"
12
13#include "../private/GrAuditTrail.h"
14
15#define ASSERT_SINGLE_OWNER \
16 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);)
17#define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return false; }
18
19GrTextureContext::GrTextureContext(GrContext* context,
20 GrDrawingManager* drawingMgr,
21 sk_sp<GrTextureProxy> textureProxy,
22 GrAuditTrail* auditTrail,
23 GrSingleOwner* singleOwner)
24 : GrSurfaceContext(context, auditTrail, singleOwner)
25 , fDrawingManager(drawingMgr)
26 , fTextureProxy(std::move(textureProxy))
27 , fOpList(SkSafeRef(fTextureProxy->getLastTextureOpList()))
28{
29 SkDEBUGCODE(this->validate();)
30}
31
32#ifdef SK_DEBUG
33void GrTextureContext::validate() const {
34 SkASSERT(fTextureProxy);
35 fTextureProxy->validate(fContext);
36
37 if (fOpList && !fOpList->isClosed()) {
38 SkASSERT(fTextureProxy->getLastOpList() == fOpList);
39 }
40}
41#endif
42
43GrTextureContext::~GrTextureContext() {
44 ASSERT_SINGLE_OWNER
45 SkSafeUnref(fOpList);
46}
47
48GrTextureOpList* GrTextureContext::getOpList() {
49 ASSERT_SINGLE_OWNER
50 SkDEBUGCODE(this->validate();)
51
52 if (!fOpList || fOpList->isClosed()) {
53 fOpList = fDrawingManager->newOpList(fTextureProxy.get());
54 }
55
56 return fOpList;
57}
58
59bool GrTextureContext::copySurface(GrSurface* src, const SkIRect& srcRect,
60 const SkIPoint& dstPoint) {
61 ASSERT_SINGLE_OWNER
62 RETURN_FALSE_IF_ABANDONED
63 SkDEBUGCODE(this->validate();)
64 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrTextureContext::copySurface");
65
66 // TODO: this needs to be fixed up since it ends the deferrable of the GrTexture
67 sk_sp<GrTexture> tex(sk_ref_sp(fTextureProxy->instantiate(fContext->textureProvider())));
68 if (!tex) {
69 return false;
70 }
71
72 GrTextureOpList* opList = this->getOpList();
73 bool result = opList->copySurface(tex.get(), src, srcRect, dstPoint);
74
75#ifndef ENABLE_MDB
76 GrBatchFlushState flushState(fContext->getGpu(), nullptr);
Brian Salomon1e41f4a2016-12-07 15:05:04 -050077 opList->prepareOps(&flushState);
78 opList->executeOps(&flushState);
Brian Osman45580d32016-11-23 09:37:01 -050079 opList->reset();
80#endif
81
82 return result;
83}