Move copy operation from GrRenderTargetContext/GrTextureContext to GrSurfaceContext

Change-Id: I5f48ce9978370f07238a7318ccb6270e10069c92
Reviewed-on: https://skia-review.googlesource.com/21104
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2017-06-28 10:33:41 -04:00 committed by Skia Commit-Bot
parent 90ca37726b
commit 2de8cfadc3
11 changed files with 69 additions and 61 deletions

View File

@ -140,7 +140,7 @@ void GrDrawingManager::internalFlush(GrSurfaceProxy*, GrResourceCache::FlushType
}
for (int j = 0; j < renderTargetContexts.count(); ++j) {
GrRenderTargetOpList* opList = renderTargetContexts[j]->getOpList();
GrOpList* opList = renderTargetContexts[j]->getOpList();
if (!opList) {
continue; // Odd - but not a big deal
}

View File

@ -23,6 +23,9 @@ class GrSurfaceProxy;
class GrTextureProxy;
class GrTextureOpList;
struct SkIPoint;
struct SkIRect;
class GrOpList : public SkRefCnt {
public:
GrOpList(GrResourceProvider*, GrSurfaceProxy*, GrAuditTrail*);
@ -33,6 +36,12 @@ public:
virtual void prepareOps(GrOpFlushState* flushState) = 0;
virtual bool executeOps(GrOpFlushState* flushState) = 0;
virtual bool copySurface(const GrCaps& caps,
GrSurfaceProxy* dst,
GrSurfaceProxy* src,
const SkIRect& srcRect,
const SkIPoint& dstPoint) = 0;
virtual void makeClosed(const GrCaps&) {
if (!this->isClosed()) {
this->setFlag(kClosed_Flag);

View File

@ -126,7 +126,7 @@ GrRenderTargetContext::GrRenderTargetContext(GrContext* context,
// MDB TODO: to ensure all resources still get allocated in the correct order in the hybrid
// world we need to get the correct opList here so that it, in turn, can grab and hold
// its rendertarget.
this->getOpList();
this->getRTOpList();
SkDEBUGCODE(this->validate();)
}
@ -153,7 +153,7 @@ sk_sp<GrTextureProxy> GrRenderTargetContext::asTextureProxyRef() {
return sk_ref_sp(fRenderTargetProxy->asTextureProxy());
}
GrRenderTargetOpList* GrRenderTargetContext::getOpList() {
GrRenderTargetOpList* GrRenderTargetContext::getRTOpList() {
ASSERT_SINGLE_OWNER
SkDEBUGCODE(this->validate();)
@ -164,17 +164,8 @@ GrRenderTargetOpList* GrRenderTargetContext::getOpList() {
return fOpList.get();
}
// MDB TODO: move this (and GrTextContext::copy) to GrSurfaceContext?
bool GrRenderTargetContext::onCopy(GrSurfaceProxy* srcProxy,
const SkIRect& srcRect,
const SkIPoint& dstPoint) {
ASSERT_SINGLE_OWNER
RETURN_FALSE_IF_ABANDONED
SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::onCopy");
return this->getOpList()->copySurface(*this->caps(),
this->asSurfaceProxy(), srcProxy, srcRect, dstPoint);
GrOpList* GrRenderTargetContext::getOpList() {
return this->getRTOpList();
}
void GrRenderTargetContext::drawText(const GrClip& clip, const SkPaint& skPaint,
@ -235,7 +226,7 @@ void GrRenderTargetContext::discard() {
if (!op) {
return;
}
this->getOpList()->addOp(std::move(op), *this->caps());
this->getRTOpList()->addOp(std::move(op), *this->caps());
}
}
@ -297,7 +288,7 @@ void GrRenderTargetContextPriv::absClear(const SkIRect* clearRect, const GrColor
if (!op) {
return;
}
fRenderTargetContext->getOpList()->addOp(std::move(op), *fRenderTargetContext->caps());
fRenderTargetContext->getRTOpList()->addOp(std::move(op), *fRenderTargetContext->caps());
}
}
@ -341,13 +332,13 @@ void GrRenderTargetContext::internalClear(const GrFixedClip& clip,
this->drawRect(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), SkRect::Make(clearRect));
} else if (isFull) {
this->getOpList()->fullClear(*this->caps(), color);
this->getRTOpList()->fullClear(*this->caps(), color);
} else {
std::unique_ptr<GrOp> op(GrClearOp::Make(clip, color, this->asSurfaceProxy()));
if (!op) {
return;
}
this->getOpList()->addOp(std::move(op), *this->caps());
this->getRTOpList()->addOp(std::move(op), *this->caps());
}
}
@ -621,7 +612,7 @@ void GrRenderTargetContextPriv::clearStencilClip(const GrFixedClip& clip, bool i
if (!op) {
return;
}
fRenderTargetContext->getOpList()->addOp(std::move(op), *fRenderTargetContext->caps());
fRenderTargetContext->getRTOpList()->addOp(std::move(op), *fRenderTargetContext->caps());
}
void GrRenderTargetContextPriv::stencilPath(const GrClip& clip,
@ -678,7 +669,7 @@ void GrRenderTargetContextPriv::stencilPath(const GrClip& clip,
return;
}
op->setClippedBounds(bounds);
fRenderTargetContext->getOpList()->addOp(std::move(op), *fRenderTargetContext->caps());
fRenderTargetContext->getRTOpList()->addOp(std::move(op), *fRenderTargetContext->caps());
}
void GrRenderTargetContextPriv::stencilRect(const GrClip& clip,
@ -1451,7 +1442,7 @@ bool GrRenderTargetContext::prepareForExternalIO(int numSemaphores,
std::unique_ptr<GrOp> signalOp(GrSemaphoreOp::MakeSignal(semaphores.back(),
fRenderTargetProxy.get(),
forceFlush));
this->getOpList()->addOp(std::move(signalOp), *this->caps());
this->getRTOpList()->addOp(std::move(signalOp), *this->caps());
}
this->drawingManager()->prepareSurfaceForExternalIO(fRenderTargetProxy.get());
@ -1480,7 +1471,7 @@ bool GrRenderTargetContext::waitOnSemaphores(int numSemaphores,
sk_sp<GrSemaphore> sema = fContext->resourceProvider()->wrapBackendSemaphore(
waitSemaphores[i], kAdopt_GrWrapOwnership);
std::unique_ptr<GrOp> waitOp(GrSemaphoreOp::MakeWait(sema, fRenderTargetProxy.get()));
this->getOpList()->addOp(std::move(waitOp), *this->caps());
this->getRTOpList()->addOp(std::move(waitOp), *this->caps());
}
return true;
}
@ -1811,8 +1802,8 @@ uint32_t GrRenderTargetContext::addDrawOp(const GrClip& clip, std::unique_ptr<Gr
}
op->setClippedBounds(bounds);
return this->getOpList()->addOp(std::move(op), *this->caps(),
std::move(appliedClip), dstProxy);
return this->getRTOpList()->addOp(std::move(op), *this->caps(),
std::move(appliedClip), dstProxy);
}
uint32_t GrRenderTargetContext::addLegacyMeshDrawOp(GrPipelineBuilder&& pipelineBuilder,
@ -1875,7 +1866,7 @@ uint32_t GrRenderTargetContext::addLegacyMeshDrawOp(GrPipelineBuilder&& pipeline
op->addDependenciesTo(this->getOpList(), *this->caps());
op->setClippedBounds(bounds);
return this->getOpList()->addOp(std::move(op), *this->caps());
return this->getRTOpList()->addOp(std::move(op), *this->caps());
}
bool GrRenderTargetContext::setupDstProxy(GrRenderTargetProxy* rtProxy, const GrClip& clip,

View File

@ -356,7 +356,7 @@ protected:
sk_sp<SkColorSpace>, const SkSurfaceProps*, GrAuditTrail*,
GrSingleOwner*, bool managedOpList = true);
SkDEBUGCODE(void validate() const;)
SkDEBUGCODE(void validate() const override;)
private:
inline GrAAType chooseAAType(GrAA aa, GrAllowMixedSamples allowMixedSamples) {
@ -406,8 +406,6 @@ private:
void internalDrawPath(
const GrClip&, GrPaint&&, GrAA, const SkMatrix&, const SkPath&, const GrStyle&);
bool onCopy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
// These perform processing specific to Gr[Mesh]DrawOp-derived ops before recording them into
// the op list. They return the id of the opList to which the op was added, or 0, if it was
// dropped (e.g., due to clipping).
@ -423,7 +421,8 @@ private:
const SkRect& opBounds,
GrXferProcessor::DstProxy* result);
GrRenderTargetOpList* getOpList();
GrRenderTargetOpList* getRTOpList();
GrOpList* getOpList() override;
sk_sp<GrRenderTargetProxy> fRenderTargetProxy;

View File

@ -22,13 +22,13 @@ struct GrUserStencilSettings;
class GrRenderTargetContextPriv {
public:
gr_instanced::InstancedRendering* accessInstancedRendering() const {
return fRenderTargetContext->getOpList()->instancedRendering();
return fRenderTargetContext->getRTOpList()->instancedRendering();
}
// called to note the last clip drawn to the stencil buffer.
// TODO: remove after clipping overhaul.
void setLastClip(int32_t clipStackGenID, const SkIRect& devClipBounds) {
GrRenderTargetOpList* opList = fRenderTargetContext->getOpList();
GrRenderTargetOpList* opList = fRenderTargetContext->getRTOpList();
opList->fLastClipStackGenID = clipStackGenID;
opList->fLastDevClipBounds = devClipBounds;
}
@ -36,7 +36,7 @@ public:
// called to determine if we have to render the clip into SB.
// TODO: remove after clipping overhaul.
bool mustRenderClip(int32_t clipStackGenID, const SkIRect& devClipBounds) const {
GrRenderTargetOpList* opList = fRenderTargetContext->getOpList();
GrRenderTargetOpList* opList = fRenderTargetContext->getRTOpList();
return opList->fLastClipStackGenID != clipStackGenID ||
!opList->fLastDevClipBounds.contains(devClipBounds);
}

View File

@ -96,7 +96,7 @@ public:
GrSurfaceProxy* dst,
GrSurfaceProxy* src,
const SkIRect& srcRect,
const SkIPoint& dstPoint);
const SkIPoint& dstPoint) override;
gr_instanced::InstancedRendering* instancedRendering() const {
SkASSERT(fInstancedRendering);

View File

@ -8,11 +8,16 @@
#include "GrSurfaceContext.h"
#include "GrContextPriv.h"
#include "GrDrawingManager.h"
#include "GrOpList.h"
#include "SkColorSpace_Base.h"
#include "SkGr.h"
#include "../private/GrAuditTrail.h"
#define ASSERT_SINGLE_OWNER \
SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
#define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; }
// In MDB mode the reffing of the 'getLastOpList' call's result allows in-progress
// GrOpLists to be picked up and added to by renderTargetContexts lower in the call
@ -35,6 +40,11 @@ GrSurfaceContext::GrSurfaceContext(GrContext* context,
bool GrSurfaceContext::readPixels(const SkImageInfo& dstInfo, void* dstBuffer,
size_t dstRowBytes, int x, int y, uint32_t flags) {
ASSERT_SINGLE_OWNER
RETURN_FALSE_IF_ABANDONED
SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrSurfaceContext::readPixels");
// TODO: teach GrRenderTarget to take ImageInfo directly to specify the src pixels
GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo, *fContext->caps());
if (kUnknown_GrPixelConfig == config) {
@ -54,6 +64,11 @@ bool GrSurfaceContext::readPixels(const SkImageInfo& dstInfo, void* dstBuffer,
bool GrSurfaceContext::writePixels(const SkImageInfo& srcInfo, const void* srcBuffer,
size_t srcRowBytes, int x, int y, uint32_t flags) {
ASSERT_SINGLE_OWNER
RETURN_FALSE_IF_ABANDONED
SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrSurfaceContext::writePixels");
// TODO: teach GrRenderTarget to take ImageInfo directly to specify the src pixels
GrPixelConfig config = SkImageInfo2GrPixelConfig(srcInfo, *fContext->caps());
if (kUnknown_GrPixelConfig == config) {
@ -68,3 +83,13 @@ bool GrSurfaceContext::writePixels(const SkImageInfo& srcInfo, const void* srcBu
config, srcInfo.colorSpace(),
srcBuffer, srcRowBytes, flags);
}
bool GrSurfaceContext::copy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) {
ASSERT_SINGLE_OWNER
RETURN_FALSE_IF_ABANDONED
SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrSurfaceContext::onCopy");
return this->getOpList()->copySurface(*fContext->caps(),
this->asSurfaceProxy(), src, srcRect, dstPoint);
}

View File

@ -15,6 +15,7 @@
class GrAuditTrail;
class GrContext;
class GrDrawingManager;
class GrOpList;
class GrRenderTargetContext;
class GrRenderTargetProxy;
class GrSingleOwner;
@ -52,14 +53,12 @@ public:
* The end result is only valid src pixels and dst pixels will be touched but the copied
* regions will not be shifted.
*/
bool copy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) {
return this->onCopy(src, srcRect, dstPoint);
}
bool copy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint);
bool copy(GrSurfaceProxy* src) {
return this->onCopy(src,
SkIRect::MakeWH(src->width(), src->height()),
SkIPoint::Make(0, 0));
return this->copy(src,
SkIRect::MakeWH(src->width(), src->height()),
SkIPoint::Make(0, 0));
}
/**
@ -119,6 +118,9 @@ protected:
GrDrawingManager* drawingManager() { return fDrawingManager; }
const GrDrawingManager* drawingManager() const { return fDrawingManager; }
virtual GrOpList* getOpList() = 0;
SkDEBUGCODE(virtual void validate() const = 0;)
SkDEBUGCODE(GrSingleOwner* singleOwner() { return fSingleOwner; })
GrContext* fContext;
@ -126,8 +128,6 @@ protected:
GrAuditTrail* fAuditTrail;
private:
virtual bool onCopy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) = 0;
GrDrawingManager* fDrawingManager;
// In debug builds we guard against improper thread handling

View File

@ -56,7 +56,7 @@ sk_sp<GrRenderTargetProxy> GrTextureContext::asRenderTargetProxyRef() {
return nullptr;
}
GrTextureOpList* GrTextureContext::getOpList() {
GrOpList* GrTextureContext::getOpList() {
ASSERT_SINGLE_OWNER
SkDEBUGCODE(this->validate();)
@ -66,17 +66,3 @@ GrTextureOpList* GrTextureContext::getOpList() {
return fOpList.get();
}
// MDB TODO: move this (and GrRenderTargetContext::copy) to GrSurfaceContext?
bool GrTextureContext::onCopy(GrSurfaceProxy* srcProxy,
const SkIRect& srcRect,
const SkIPoint& dstPoint) {
ASSERT_SINGLE_OWNER
RETURN_FALSE_IF_ABANDONED
SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrTextureContext::onCopy");
return this->getOpList()->copySurface(*fContext->caps(),
fTextureProxy.get(), srcProxy, srcRect, dstPoint);
}

View File

@ -41,14 +41,12 @@ protected:
GrTextureContext(GrContext*, GrDrawingManager*, sk_sp<GrTextureProxy>,
sk_sp<SkColorSpace>, GrAuditTrail*, GrSingleOwner*);
SkDEBUGCODE(void validate() const;)
SkDEBUGCODE(void validate() const override;)
private:
friend class GrDrawingManager; // for ctor
bool onCopy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
GrTextureOpList* getOpList();
GrOpList* getOpList() override;
sk_sp<GrTextureProxy> fTextureProxy;

View File

@ -55,7 +55,7 @@ public:
GrSurfaceProxy* dst,
GrSurfaceProxy* src,
const SkIRect& srcRect,
const SkIPoint& dstPoint);
const SkIPoint& dstPoint) override;
GrTextureOpList* asTextureOpList() override { return this; }