Guard SkGpuDevice
TBR=bsalomon@google.com BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1567093002 Review URL: https://codereview.chromium.org/1567093002
This commit is contained in:
parent
8604ca2d84
commit
ce894007eb
@ -361,6 +361,9 @@ public:
|
||||
|
||||
GrAuditTrail* getAuditTrail() { return &fAuditTrail; }
|
||||
|
||||
/** This is only useful for debug purposes */
|
||||
SkDEBUGCODE(GrSingleOwner* debugSingleOwner() const { return &fSingleOwner; } )
|
||||
|
||||
private:
|
||||
GrGpu* fGpu;
|
||||
const GrCaps* fCaps;
|
||||
|
@ -50,6 +50,9 @@
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
#define ASSERT_SINGLE_OWNER \
|
||||
SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fContext->debugSingleOwner());)
|
||||
|
||||
enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 };
|
||||
|
||||
#if 0
|
||||
@ -227,6 +230,7 @@ GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B
|
||||
|
||||
bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
|
||||
int x, int y) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
DO_DEFERRED_CLEAR();
|
||||
|
||||
// TODO: teach fRenderTarget to take ImageInfo directly to specify the src pixels
|
||||
@ -245,6 +249,7 @@ bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size
|
||||
|
||||
bool SkGpuDevice::onWritePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes,
|
||||
int x, int y) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
// TODO: teach fRenderTarget to take ImageInfo directly to specify the src pixels
|
||||
GrPixelConfig config = SkImageInfo2GrPixelConfig(info);
|
||||
if (kUnknown_GrPixelConfig == config) {
|
||||
@ -263,11 +268,13 @@ bool SkGpuDevice::onWritePixels(const SkImageInfo& info, const void* pixels, siz
|
||||
}
|
||||
|
||||
const SkBitmap& SkGpuDevice::onAccessBitmap() {
|
||||
ASSERT_SINGLE_OWNER
|
||||
DO_DEFERRED_CLEAR();
|
||||
return fLegacyBitmap;
|
||||
}
|
||||
|
||||
bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
DO_DEFERRED_CLEAR();
|
||||
// For compatibility with clients the know we're backed w/ a bitmap, and want to inspect its
|
||||
// genID. When we can hide/remove that fact, we can eliminate this call to notify.
|
||||
@ -277,6 +284,7 @@ bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) {
|
||||
}
|
||||
|
||||
void SkGpuDevice::onAttachToCanvas(SkCanvas* canvas) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
INHERITED::onAttachToCanvas(canvas);
|
||||
|
||||
// Canvas promises that this ptr is valid until onDetachFromCanvas is called
|
||||
@ -284,6 +292,7 @@ void SkGpuDevice::onAttachToCanvas(SkCanvas* canvas) {
|
||||
}
|
||||
|
||||
void SkGpuDevice::onDetachFromCanvas() {
|
||||
ASSERT_SINGLE_OWNER
|
||||
INHERITED::onDetachFromCanvas();
|
||||
fClip.reset();
|
||||
fClipStack.reset(nullptr);
|
||||
@ -292,6 +301,7 @@ void SkGpuDevice::onDetachFromCanvas() {
|
||||
// call this every draw call, to ensure that the context reflects our state,
|
||||
// and not the state from some other canvas/device
|
||||
void SkGpuDevice::prepareDraw(const SkDraw& draw) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
SkASSERT(fClipStack.get());
|
||||
|
||||
SkASSERT(draw.fClipStack && draw.fClipStack == fClipStack);
|
||||
@ -302,11 +312,13 @@ void SkGpuDevice::prepareDraw(const SkDraw& draw) {
|
||||
}
|
||||
|
||||
GrRenderTarget* SkGpuDevice::accessRenderTarget() {
|
||||
ASSERT_SINGLE_OWNER
|
||||
DO_DEFERRED_CLEAR();
|
||||
return fRenderTarget;
|
||||
}
|
||||
|
||||
void SkGpuDevice::clearAll() {
|
||||
ASSERT_SINGLE_OWNER
|
||||
GrColor color = 0;
|
||||
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext);
|
||||
SkIRect rect = SkIRect::MakeWH(this->width(), this->height());
|
||||
@ -315,6 +327,7 @@ void SkGpuDevice::clearAll() {
|
||||
}
|
||||
|
||||
void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
// Caller must have accessed the render target, because it knows the rt must be replaced.
|
||||
SkASSERT(!fNeedClear);
|
||||
|
||||
@ -354,6 +367,7 @@ void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
CHECK_SHOULD_DRAW(draw);
|
||||
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext);
|
||||
|
||||
@ -396,6 +410,7 @@ static bool needs_antialiasing(SkCanvas::PointMode mode, size_t count, const SkP
|
||||
|
||||
void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
|
||||
size_t count, const SkPoint pts[], const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
CHECK_FOR_ANNOTATION(paint);
|
||||
CHECK_SHOULD_DRAW(draw);
|
||||
|
||||
@ -446,6 +461,7 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRect", fContext);
|
||||
CHECK_FOR_ANNOTATION(paint);
|
||||
CHECK_SHOULD_DRAW(draw);
|
||||
@ -492,6 +508,7 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint
|
||||
|
||||
void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
|
||||
const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext);
|
||||
CHECK_FOR_ANNOTATION(paint);
|
||||
CHECK_SHOULD_DRAW(draw);
|
||||
@ -555,6 +572,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
|
||||
|
||||
void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
|
||||
const SkRRect& inner, const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext);
|
||||
CHECK_FOR_ANNOTATION(paint);
|
||||
CHECK_SHOULD_DRAW(draw);
|
||||
@ -587,6 +605,7 @@ void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawOval", fContext);
|
||||
CHECK_FOR_ANNOTATION(paint);
|
||||
CHECK_SHOULD_DRAW(draw);
|
||||
@ -631,6 +650,7 @@ static SkBitmap wrap_texture(GrTexture* texture, int width, int height) {
|
||||
void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
|
||||
const SkPaint& paint, const SkMatrix* prePathMatrix,
|
||||
bool pathIsMutable) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
if (!origSrcPath.isInverseFillType() && !paint.getPathEffect() && !prePathMatrix) {
|
||||
bool isClosed;
|
||||
SkRect rect;
|
||||
@ -723,6 +743,7 @@ bool SkGpuDevice::shouldTileImageID(uint32_t imageID, const SkIRect& imageRect,
|
||||
int maxTileSize,
|
||||
int* tileSize,
|
||||
SkIRect* clippedSubset) const {
|
||||
ASSERT_SINGLE_OWNER
|
||||
// if it's larger than the max tile size, then we have no choice but tiling.
|
||||
if (imageRect.width() > maxTileSize || imageRect.height() > maxTileSize) {
|
||||
determine_clipped_src_rect(fRenderTarget, fClip, viewMatrix, imageRect.size(),
|
||||
@ -769,6 +790,7 @@ bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap,
|
||||
int maxTileSize,
|
||||
int* tileSize,
|
||||
SkIRect* clippedSrcRect) const {
|
||||
ASSERT_SINGLE_OWNER
|
||||
// if bitmap is explictly texture backed then just use the texture
|
||||
if (bitmap.getTexture()) {
|
||||
return false;
|
||||
@ -781,6 +803,7 @@ bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap,
|
||||
bool SkGpuDevice::shouldTileImage(const SkImage* image, const SkRect* srcRectPtr,
|
||||
SkCanvas::SrcRectConstraint constraint, SkFilterQuality quality,
|
||||
const SkMatrix& viewMatrix) const {
|
||||
ASSERT_SINGLE_OWNER
|
||||
// if image is explictly texture backed then just use the texture
|
||||
if (as_IB(image)->peekTexture()) {
|
||||
return false;
|
||||
@ -815,6 +838,7 @@ void SkGpuDevice::drawBitmap(const SkDraw& origDraw,
|
||||
const SkBitmap& bitmap,
|
||||
const SkMatrix& m,
|
||||
const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
CHECK_SHOULD_DRAW(origDraw);
|
||||
SkMatrix viewMatrix;
|
||||
viewMatrix.setConcat(*origDraw.fMatrix, m);
|
||||
@ -915,6 +939,7 @@ void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap,
|
||||
SkCanvas::SrcRectConstraint constraint,
|
||||
int tileSize,
|
||||
bool bicubic) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
// The following pixel lock is technically redundant, but it is desirable
|
||||
// to lock outside of the tile loop to prevent redecoding the whole image
|
||||
// at each tile in cases where 'bitmap' holds an SkDiscardablePixelRef that
|
||||
@ -1107,6 +1132,7 @@ bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
|
||||
const SkImageFilter* filter,
|
||||
const SkImageFilter::Context& ctx,
|
||||
SkBitmap* result, SkIPoint* offset) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
SkASSERT(filter);
|
||||
|
||||
SkImageFilter::DeviceProxy proxy(this);
|
||||
@ -1121,6 +1147,7 @@ bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
|
||||
|
||||
void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
|
||||
int left, int top, const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
// drawSprite is defined to be in device coords.
|
||||
CHECK_SHOULD_DRAW(draw);
|
||||
|
||||
@ -1200,6 +1227,7 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
|
||||
void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
|
||||
const SkRect* src, const SkRect& origDst,
|
||||
const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
if (bitmap.getTexture()) {
|
||||
CHECK_SHOULD_DRAW(draw);
|
||||
GrBitmapTextureAdjuster adjuster(&bitmap);
|
||||
@ -1286,6 +1314,7 @@ void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
|
||||
|
||||
void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
|
||||
int x, int y, const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
// clear of the source device must occur before CHECK_SHOULD_DRAW
|
||||
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDevice", fContext);
|
||||
SkGpuDevice* dev = static_cast<SkGpuDevice*>(device);
|
||||
@ -1364,12 +1393,14 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
|
||||
}
|
||||
|
||||
bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
return filter->canFilterImageGPU();
|
||||
}
|
||||
|
||||
bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src,
|
||||
const SkImageFilter::Context& ctx,
|
||||
SkBitmap* result, SkIPoint* offset) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
// want explicitly our impl, so guard against a subclass of us overriding it
|
||||
if (!this->SkGpuDevice::canHandleImageFilter(filter)) {
|
||||
return false;
|
||||
@ -1394,6 +1425,7 @@ bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src,
|
||||
|
||||
void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x, SkScalar y,
|
||||
const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
SkMatrix viewMatrix = *draw.fMatrix;
|
||||
viewMatrix.preTranslate(x, y);
|
||||
if (as_IB(image)->peekTexture()) {
|
||||
@ -1425,6 +1457,7 @@ void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x
|
||||
void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const SkRect* src,
|
||||
const SkRect& dst, const SkPaint& paint,
|
||||
SkCanvas::SrcRectConstraint constraint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
if (as_IB(image)->peekTexture()) {
|
||||
CHECK_SHOULD_DRAW(draw);
|
||||
GrImageTextureAdjuster adjuster(as_IB(image));
|
||||
@ -1492,6 +1525,7 @@ void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* produc
|
||||
|
||||
void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image,
|
||||
const SkIRect& center, const SkRect& dst, const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
if (as_IB(image)->peekTexture()) {
|
||||
GrImageTextureAdjuster adjuster(as_IB(image));
|
||||
this->drawProducerNine(draw, &adjuster, center, dst, paint);
|
||||
@ -1508,6 +1542,7 @@ void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image,
|
||||
|
||||
void SkGpuDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, const SkIRect& center,
|
||||
const SkRect& dst, const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
if (bitmap.getTexture()) {
|
||||
GrBitmapTextureAdjuster adjuster(&bitmap);
|
||||
this->drawProducerNine(draw, &adjuster, center, dst, paint);
|
||||
@ -1532,6 +1567,7 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
|
||||
SkXfermode* xmode,
|
||||
const uint16_t indices[], int indexCount,
|
||||
const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
CHECK_SHOULD_DRAW(draw);
|
||||
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawVertices", fContext);
|
||||
|
||||
@ -1659,6 +1695,7 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
|
||||
void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRSXform xform[],
|
||||
const SkRect texRect[], const SkColor colors[], int count,
|
||||
SkXfermode::Mode mode, const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
if (paint.isAntiAlias()) {
|
||||
this->INHERITED::drawAtlas(draw, atlas, xform, texRect, colors, count, mode, paint);
|
||||
return;
|
||||
@ -1691,6 +1728,7 @@ void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRS
|
||||
void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
|
||||
size_t byteLength, SkScalar x, SkScalar y,
|
||||
const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
CHECK_SHOULD_DRAW(draw);
|
||||
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawText", fContext);
|
||||
|
||||
@ -1708,6 +1746,7 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
|
||||
void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteLength,
|
||||
const SkScalar pos[], int scalarsPerPos,
|
||||
const SkPoint& offset, const SkPaint& paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPosText", fContext);
|
||||
CHECK_SHOULD_DRAW(draw);
|
||||
|
||||
@ -1725,6 +1764,7 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL
|
||||
|
||||
void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkScalar x, SkScalar y,
|
||||
const SkPaint& paint, SkDrawFilter* drawFilter) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawTextBlob", fContext);
|
||||
CHECK_SHOULD_DRAW(draw);
|
||||
|
||||
@ -1741,6 +1781,7 @@ bool SkGpuDevice::onShouldDisableLCD(const SkPaint& paint) const {
|
||||
}
|
||||
|
||||
void SkGpuDevice::flush() {
|
||||
ASSERT_SINGLE_OWNER
|
||||
DO_DEFERRED_CLEAR();
|
||||
fRenderTarget->prepareForExternalIO();
|
||||
|
||||
@ -1754,6 +1795,7 @@ void SkGpuDevice::flush() {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint*) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
GrSurfaceDesc desc;
|
||||
desc.fConfig = fRenderTarget->config();
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
@ -1786,6 +1828,7 @@ SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint
|
||||
}
|
||||
|
||||
SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps& props) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
// TODO: Change the signature of newSurface to take a budgeted parameter.
|
||||
static const SkSurface::Budgeted kBudgeted = SkSurface::kNo_Budgeted;
|
||||
return SkSurface::NewRenderTarget(fContext, kBudgeted, info, fRenderTarget->desc().fSampleCnt,
|
||||
@ -1794,6 +1837,7 @@ SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps
|
||||
|
||||
bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture* mainPicture,
|
||||
const SkMatrix* matrix, const SkPaint* paint) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
#ifndef SK_IGNORE_GPU_LAYER_HOISTING
|
||||
// todo: should handle this natively
|
||||
if (paint) {
|
||||
@ -1867,6 +1911,7 @@ SkImageFilter::Cache* SkGpuDevice::NewImageFilterCache() {
|
||||
}
|
||||
|
||||
SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
|
||||
ASSERT_SINGLE_OWNER
|
||||
// We always return a transient cache, so it is freed after each
|
||||
// filter traversal.
|
||||
return SkGpuDevice::NewImageFilterCache();
|
||||
|
Loading…
Reference in New Issue
Block a user