diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-11-13 16:02:18 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-11-13 16:02:18 +0000 |
commit | ec3ca87d331c4b7058a0fff376a05e84ae0619ca (patch) | |
tree | 9817818fdea1dcac2ed07a905c4132f20c12bbca | |
parent | 5308c83a366f965c308862bed1b6acf594af3df9 (diff) |
Revert "Revert "switch GatherPixelRefs to use SkBaseDevice instead of SkBitmapDevice""
This reverts commit ff0152ec5e2a0faf38ae1a317c5d77df08139104.
BUG=
Review URL: https://codereview.chromium.org/68203018
git-svn-id: http://skia.googlecode.com/svn/trunk@12271 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/core/SkBitmapDevice.h | 7 | ||||
-rw-r--r-- | include/core/SkDevice.h | 8 | ||||
-rw-r--r-- | include/gpu/SkGpuDevice.h | 1 | ||||
-rw-r--r-- | src/core/SkBitmapDevice.cpp | 8 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 7 | ||||
-rw-r--r-- | src/utils/SkPictureUtils.cpp | 95 |
6 files changed, 72 insertions, 54 deletions
diff --git a/include/core/SkBitmapDevice.h b/include/core/SkBitmapDevice.h index 691202004e..83f480c60c 100644 --- a/include/core/SkBitmapDevice.h +++ b/include/core/SkBitmapDevice.h @@ -73,13 +73,6 @@ public: */ virtual int height() const SK_OVERRIDE { return fBitmap.height(); } - /** - * Return the bounds of the device in the coordinate space of the root - * canvas. The root device will have its top-left at 0,0, but other devices - * such as those associated with saveLayer may have a non-zero origin. - */ - virtual void getGlobalBounds(SkIRect* bounds) const SK_OVERRIDE; - /** Returns true if the device's bitmap's config treats every pixels as implicitly opaque. */ diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index 8dce0a49e5..b1f430ec77 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -83,7 +83,12 @@ public: * canvas. The root device will have its top-left at 0,0, but other devices * such as those associated with saveLayer may have a non-zero origin. */ - virtual void getGlobalBounds(SkIRect* bounds) const = 0; + void getGlobalBounds(SkIRect* bounds) const { + SkASSERT(bounds); + const SkIPoint& origin = this->getOrigin(); + bounds->setXYWH(origin.x(), origin.y(), this->width(), this->height()); + } + /** Returns true if the device's bitmap's config treats every pixel as implicitly opaque. @@ -383,6 +388,7 @@ private: // used to change the backend's pixels (and possibly config/rowbytes) // but cannot change the width/height, so there should be no change to // any clip information. + // TODO: move to SkBitmapDevice virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) = 0; // just called by SkCanvas when built as a layer diff --git a/include/gpu/SkGpuDevice.h b/include/gpu/SkGpuDevice.h index 29f59f28df..d37f63d7a0 100644 --- a/include/gpu/SkGpuDevice.h +++ b/include/gpu/SkGpuDevice.h @@ -72,7 +72,6 @@ public: virtual int height() const SK_OVERRIDE { return NULL == fRenderTarget ? 0 : fRenderTarget->height(); } - virtual void getGlobalBounds(SkIRect* bounds) const SK_OVERRIDE; virtual bool isOpaque() const SK_OVERRIDE { return NULL == fRenderTarget ? false : kRGB_565_GrPixelConfig == fRenderTarget->config(); diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index 7731a920dc..369f10c1bf 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -77,14 +77,6 @@ void SkBitmapDevice::unlockPixels() { } } -void SkBitmapDevice::getGlobalBounds(SkIRect* bounds) const { - if (NULL != bounds) { - const SkIPoint& origin = this->getOrigin(); - bounds->setXYWH(origin.x(), origin.y(), - fBitmap.width(), fBitmap.height()); - } -} - void SkBitmapDevice::clear(SkColor color) { fBitmap.eraseColor(color); } diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 429ee9f8e2..747688ed8b 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -513,13 +513,6 @@ inline bool skPaint2GrPaintShader(SkGpuDevice* dev, } /////////////////////////////////////////////////////////////////////////////// -void SkGpuDevice::getGlobalBounds(SkIRect* bounds) const { - if (NULL != bounds) { - const SkIPoint& origin = this->getOrigin(); - bounds->setXYWH(origin.x(), origin.y(), - this->width(), this->height()); - } -} SkBitmap::Config SkGpuDevice::config() const { if (NULL == fRenderTarget) { diff --git a/src/utils/SkPictureUtils.cpp b/src/utils/SkPictureUtils.cpp index ffd9aa4429..fa16af07f2 100644 --- a/src/utils/SkPictureUtils.cpp +++ b/src/utils/SkPictureUtils.cpp @@ -45,34 +45,38 @@ static void nothing_to_do() {} /** * This device will route all bitmaps (primitives and in shaders) to its PRSet. * It should never actually draw anything, so there need not be any pixels - * behind its device-bitmap. - * FIXME: Derive from SkBaseDevice. + * behind its device. */ -class GatherPixelRefDevice : public SkBitmapDevice { -private: - PixelRefSet* fPRSet; - - void addBitmap(const SkBitmap& bm) { - fPRSet->add(bm.pixelRef()); +class GatherPixelRefDevice : public SkBaseDevice { +public: + GatherPixelRefDevice(int width, int height, PixelRefSet* prset) { + fSize.set(width, height); + fEmptyBitmap.setConfig(SkBitmap::kNo_Config, width, height); + fPRSet = prset; } - void addBitmapFromPaint(const SkPaint& paint) { - SkShader* shader = paint.getShader(); - if (shader) { - SkBitmap bm; - // Check whether the shader is a gradient in order to short-circuit - // call to asABitmap to prevent generation of bitmaps from - // gradient shaders, which implement asABitmap. - if (SkShader::kNone_GradientType == shader->asAGradient(NULL) && - shader->asABitmap(&bm, NULL, NULL)) { - fPRSet->add(bm.pixelRef()); - } - } + virtual uint32_t getDeviceCapabilities() SK_OVERRIDE { return 0; } + virtual int width() const SK_OVERRIDE { return fSize.width(); } + virtual int height() const SK_OVERRIDE { return fSize.height(); } + virtual bool isOpaque() const SK_OVERRIDE { return false; } + virtual SkBitmap::Config config() const SK_OVERRIDE { + return SkBitmap::kNo_Config; } - -public: - GatherPixelRefDevice(const SkBitmap& bm, PixelRefSet* prset) : SkBitmapDevice(bm) { - fPRSet = prset; + virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE { return NULL; } + virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE { + return true; + } + // TODO: allow this call to return failure, or move to SkBitmapDevice only. + virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE { + return fEmptyBitmap; + } + virtual void lockPixels() SK_OVERRIDE { nothing_to_do(); } + virtual void unlockPixels() SK_OVERRIDE { nothing_to_do(); } + virtual bool allowImageFilter(SkImageFilter*) SK_OVERRIDE { return false; } + virtual bool canHandleImageFilter(SkImageFilter*) SK_OVERRIDE { return false; } + virtual bool filterImage(SkImageFilter*, const SkBitmap&, const SkMatrix&, + SkBitmap* result, SkIPoint* offset) SK_OVERRIDE { + return false; } virtual void clear(SkColor color) SK_OVERRIDE { @@ -156,8 +160,43 @@ protected: return false; } + virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRIDE { + not_supported(); + } + virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config, + int width, int height, + bool isOpaque, + Usage usage) SK_OVERRIDE { + // we expect to only get called via savelayer, in which case it is fine. + SkASSERT(kSaveLayer_Usage == usage); + return SkNEW_ARGS(GatherPixelRefDevice, (width, height, fPRSet)); + } + virtual void flush() SK_OVERRIDE {} + private: - typedef SkBitmapDevice INHERITED; + PixelRefSet* fPRSet; + SkBitmap fEmptyBitmap; // legacy -- need to remove the need for this guy + SkISize fSize; + + void addBitmap(const SkBitmap& bm) { + fPRSet->add(bm.pixelRef()); + } + + void addBitmapFromPaint(const SkPaint& paint) { + SkShader* shader = paint.getShader(); + if (shader) { + SkBitmap bm; + // Check whether the shader is a gradient in order to short-circuit + // call to asABitmap to prevent generation of bitmaps from + // gradient shaders, which implement asABitmap. + if (SkShader::kNone_GradientType == shader->asAGradient(NULL) && + shader->asABitmap(&bm, NULL, NULL)) { + fPRSet->add(bm.pixelRef()); + } + } + } + + typedef SkBaseDevice INHERITED; }; class NoSaveLayerCanvas : public SkCanvas { @@ -214,11 +253,7 @@ SkData* SkPictureUtils::GatherPixelRefs(SkPicture* pict, const SkRect& area) { SkTDArray<SkPixelRef*> array; PixelRefSet prset(&array); - SkBitmap emptyBitmap; - emptyBitmap.setConfig(SkBitmap::kARGB_8888_Config, pict->width(), pict->height()); - // note: we do not set any pixels (shouldn't need to) - - GatherPixelRefDevice device(emptyBitmap, &prset); + GatherPixelRefDevice device(pict->width(), pict->height(), &prset); NoSaveLayerCanvas canvas(&device); canvas.clipRect(area, SkRegion::kIntersect_Op, false); |