diff options
author | reed <reed@google.com> | 2014-06-27 11:34:19 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-06-27 11:34:19 -0700 |
commit | 89443aba5bfa2b040dc9fd24938b7d0b3decd737 (patch) | |
tree | 48444359fc93d9e8cab2bfa6d203efe3c123835b | |
parent | 479fbaf3bd65346c8dba2363aadde3b57bddd195 (diff) |
change gpudevice and pdfdevice to inherit from basedevice
BUG=skia:
R=robertphillips@google.com
Author: reed@google.com
Review URL: https://codereview.chromium.org/354133002
-rw-r--r-- | include/core/SkBitmapDevice.h | 44 | ||||
-rw-r--r-- | include/core/SkDevice.h | 22 | ||||
-rw-r--r-- | include/gpu/SkGpuDevice.h | 11 | ||||
-rw-r--r-- | include/pdf/SkPDFDevice.h | 23 | ||||
-rw-r--r-- | src/core/SkBitmapDevice.cpp | 14 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 24 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 78 | ||||
-rw-r--r-- | src/utils/SkGatherPixelRefsAndRects.h | 7 |
8 files changed, 85 insertions, 138 deletions
diff --git a/include/core/SkBitmapDevice.h b/include/core/SkBitmapDevice.h index cc6d2adc6c..e1765e56ab 100644 --- a/include/core/SkBitmapDevice.h +++ b/include/core/SkBitmapDevice.h @@ -35,20 +35,7 @@ public: virtual SkImageInfo imageInfo() const SK_OVERRIDE; - /** - * Return the device's associated gpu render target, or NULL. - */ - virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE { return NULL; } - protected: - /** - * Device may filter the text flags for drawing text here. If it wants to - * make a change to the specified values, it should write them into the - * textflags parameter (output) and return true. If the paint is fine as - * is, then ignore the textflags parameter and return false. - * - * The baseclass SkDevice filters based on its depth and blitters. - */ virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE; /** Clears the entire device to the specified color (including alpha). @@ -149,33 +136,6 @@ protected: virtual void lockPixels() SK_OVERRIDE; virtual void unlockPixels() SK_OVERRIDE; - /** - * Returns true if the device allows processing of this imagefilter. If - * false is returned, then the filter is ignored. This may happen for - * some subclasses that do not support pixel manipulations after drawing - * has occurred (e.g. printing). The default implementation returns true. - */ - virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE; - - /** - * Override and return true for filters that the device can handle - * intrinsically. Doing so means that SkCanvas will pass-through this - * filter to drawSprite and drawDevice (and potentially filterImage). - * Returning false means the SkCanvas will have apply the filter itself, - * and just pass the resulting image to the device. - */ - virtual bool canHandleImageFilter(const SkImageFilter*) SK_OVERRIDE; - - /** - * Related (but not required) to canHandleImageFilter, this method returns - * true if the device could apply the filter to the src bitmap and return - * the result (and updates offset as needed). - * If the device does not recognize or support this filter, - * it just returns false and leaves result and offset unchanged. - */ - virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter::Context&, - SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; - private: friend class SkCanvas; friend struct DeviceCM; //for setMatrixClip @@ -193,10 +153,6 @@ private: virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE; - /** Causes any deferred drawing to the device to be completed. - */ - virtual void flush() SK_OVERRIDE {} - virtual SkSurface* newSurface(const SkImageInfo&) SK_OVERRIDE; virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes) SK_OVERRIDE; diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index 4b3db126f1..80bf24283d 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -104,7 +104,7 @@ public: /** * Return the device's associated gpu render target, or NULL. */ - virtual GrRenderTarget* accessRenderTarget() = 0; + virtual GrRenderTarget* accessRenderTarget() { return NULL; } /** @@ -157,10 +157,8 @@ protected: * make a change to the specified values, it should write them into the * textflags parameter (output) and return true. If the paint is fine as * is, then ignore the textflags parameter and return false. - * - * The baseclass SkBaseDevice filters based on its depth and blitters. */ - virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) = 0; + virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) { return false; } /** * @@ -273,8 +271,8 @@ protected: /** Called when this device is installed into a Canvas. Balanced by a call to unlockPixels() when the device is removed from a Canvas. */ - virtual void lockPixels() = 0; - virtual void unlockPixels() = 0; + virtual void lockPixels() {} + virtual void unlockPixels() {} /** * Returns true if the device allows processing of this imagefilter. If @@ -282,7 +280,7 @@ protected: * some subclasses that do not support pixel manipulations after drawing * has occurred (e.g. printing). The default implementation returns true. */ - virtual bool allowImageFilter(const SkImageFilter*) = 0; + virtual bool allowImageFilter(const SkImageFilter*) { return true; } /** * Override and return true for filters that the device can handle @@ -291,7 +289,7 @@ protected: * Returning false means the SkCanvas will have apply the filter itself, * and just pass the resulting image to the device. */ - virtual bool canHandleImageFilter(const SkImageFilter*) = 0; + virtual bool canHandleImageFilter(const SkImageFilter*) { return false; } /** * Related (but not required) to canHandleImageFilter, this method returns @@ -302,7 +300,9 @@ protected: */ virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter::Context& ctx, - SkBitmap* result, SkIPoint* offset) = 0; + SkBitmap* result, SkIPoint* offset) { + return false; + } protected: // default impl returns NULL @@ -380,7 +380,7 @@ private: // 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; + virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) {} // just called by SkCanvas when built as a layer void setOrigin(int x, int y) { fOrigin.set(x, y); } @@ -393,7 +393,7 @@ private: /** Causes any deferred drawing to the device to be completed. */ - virtual void flush() = 0; + virtual void flush() {} SkIPoint fOrigin; SkMetaData* fMetaData; diff --git a/include/gpu/SkGpuDevice.h b/include/gpu/SkGpuDevice.h index 0b6bbc1857..6451e15c9b 100644 --- a/include/gpu/SkGpuDevice.h +++ b/include/gpu/SkGpuDevice.h @@ -13,7 +13,7 @@ #include "SkGr.h" #include "SkBitmap.h" -#include "SkBitmapDevice.h" +#include "SkDevice.h" #include "SkPicture.h" #include "SkRegion.h" #include "GrContext.h" @@ -24,10 +24,10 @@ struct GrSkDrawProcs; class GrTextContext; /** - * Subclass of SkBitmapDevice, which directs all drawing to the GrGpu owned by the + * Subclass of SkBaseDevice, which directs all drawing to the GrGpu owned by the * canvas. */ -class SK_API SkGpuDevice : public SkBitmapDevice { +class SK_API SkGpuDevice : public SkBaseDevice { public: enum Flags { kNeedClear_Flag = 1 << 0, //!< Surface requires an initial clear @@ -161,6 +161,9 @@ private: GrRenderTarget* fRenderTarget; bool fNeedClear; + // remove when our clients don't rely on accessBitmap() + SkBitmap fLegacyBitmap; + // called from rt and tex cons void initFromRenderTarget(GrContext*, GrRenderTarget*, unsigned flags); @@ -214,7 +217,7 @@ private: static SkPicture::AccelData::Key ComputeAccelDataKey(); - typedef SkBitmapDevice INHERITED; + typedef SkBaseDevice INHERITED; }; #endif diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h index e250a6de4f..bcdcfb24e4 100644 --- a/include/pdf/SkPDFDevice.h +++ b/include/pdf/SkPDFDevice.h @@ -10,7 +10,7 @@ #ifndef SkPDFDevice_DEFINED #define SkPDFDevice_DEFINED -#include "SkBitmapDevice.h" +#include "SkDevice.h" #include "SkBitmap.h" #include "SkCanvas.h" #include "SkPaint.h" @@ -45,7 +45,7 @@ struct NamedDestination; The drawing context for the PDF backend. */ -class SkPDFDevice : public SkBitmapDevice { +class SkPDFDevice : public SkBaseDevice { public: /** Create a PDF drawing context with the given width and height. * 72 points/in means letter paper is 612x792. @@ -82,8 +82,8 @@ public: size_t count, const SkPoint[], const SkPaint& paint) SK_OVERRIDE; virtual void drawRect(const SkDraw&, const SkRect& r, const SkPaint& paint); - virtual void drawRRect(const SkDraw&, const SkRRect& rr, - const SkPaint& paint) SK_OVERRIDE; + virtual void drawOval(const SkDraw&, const SkRect& oval, const SkPaint& paint) SK_OVERRIDE; + virtual void drawRRect(const SkDraw&, const SkRRect& rr, const SkPaint& paint) SK_OVERRIDE; virtual void drawPath(const SkDraw&, const SkPath& origpath, const SkPaint& paint, const SkMatrix* prePathMatrix, bool pathIsMutable) SK_OVERRIDE; @@ -113,6 +113,7 @@ public: virtual void onAttachToCanvas(SkCanvas* canvas) SK_OVERRIDE; virtual void onDetachFromCanvas() SK_OVERRIDE; + virtual SkImageInfo imageInfo() const SK_OVERRIDE; enum DrawingArea { kContent_DrawingArea, // Drawing area for the page content. @@ -208,7 +209,15 @@ public: } protected: - virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE; + virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE { + return fLegacyBitmap; + } + + virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE { + return false; + } + + virtual SkSurface* newSurface(const SkImageInfo&) SK_OVERRIDE; private: // TODO(vandebo): push most of SkPDFDevice's state into a core object in @@ -248,6 +257,8 @@ private: SkPicture::EncodeBitmap fEncoder; SkScalar fRasterDpi; + SkBitmap fLegacyBitmap; + SkPDFDevice(const SkISize& layerSize, const SkClipStack& existingClipStack, const SkRegion& existingClipRegion); @@ -323,7 +334,7 @@ private: void defineNamedDestination(SkData* nameData, const SkPoint& point, const SkMatrix& matrix); - typedef SkBitmapDevice INHERITED; + typedef SkBaseDevice INHERITED; // TODO(edisonn): Only SkDocument_PDF and SkPDFImageShader should be able to create // an SkPDFDevice diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index 0f3cc2be50..86c5702f03 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -132,20 +132,6 @@ const SkBitmap& SkBitmapDevice::onAccessBitmap() { return fBitmap; } -bool SkBitmapDevice::canHandleImageFilter(const SkImageFilter*) { - return false; -} - -bool SkBitmapDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, - const SkImageFilter::Context& ctx, SkBitmap* result, - SkIPoint* offset) { - return false; -} - -bool SkBitmapDevice::allowImageFilter(const SkImageFilter*) { - return true; -} - void* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { if (fBitmap.getPixels()) { *info = fBitmap.info(); diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index d34170cba1..3b82a33c9c 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -127,16 +127,6 @@ public: /////////////////////////////////////////////////////////////////////////////// -/* - * GrRenderTarget does not know its opaqueness, only its config, so we have - * to make conservative guesses when we return an "equivalent" bitmap. - */ -static SkBitmap make_bitmap(GrContext* context, GrRenderTarget* renderTarget) { - SkBitmap bitmap; - bitmap.setInfo(renderTarget->info()); - return bitmap; -} - SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, unsigned flags) { SkASSERT(NULL != surface); if (NULL == surface->asRenderTarget() || NULL == surface->getContext()) { @@ -149,13 +139,11 @@ SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, unsigned flags) { } } -SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture, unsigned flags) - : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { +SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture, unsigned flags) { this->initFromRenderTarget(context, texture->asRenderTarget(), flags); } -SkGpuDevice::SkGpuDevice(GrContext* context, GrRenderTarget* renderTarget, unsigned flags) - : SkBitmapDevice(make_bitmap(context, renderTarget)) { +SkGpuDevice::SkGpuDevice(GrContext* context, GrRenderTarget* renderTarget, unsigned flags) { this->initFromRenderTarget(context, renderTarget, flags); } @@ -185,8 +173,8 @@ void SkGpuDevice::initFromRenderTarget(GrContext* context, SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (surface->info(), surface, SkToBool(flags & kCached_Flag))); - - this->setPixelRef(pr)->unref(); + fLegacyBitmap.setInfo(surface->info()); + fLegacyBitmap.setPixelRef(pr)->unref(); bool useDFFonts = !!(flags & kDFFonts_Flag); fMainTextContext = fContext->createTextContext(fRenderTarget, fLeakyProperties, useDFFonts); @@ -290,14 +278,14 @@ bool SkGpuDevice::onWritePixels(const SkImageInfo& info, const void* pixels, siz fRenderTarget->writePixels(x, y, info.width(), info.height(), config, pixels, rowBytes, flags); // need to bump our genID for compatibility with clients that "know" we have a bitmap - this->onAccessBitmap().notifyPixelsChanged(); + fLegacyBitmap.notifyPixelsChanged(); return true; } const SkBitmap& SkGpuDevice::onAccessBitmap() { DO_DEFERRED_CLEAR(); - return INHERITED::onAccessBitmap(); + return fLegacyBitmap; } void SkGpuDevice::onAttachToCanvas(SkCanvas* canvas) { diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index ab4d71d37f..e571477e43 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -29,6 +29,7 @@ #include "SkRect.h" #include "SkRRect.h" #include "SkString.h" +#include "SkSurface.h" #include "SkTextFormatParams.h" #include "SkTemplates.h" #include "SkTypefacePriv.h" @@ -702,8 +703,8 @@ private: //////////////////////////////////////////////////////////////////////////////// -static inline SkBitmap makeContentBitmap(const SkISize& contentSize, - const SkMatrix* initialTransform) { +static inline SkImageInfo make_content_info(const SkISize& contentSize, + const SkMatrix* initialTransform) { SkImageInfo info; if (initialTransform) { // Compute the size of the drawing area. @@ -723,24 +724,22 @@ static inline SkBitmap makeContentBitmap(const SkISize& contentSize, info = SkImageInfo::MakeUnknown(abs(contentSize.fWidth), abs(contentSize.fHeight)); } - - SkBitmap bitmap; - bitmap.setInfo(info); - return bitmap; + return info; } // TODO(vandebo) change pageSize to SkSize. -// TODO: inherit from SkBaseDevice instead of SkBitmapDevice SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, const SkMatrix& initialTransform) - : SkBitmapDevice(makeContentBitmap(contentSize, &initialTransform)), - fPageSize(pageSize), - fContentSize(contentSize), - fLastContentEntry(NULL), - fLastMarginContentEntry(NULL), - fClipStack(NULL), - fEncoder(NULL), - fRasterDpi(72.0f) { + : fPageSize(pageSize) + , fContentSize(contentSize) + , fLastContentEntry(NULL) + , fLastMarginContentEntry(NULL) + , fClipStack(NULL) + , fEncoder(NULL) + , fRasterDpi(72.0f) +{ + const SkImageInfo info = make_content_info(contentSize, &initialTransform); + // Just report that PDF does not supports perspective in the // initial transform. NOT_IMPLEMENTED(initialTransform.hasPerspective(), true); @@ -751,10 +750,10 @@ SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight)); fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1); fInitialTransform.preConcat(initialTransform); + fLegacyBitmap.setInfo(info); - SkIRect existingClip = SkIRect::MakeWH(this->width(), this->height()); + SkIRect existingClip = SkIRect::MakeWH(info.width(), info.height()); fExistingClipRegion.setRect(existingClip); - this->init(); } @@ -762,17 +761,19 @@ SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, SkPDFDevice::SkPDFDevice(const SkISize& layerSize, const SkClipStack& existingClipStack, const SkRegion& existingClipRegion) - : SkBitmapDevice(makeContentBitmap(layerSize, NULL)), - fPageSize(layerSize), - fContentSize(layerSize), - fExistingClipStack(existingClipStack), - fExistingClipRegion(existingClipRegion), - fLastContentEntry(NULL), - fLastMarginContentEntry(NULL), - fClipStack(NULL), - fEncoder(NULL), - fRasterDpi(72.0f) { + : fPageSize(layerSize) + , fContentSize(layerSize) + , fExistingClipStack(existingClipStack) + , fExistingClipRegion(existingClipRegion) + , fLastContentEntry(NULL) + , fLastMarginContentEntry(NULL) + , fClipStack(NULL) + , fEncoder(NULL) + , fRasterDpi(72.0f) +{ fInitialTransform.reset(); + fLegacyBitmap.setInfo(make_content_info(layerSize, NULL)); + this->init(); } @@ -961,13 +962,18 @@ void SkPDFDevice::drawRect(const SkDraw& d, const SkRect& rect, &content.entry()->fContent); } -void SkPDFDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, - const SkPaint& paint) { +void SkPDFDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const SkPaint& paint) { SkPath path; path.addRRect(rrect); this->drawPath(draw, path, paint, NULL, true); } +void SkPDFDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) { + SkPath path; + path.addOval(oval); + this->drawPath(draw, path, paint, NULL, true); +} + void SkPDFDevice::drawPath(const SkDraw& d, const SkPath& origPath, const SkPaint& paint, const SkMatrix* prePathMatrix, bool pathIsMutable) { @@ -1364,6 +1370,10 @@ void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device, fFontGlyphUsage->merge(pdfDevice->getFontGlyphUsage()); } +SkImageInfo SkPDFDevice::imageInfo() const { + return fLegacyBitmap.info(); +} + void SkPDFDevice::onAttachToCanvas(SkCanvas* canvas) { INHERITED::onAttachToCanvas(canvas); @@ -1377,6 +1387,10 @@ void SkPDFDevice::onDetachFromCanvas() { fClipStack = NULL; } +SkSurface* SkPDFDevice::newSurface(const SkImageInfo& info) { + return SkSurface::NewRaster(info); +} + ContentEntry* SkPDFDevice::getLastContentEntry() { if (fDrawingArea == kContent_DrawingArea) { return fLastContentEntry; @@ -2237,8 +2251,7 @@ void SkPDFDevice::internalDrawBitmap(const SkMatrix& origMatrix, } perspectiveBitmap.eraseColor(SK_ColorTRANSPARENT); - SkBitmapDevice device(perspectiveBitmap); - SkCanvas canvas(&device); + SkCanvas canvas(perspectiveBitmap); SkScalar deltaX = bounds.left(); SkScalar deltaY = bounds.top(); @@ -2305,6 +2318,3 @@ void SkPDFDevice::internalDrawBitmap(const SkMatrix& origMatrix, &content.entry()->fContent); } -bool SkPDFDevice::allowImageFilter(const SkImageFilter*) { - return false; -} diff --git a/src/utils/SkGatherPixelRefsAndRects.h b/src/utils/SkGatherPixelRefsAndRects.h index df3651e2e5..5d980aaf5f 100644 --- a/src/utils/SkGatherPixelRefsAndRects.h +++ b/src/utils/SkGatherPixelRefsAndRects.h @@ -39,12 +39,7 @@ public: return fEmptyBitmap.info(); } - virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE { return NULL; } - protected: - virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE { - return false; - } virtual void clear(SkColor color) SK_OVERRIDE { NothingToDo(); } @@ -319,8 +314,6 @@ private: (info.width(), info.height(), fPRCont)); } - virtual void flush() SK_OVERRIDE {} - static void NotSupported() { SkDEBUGFAIL("this method should never be called"); } |