diff options
author | Brian Osman <brianosman@google.com> | 2016-11-23 09:37:01 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-11-23 15:52:27 +0000 |
commit | 45580d3e3024c1536e8e1b2017b704805442b634 (patch) | |
tree | 9ed9fe3bdc0d949ec8e83b06691b37b6ffdcc54a /src/gpu/GrTextureContext.cpp | |
parent | 07764cefbb18041a77897df3453903b0a2016583 (diff) |
Added GrSurfaceContext and GrTextureContext
This lets copy-to-texture to be treated like copy-to-rt.
To match current behavior, though, copies to texture are
still executed immediately (forcing a flush).
Once MDB is enabled, copies to texture will be deferred.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5093
Change-Id: Icc0ce5435507a5f0a237c22eedef879824952367
Reviewed-on: https://skia-review.googlesource.com/5093
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu/GrTextureContext.cpp')
-rw-r--r-- | src/gpu/GrTextureContext.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/gpu/GrTextureContext.cpp b/src/gpu/GrTextureContext.cpp new file mode 100644 index 0000000000..5c0c17b728 --- /dev/null +++ b/src/gpu/GrTextureContext.cpp @@ -0,0 +1,83 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "GrTextureContext.h" +#include "GrDrawingManager.h" +#include "GrResourceProvider.h" +#include "GrTextureOpList.h" + +#include "../private/GrAuditTrail.h" + +#define ASSERT_SINGLE_OWNER \ + SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);) +#define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return false; } + +GrTextureContext::GrTextureContext(GrContext* context, + GrDrawingManager* drawingMgr, + sk_sp<GrTextureProxy> textureProxy, + GrAuditTrail* auditTrail, + GrSingleOwner* singleOwner) + : GrSurfaceContext(context, auditTrail, singleOwner) + , fDrawingManager(drawingMgr) + , fTextureProxy(std::move(textureProxy)) + , fOpList(SkSafeRef(fTextureProxy->getLastTextureOpList())) +{ + SkDEBUGCODE(this->validate();) +} + +#ifdef SK_DEBUG +void GrTextureContext::validate() const { + SkASSERT(fTextureProxy); + fTextureProxy->validate(fContext); + + if (fOpList && !fOpList->isClosed()) { + SkASSERT(fTextureProxy->getLastOpList() == fOpList); + } +} +#endif + +GrTextureContext::~GrTextureContext() { + ASSERT_SINGLE_OWNER + SkSafeUnref(fOpList); +} + +GrTextureOpList* GrTextureContext::getOpList() { + ASSERT_SINGLE_OWNER + SkDEBUGCODE(this->validate();) + + if (!fOpList || fOpList->isClosed()) { + fOpList = fDrawingManager->newOpList(fTextureProxy.get()); + } + + return fOpList; +} + +bool GrTextureContext::copySurface(GrSurface* src, const SkIRect& srcRect, + const SkIPoint& dstPoint) { + ASSERT_SINGLE_OWNER + RETURN_FALSE_IF_ABANDONED + SkDEBUGCODE(this->validate();) + GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrTextureContext::copySurface"); + + // TODO: this needs to be fixed up since it ends the deferrable of the GrTexture + sk_sp<GrTexture> tex(sk_ref_sp(fTextureProxy->instantiate(fContext->textureProvider()))); + if (!tex) { + return false; + } + + GrTextureOpList* opList = this->getOpList(); + bool result = opList->copySurface(tex.get(), src, srcRect, dstPoint); + +#ifndef ENABLE_MDB + GrBatchFlushState flushState(fContext->getGpu(), nullptr); + opList->prepareBatches(&flushState); + opList->drawBatches(&flushState); + opList->reset(); +#endif + + return result; +} |