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
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 0f3cc2b..86c5702 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -132,20 +132,6 @@
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 d34170c..3b82a33 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -127,16 +127,6 @@
///////////////////////////////////////////////////////////////////////////////
-/*
- * 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(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 @@
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 @@
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 ab4d71d..e571477 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 @@
////////////////////////////////////////////////////////////////////////////////
-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 @@
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 @@
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& 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 @@
&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 @@
fFontGlyphUsage->merge(pdfDevice->getFontGlyphUsage());
}
+SkImageInfo SkPDFDevice::imageInfo() const {
+ return fLegacyBitmap.info();
+}
+
void SkPDFDevice::onAttachToCanvas(SkCanvas* canvas) {
INHERITED::onAttachToCanvas(canvas);
@@ -1377,6 +1387,10 @@
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 @@
}
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 @@
&content.entry()->fContent);
}
-bool SkPDFDevice::allowImageFilter(const SkImageFilter*) {
- return false;
-}
diff --git a/src/utils/SkGatherPixelRefsAndRects.h b/src/utils/SkGatherPixelRefsAndRects.h
index df3651e..5d980aa 100644
--- a/src/utils/SkGatherPixelRefsAndRects.h
+++ b/src/utils/SkGatherPixelRefsAndRects.h
@@ -39,12 +39,7 @@
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 @@
(info.width(), info.height(), fPRCont));
}
- virtual void flush() SK_OVERRIDE {}
-
static void NotSupported() {
SkDEBUGFAIL("this method should never be called");
}