Reland r5861 but leave setMatrixClip virtual on SkDevice (IOW this is a partial revert of r5871 which reverted r5861).

Unreviewed
Review URL: https://codereview.appspot.com/6631062

git-svn-id: http://skia.googlecode.com/svn/trunk@5881 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2012-10-10 15:25:50 +00:00
parent 2a827e81b3
commit a6926b1f03
6 changed files with 34 additions and 110 deletions

View File

@ -978,7 +978,6 @@ private:
uint32_t fMCRecStorage[32];
SkBounder* fBounder;
SkDevice* fLastDeviceToGainFocus;
int fSaveLayerCount; // number of successful saveLayer calls
SkMetaData* fMetaData;
@ -989,9 +988,7 @@ private:
fSurfaceBase = sb;
}
friend class SkSurface_Base;
void prepareForDeviceDraw(SkDevice*, const SkMatrix&, const SkRegion&);
bool fDeviceCMDirty; // cleared by updateDeviceCMCache()
void updateDeviceCMCache();

View File

@ -188,6 +188,10 @@ protected:
virtual bool filterTextFlags(const SkPaint& paint, TextFlags*);
/**
*
* DEPRECATED: This will be removed in a future change. Device subclasses
* should use the matrix and clip from the SkDraw passed to draw functions.
*
* Called with the correct matrix and clip before this device is drawn
* to using those settings. If your subclass overrides this, be sure to
* call through to the base class as well.
@ -198,16 +202,9 @@ protected:
* picture of the current clip. (i.e. if you regionize all of the geometry
* in the clipstack, you will arrive at an equivalent region to the one
* passed in).
*/
virtual void setMatrixClip(const SkMatrix&, const SkRegion&,
const SkClipStack&);
/** Called when this device gains focus (i.e becomes the current device
for drawing).
*/
virtual void gainFocus(const SkMatrix&, const SkRegion&) {
SkASSERT(fAttachedToCanvas);
}
*/
virtual void setMatrixClip(const SkMatrix&, const SkRegion&,
const SkClipStack&);
/** Clears the entire device to the specified color (including alpha).
* Ignores the clip.

View File

@ -51,12 +51,6 @@ public:
GrContext* context() const { return fContext; }
/**
* Override from SkGpuDevice, so we can set our FBO to be the render target
* The canvas parameter must be a SkGpuCanvas
*/
virtual void gainFocus(const SkMatrix&, const SkRegion&) SK_OVERRIDE;
virtual SkGpuRenderTarget* accessRenderTarget() SK_OVERRIDE;
// overrides from SkDevice
@ -65,9 +59,6 @@ public:
virtual void writePixels(const SkBitmap& bitmap, int x, int y,
SkCanvas::Config8888 config8888) SK_OVERRIDE;
virtual void setMatrixClip(const SkMatrix& matrix, const SkRegion& clip,
const SkClipStack&) SK_OVERRIDE;
virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE;
virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
const SkPoint[], const SkPaint& paint) SK_OVERRIDE;
@ -134,10 +125,9 @@ private:
GrClipData fClipData;
// state for our offscreen render-target
// state for our render-target
GrRenderTarget* fRenderTarget;
bool fNeedClear;
bool fNeedPrepareRenderTarget;
// called from rt and tex cons
void initFromRenderTarget(GrContext*, GrRenderTarget*, bool cached);
@ -154,7 +144,7 @@ private:
SkDrawProcs* initDrawForText(GrTextContext*);
bool bindDeviceAsTexture(GrPaint* paint);
void prepareRenderTarget(const SkDraw&);
void prepareDraw(const SkDraw&); // sets the render target, clip, and matrix on GrContext.
bool shouldTileBitmap(const SkBitmap& bitmap,
const GrTextureParams& sampler,
const SkRect* srcRectPtr) const;

View File

@ -244,7 +244,6 @@ public:
}
// fCurrLayer may be NULL now
fCanvas->prepareForDeviceDraw(fDevice, *fMatrix, *fClip);
return true;
}
return false;
@ -441,7 +440,6 @@ SkDevice* SkCanvas::init(SkDevice* device) {
fBounder = NULL;
fLocalBoundsCompareType.setEmpty();
fLocalBoundsCompareTypeDirty = true;
fLastDeviceToGainFocus = NULL;
fDeviceCMDirty = false;
fSaveLayerCount = 0;
fMetaData = NULL;
@ -664,15 +662,6 @@ void SkCanvas::updateDeviceCMCache() {
}
}
void SkCanvas::prepareForDeviceDraw(SkDevice* device, const SkMatrix& matrix,
const SkRegion& clip) {
SkASSERT(device);
if (fLastDeviceToGainFocus != device) {
device->gainFocus(matrix, clip);
fLastDeviceToGainFocus = device;
}
}
///////////////////////////////////////////////////////////////////////////////
int SkCanvas::internalSave(SaveFlags flags) {
@ -859,13 +848,6 @@ void SkCanvas::internalRestore() {
fDeviceCMDirty = true;
fLocalBoundsCompareTypeDirty = true;
// Dirty this pointer to handle the case of a new device created at the same address as the
// device we are restoring from. E.g.:
// saveLayer (creates a device)
// drawSomething
// restore (deletes the device)
// saveLayer (oops new device at the same address)
fLastDeviceToGainFocus = NULL;
fClipStack.restore();
// reserve our layer (if any)

View File

@ -30,12 +30,10 @@
#define CHECK_SHOULD_DRAW(draw) \
do { \
if (gShouldDrawProc && !gShouldDrawProc()) return; \
this->prepareRenderTarget(draw); \
GrAssert(!fNeedClear) \
this->prepareDraw(draw); \
} while (0)
#else
#define CHECK_SHOULD_DRAW(draw) this->prepareRenderTarget(draw); \
GrAssert(!fNeedClear)
#define CHECK_SHOULD_DRAW(draw) this->prepareDraw(draw)
#endif
// we use the same texture slot on GrPaint for bitmaps and shaders
@ -46,7 +44,6 @@ enum {
kColorFilterTextureIdx = 1
};
#define MAX_BLUR_SIGMA 4.0f
// FIXME: This value comes from from SkBlurMaskFilter.cpp.
// Should probably be put in a common header someplace.
@ -64,11 +61,10 @@ enum {
// a sub region of a larger source image.
#define COLOR_BLEED_TOLERANCE SkFloatToScalar(0.001f)
#define DO_DEFERRED_CLEAR \
#define DO_DEFERRED_CLEAR() \
do { \
if (fNeedClear) { \
this->clear(0x0); \
fNeedClear = false; \
} \
} while (false) \
@ -182,7 +178,6 @@ SkGpuDevice::SkGpuDevice(GrContext* context, GrRenderTarget* renderTarget)
void SkGpuDevice::initFromRenderTarget(GrContext* context,
GrRenderTarget* renderTarget,
bool cached) {
fNeedPrepareRenderTarget = false;
fDrawProcs = NULL;
fContext = context;
@ -214,7 +209,6 @@ SkGpuDevice::SkGpuDevice(GrContext* context,
int height)
: SkDevice(config, width, height, false /*isOpaque*/) {
fNeedPrepareRenderTarget = false;
fDrawProcs = NULL;
fContext = context;
@ -258,9 +252,11 @@ SkGpuDevice::~SkGpuDevice() {
delete fDrawProcs;
}
// The SkGpuDevice gives the context the render target (e.g., in gainFocus)
// This call gives the context a chance to relinquish it
fContext->setRenderTarget(NULL);
// The GrContext takes a ref on the target. We don't want to cause the render
// target to be unnecessarily kept alive.
if (fContext->getRenderTarget() == fRenderTarget) {
fContext->setRenderTarget(NULL);
}
SkSafeUnref(fRenderTarget);
fContext->unref();
@ -269,9 +265,8 @@ SkGpuDevice::~SkGpuDevice() {
///////////////////////////////////////////////////////////////////////////////
void SkGpuDevice::makeRenderTargetCurrent() {
DO_DEFERRED_CLEAR;
DO_DEFERRED_CLEAR();
fContext->setRenderTarget(fRenderTarget);
fNeedPrepareRenderTarget = true;
}
///////////////////////////////////////////////////////////////////////////////
@ -308,7 +303,7 @@ GrPixelConfig config8888_to_grconfig_and_flags(SkCanvas::Config8888 config8888,
bool SkGpuDevice::onReadPixels(const SkBitmap& bitmap,
int x, int y,
SkCanvas::Config8888 config8888) {
DO_DEFERRED_CLEAR;
DO_DEFERRED_CLEAR();
SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config());
SkASSERT(!bitmap.isNull());
SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.height())));
@ -411,64 +406,29 @@ static void check_bounds(const GrClipData& clipData,
///////////////////////////////////////////////////////////////////////////////
static void set_matrix_and_clip(GrContext* context, const SkMatrix& matrix,
GrClipData& clipData,
const SkRegion& clipRegion,
const SkIPoint& origin,
int renderTargetWidth, int renderTargetHeight) {
context->setMatrix(matrix);
clipData.fOrigin = origin;
#ifdef SK_DEBUG
check_bounds(clipData, clipRegion,
renderTargetWidth, renderTargetHeight);
#endif
context->setClip(&clipData);
}
// call this every draw call, to ensure that the context reflects our state,
// and not the state from some other canvas/device
void SkGpuDevice::prepareRenderTarget(const SkDraw& draw) {
GrAssert(NULL != fClipData.fClipStack);
if (fNeedPrepareRenderTarget ||
fContext->getRenderTarget() != fRenderTarget) {
fContext->setRenderTarget(fRenderTarget);
SkASSERT(draw.fClipStack && draw.fClipStack == fClipData.fClipStack);
set_matrix_and_clip(fContext, *draw.fMatrix,
fClipData, *draw.fClip, this->getOrigin(),
fRenderTarget->width(), fRenderTarget->height());
fNeedPrepareRenderTarget = false;
}
}
void SkGpuDevice::setMatrixClip(const SkMatrix& matrix, const SkRegion& clip,
const SkClipStack& clipStack) {
this->INHERITED::setMatrixClip(matrix, clip, clipStack);
// We don't need to set them now because the context may not reflect this device.
fNeedPrepareRenderTarget = true;
}
void SkGpuDevice::gainFocus(const SkMatrix& matrix, const SkRegion& clip) {
void SkGpuDevice::prepareDraw(const SkDraw& draw) {
GrAssert(NULL != fClipData.fClipStack);
fContext->setRenderTarget(fRenderTarget);
this->INHERITED::gainFocus(matrix, clip);
SkASSERT(draw.fClipStack && draw.fClipStack == fClipData.fClipStack);
set_matrix_and_clip(fContext, matrix, fClipData, clip, this->getOrigin(),
fRenderTarget->width(), fRenderTarget->height());
fContext->setMatrix(*draw.fMatrix);
fClipData.fOrigin = this->getOrigin();
DO_DEFERRED_CLEAR;
#ifdef SK_DEBUG
check_bounds(fClipData, *draw.fClip, fRenderTarget->width(), fRenderTarget->height());
#endif
fContext->setClip(&fClipData);
DO_DEFERRED_CLEAR();
}
SkGpuRenderTarget* SkGpuDevice::accessRenderTarget() {
DO_DEFERRED_CLEAR;
DO_DEFERRED_CLEAR();
return (SkGpuRenderTarget*)fRenderTarget;
}
@ -662,6 +622,7 @@ inline bool skPaint2GrPaintShader(SkGpuDevice* dev,
///////////////////////////////////////////////////////////////////////////////
void SkGpuDevice::clear(SkColor color) {
fContext->clear(NULL, color, fRenderTarget);
fNeedClear = false;
}
void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
@ -1927,7 +1888,7 @@ bool SkGpuDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) {
}
void SkGpuDevice::flush() {
DO_DEFERRED_CLEAR;
DO_DEFERRED_CLEAR();
fContext->resolveRenderTarget(fRenderTarget);
}

View File

@ -268,9 +268,6 @@ protected:
virtual bool filterTextFlags(const SkPaint& paint, TextFlags*)
SK_OVERRIDE
{return false;}
virtual void setMatrixClip(const SkMatrix&, const SkRegion&,
const SkClipStack&) SK_OVERRIDE
{}
// None of the following drawing methods should ever get called on the
// deferred device