From: robertphillips@google.com Date: Thu, 29 Aug 2013 11:54:56 +0000 (+0000) Subject: Split SkDevice into SkBaseDevice and SkBitmapDevice X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~11049 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1f2f338e23789f3eef168dcbd8171a28820ba6c1;p=platform%2Fupstream%2FlibSkiaSharp.git Split SkDevice into SkBaseDevice and SkBitmapDevice https://codereview.chromium.org/22978012/ git-svn-id: http://skia.googlecode.com/svn/trunk@10995 2bbb7eff-a529-9590-31e7-b0007b416f81 --- diff --git a/bench/BlurImageFilterBench.cpp b/bench/BlurImageFilterBench.cpp index 1666f57..10320e8 100644 --- a/bench/BlurImageFilterBench.cpp +++ b/bench/BlurImageFilterBench.cpp @@ -6,9 +6,9 @@ */ #include "SkBenchmark.h" +#include "SkBitmapDevice.h" #include "SkBlurImageFilter.h" #include "SkCanvas.h" -#include "SkDevice.h" #include "SkPaint.h" #include "SkRandom.h" #include "SkShader.h" @@ -53,7 +53,7 @@ private: const int h = fIsSmall ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, w, h); fCheckerboard.allocPixels(); - SkDevice device(fCheckerboard); + SkBitmapDevice device(fCheckerboard); SkCanvas canvas(&device); canvas.clear(0x00000000); SkPaint darkPaint; diff --git a/bench/DeferredCanvasBench.cpp b/bench/DeferredCanvasBench.cpp index 9e7e7238..e14bb24 100644 --- a/bench/DeferredCanvasBench.cpp +++ b/bench/DeferredCanvasBench.cpp @@ -26,7 +26,7 @@ protected: } virtual void onDraw(SkCanvas* canvas) { - SkDevice *device = canvas->getDevice()->createCompatibleDevice( + SkBaseDevice *device = canvas->getDevice()->createCompatibleDevice( SkBitmap::kARGB_8888_Config, CANVAS_WIDTH, CANVAS_HEIGHT, false); SkAutoTUnref deferredCanvas(SkDeferredCanvas::Create(device)); diff --git a/bench/DisplacementBench.cpp b/bench/DisplacementBench.cpp index 5adec1f..e498a1b 100644 --- a/bench/DisplacementBench.cpp +++ b/bench/DisplacementBench.cpp @@ -5,9 +5,9 @@ * found in the LICENSE file. */ #include "SkBenchmark.h" +#include "SkBitmapDevice.h" #include "SkBitmapSource.h" #include "SkCanvas.h" -#include "SkDevice.h" #include "SkDisplacementMapEffect.h" #define FILTER_WIDTH_SMALL 32 @@ -35,7 +35,7 @@ protected: const int h = isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; fBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h); fBitmap.allocPixels(); - SkDevice device(fBitmap); + SkBitmapDevice device(fBitmap); SkCanvas canvas(&device); canvas.clear(0x00000000); SkPaint paint; @@ -51,7 +51,7 @@ protected: const int h = isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, w, h); fCheckerboard.allocPixels(); - SkDevice device(fCheckerboard); + SkBitmapDevice device(fCheckerboard); SkCanvas canvas(&device); canvas.clear(0x00000000); SkPaint darkPaint; diff --git a/bench/MagnifierBench.cpp b/bench/MagnifierBench.cpp index 969323a..2e937f3 100644 --- a/bench/MagnifierBench.cpp +++ b/bench/MagnifierBench.cpp @@ -5,8 +5,8 @@ * found in the LICENSE file. */ #include "SkBenchmark.h" +#include "SkBitmapDevice.h" #include "SkCanvas.h" -#include "SkDevice.h" #include "SkMagnifierImageFilter.h" #include "SkRandom.h" @@ -52,7 +52,7 @@ private: const int h = fIsSmall ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, w, h); fCheckerboard.allocPixels(); - SkDevice device(fCheckerboard); + SkBitmapDevice device(fCheckerboard); SkCanvas canvas(&device); canvas.clear(0x00000000); SkPaint darkPaint; diff --git a/bench/MergeBench.cpp b/bench/MergeBench.cpp index 3639c95..992507d 100644 --- a/bench/MergeBench.cpp +++ b/bench/MergeBench.cpp @@ -5,9 +5,9 @@ * found in the LICENSE file. */ #include "SkBenchmark.h" +#include "SkBitmapDevice.h" #include "SkBitmapSource.h" #include "SkCanvas.h" -#include "SkDevice.h" #include "SkMergeImageFilter.h" #define FILTER_WIDTH_SMALL SkIntToScalar(32) @@ -53,7 +53,7 @@ private: void make_bitmap() { fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); fBitmap.allocPixels(); - SkDevice device(fBitmap); + SkBitmapDevice device(fBitmap); SkCanvas canvas(&device); canvas.clear(0x00000000); SkPaint paint; @@ -67,7 +67,7 @@ private: void make_checkerboard() { fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); fCheckerboard.allocPixels(); - SkDevice device(fCheckerboard); + SkBitmapDevice device(fCheckerboard); SkCanvas canvas(&device); canvas.clear(0x00000000); SkPaint darkPaint; diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp index cec21df..99e9f6c 100644 --- a/bench/benchmain.cpp +++ b/bench/benchmain.cpp @@ -199,9 +199,9 @@ enum Backend { kPDF_Backend, }; -static SkDevice* make_device(SkBitmap::Config config, const SkIPoint& size, - Backend backend, int sampleCount, GrContext* context) { - SkDevice* device = NULL; +static SkBaseDevice* make_device(SkBitmap::Config config, const SkIPoint& size, + Backend backend, int sampleCount, GrContext* context) { + SkBaseDevice* device = NULL; SkBitmap bitmap; bitmap.setConfig(config, size.fX, size.fY); @@ -209,7 +209,7 @@ static SkDevice* make_device(SkBitmap::Config config, const SkIPoint& size, case kRaster_Backend: bitmap.allocPixels(); erase(bitmap); - device = SkNEW_ARGS(SkDevice, (bitmap)); + device = SkNEW_ARGS(SkBitmapDevice, (bitmap)); break; #if SK_SUPPORT_GPU case kGPU_Backend: { @@ -780,7 +780,7 @@ int tool_main(int argc, char** argv) { glContext = gContextFactory.getGLContext(gConfigs[configIndex].fContextType); } #endif - SkDevice* device = NULL; + SkBaseDevice* device = NULL; SkCanvas* canvas = NULL; SkPicture pictureRecordFrom; SkPicture pictureRecordTo; diff --git a/debugger/QT/SkRasterWidget.cpp b/debugger/QT/SkRasterWidget.cpp index 3817c0e..d78e5f8 100644 --- a/debugger/QT/SkRasterWidget.cpp +++ b/debugger/QT/SkRasterWidget.cpp @@ -12,7 +12,7 @@ SkRasterWidget::SkRasterWidget(SkDebugger *debugger) : QWidget() { fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 800, 800); fBitmap.allocPixels(); fBitmap.eraseColor(SK_ColorTRANSPARENT); - fDevice = new SkDevice(fBitmap); + fDevice = new SkBitmapDevice(fBitmap); fDebugger = debugger; fCanvas = new SkCanvas(fDevice); this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}"); @@ -29,7 +29,7 @@ void SkRasterWidget::resizeEvent(QResizeEvent* event) { fBitmap.eraseColor(SK_ColorTRANSPARENT); SkSafeUnref(fCanvas); SkSafeUnref(fDevice); - fDevice = new SkDevice(fBitmap); + fDevice = new SkBitmapDevice(fBitmap); fCanvas = new SkCanvas(fDevice); fDebugger->resize(event->size().width(), event->size().height()); this->update(); diff --git a/debugger/QT/SkRasterWidget.h b/debugger/QT/SkRasterWidget.h index 769aa51..9e4f01d 100644 --- a/debugger/QT/SkRasterWidget.h +++ b/debugger/QT/SkRasterWidget.h @@ -44,7 +44,7 @@ private: SkBitmap fBitmap; SkDebugger* fDebugger; SkCanvas* fCanvas; - SkDevice* fDevice; + SkBaseDevice* fDevice; }; #endif /* SKRASTERWIDGET_H_ */ diff --git a/experimental/PdfViewer/SkNulCanvas.h b/experimental/PdfViewer/SkNulCanvas.h index 98d9583..1789b6f 100644 --- a/experimental/PdfViewer/SkNulCanvas.h +++ b/experimental/PdfViewer/SkNulCanvas.h @@ -15,7 +15,7 @@ public: SK_DECLARE_INST_COUNT(SkNulCanvas); SkNulCanvas() {} - explicit SkNulCanvas(SkDevice* device) : SkCanvas(device) {} + explicit SkNulCanvas(SkBaseDevice* device) : SkCanvas(device) {} explicit SkNulCanvas(const SkBitmap& bitmap) : SkCanvas(bitmap) {} virtual ~SkNulCanvas() {} @@ -90,7 +90,7 @@ public: protected: virtual SkCanvas* canvasForDrawIter() {return NULL;} - virtual SkDevice* setDevice(SkDevice* device) {return NULL;} + virtual SkBaseDevice* setDevice(SkBaseDevice* device) {return NULL;} private: typedef SkCanvas INHERITED; diff --git a/experimental/PdfViewer/SkPdfRenderer.cpp b/experimental/PdfViewer/SkPdfRenderer.cpp index 7fa1c15..57b41c8 100644 --- a/experimental/PdfViewer/SkPdfRenderer.cpp +++ b/experimental/PdfViewer/SkPdfRenderer.cpp @@ -352,7 +352,7 @@ static bool readToken(SkPdfNativeTokenizer* fTokenizer, PdfToken* token) { memcpy(bitmap.getPixels(), gDumpBitmap->getPixels(), gDumpBitmap->getSize()); - SkAutoTUnref device(SkNEW_ARGS(SkDevice, (bitmap))); + SkAutoTUnref device(SkNEW_ARGS(SkBitmapDevice, (bitmap))); SkCanvas canvas(device); // draw context stuff here @@ -2909,7 +2909,7 @@ bool SkPDFNativeRenderToBitmap(SkStream* stream, setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(height)); - SkAutoTUnref device(SkNEW_ARGS(SkDevice, (*output))); + SkAutoTUnref device(SkNEW_ARGS(SkBitmapDevice, (*output))); SkCanvas canvas(device); return renderer.renderPage(page, &canvas, rect); diff --git a/experimental/PdfViewer/SkTrackDevice.h b/experimental/PdfViewer/SkTrackDevice.h index 545250b..2b8a8ea 100644 --- a/experimental/PdfViewer/SkTrackDevice.h +++ b/experimental/PdfViewer/SkTrackDevice.h @@ -11,24 +11,24 @@ #include "SkDevice.h" #include "SkTracker.h" -class SkTrackDevice : public SkDevice { +class SkTrackDevice : public SkBitmapDevice { public: SK_DECLARE_INST_COUNT(SkTrackDevice) - SkTrackDevice(const SkBitmap& bitmap) : SkDevice(bitmap) + SkTrackDevice(const SkBitmap& bitmap) : SkBitmapDevice(bitmap) , fTracker(NULL) {} SkTrackDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties) - : SkDevice(bitmap, deviceProperties) + : SkBitmapDevice(bitmap, deviceProperties) , fTracker(NULL) {} SkTrackDevice(SkBitmap::Config config, int width, int height, bool isOpaque = false) - : SkDevice(config, width, height, isOpaque) + : SkBitmapDevice(config, width, height, isOpaque) , fTracker(NULL) {} SkTrackDevice(SkBitmap::Config config, int width, int height, bool isOpaque, const SkDeviceProperties& deviceProperties) - : SkDevice(config, width, height, isOpaque, deviceProperties) + : SkBitmapDevice(config, width, height, isOpaque, deviceProperties) , fTracker(NULL) {} virtual ~SkTrackDevice() {} @@ -154,7 +154,7 @@ protected: after(); } - virtual void drawDevice(const SkDraw& dummy1, SkDevice* dummy2, int x, int y, + virtual void drawDevice(const SkDraw& dummy1, SkBaseDevice* dummy2, int x, int y, const SkPaint& dummy3) { before(); INHERITED::drawDevice(dummy1, dummy2, x, y, dummy3); @@ -178,7 +178,7 @@ private: private: SkTracker* fTracker; - typedef SkDevice INHERITED; + typedef SkBitmapDevice INHERITED; }; #endif // SkTrackDevice_DEFINED diff --git a/experimental/PdfViewer/pdf_viewer_main.cpp b/experimental/PdfViewer/pdf_viewer_main.cpp index ca2a9da..5fe99ad 100644 --- a/experimental/PdfViewer/pdf_viewer_main.cpp +++ b/experimental/PdfViewer/pdf_viewer_main.cpp @@ -186,7 +186,7 @@ static bool render_page(const SkString& outputDir, // Exercise all pdf codepaths as in normal rendering, but no actual bits are changed. if (!FLAGS_config.isEmpty() && strcmp(FLAGS_config[0], "nul") == 0) { SkBitmap bitmap; - SkAutoTUnref device(SkNEW_ARGS(SkDevice, (bitmap))); + SkAutoTUnref device(SkNEW_ARGS(SkBitmapDevice, (bitmap))); SkNulCanvas canvas(device); renderer.renderPage(page < 0 ? 0 : page, &canvas, rect); } else { @@ -204,9 +204,9 @@ static bool render_page(const SkString& outputDir, #else setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDouble(height)); #endif - SkAutoTUnref device; + SkAutoTUnref device; if (strcmp(FLAGS_config[0], "8888") == 0) { - device.reset(SkNEW_ARGS(SkDevice, (bitmap))); + device.reset(SkNEW_ARGS(SkBitmapDevice, (bitmap))); } #if SK_SUPPORT_GPU else if (strcmp(FLAGS_config[0], "gpu") == 0) { diff --git a/experimental/SkiaExamples/SkExample.cpp b/experimental/SkiaExamples/SkExample.cpp index 387276a..d3601e1 100644 --- a/experimental/SkiaExamples/SkExample.cpp +++ b/experimental/SkiaExamples/SkExample.cpp @@ -115,7 +115,7 @@ void SkExampleWindow::setupRenderTarget() { SkCanvas* SkExampleWindow::createCanvas() { if (fType == kGPU_DeviceType) { if (NULL != fContext && NULL != fRenderTarget) { - SkAutoTUnref device(new SkGpuDevice(fContext, fRenderTarget)); + SkAutoTUnref device(new SkGpuDevice(fContext, fRenderTarget)); return new SkCanvas(device); } tearDownBackend(); diff --git a/experimental/iOSSampleApp/SkSampleUIView.mm b/experimental/iOSSampleApp/SkSampleUIView.mm index 9fc95bd..421dfcf 100644 --- a/experimental/iOSSampleApp/SkSampleUIView.mm +++ b/experimental/iOSSampleApp/SkSampleUIView.mm @@ -136,8 +136,8 @@ public: case SampleWindow::kGPU_DeviceType: case SampleWindow::kNullGPU_DeviceType: if (fCurContext) { - SkAutoTUnref device(new SkGpuDevice(fCurContext, - fCurRenderTarget)); + SkAutoTUnref device(new SkGpuDevice(fCurContext, + fCurRenderTarget)); return new SkCanvas(device); } else { return NULL; diff --git a/gm/beziereffects.cpp b/gm/beziereffects.cpp index 19ba4e2..2a63d73 100644 --- a/gm/beziereffects.cpp +++ b/gm/beziereffects.cpp @@ -58,7 +58,7 @@ protected: virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { - SkDevice* device = canvas->getTopDevice(); + SkBaseDevice* device = canvas->getTopDevice(); GrRenderTarget* rt = device->accessRenderTarget(); if (NULL == rt) { return; @@ -210,7 +210,7 @@ protected: virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { - SkDevice* device = canvas->getTopDevice(); + SkBaseDevice* device = canvas->getTopDevice(); GrRenderTarget* rt = device->accessRenderTarget(); if (NULL == rt) { return; @@ -395,7 +395,7 @@ protected: virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { - SkDevice* device = canvas->getTopDevice(); + SkBaseDevice* device = canvas->getTopDevice(); GrRenderTarget* rt = device->accessRenderTarget(); if (NULL == rt) { return; diff --git a/gm/bitmapcopy.cpp b/gm/bitmapcopy.cpp index 1c56bde..5e88cfd 100644 --- a/gm/bitmapcopy.cpp +++ b/gm/bitmapcopy.cpp @@ -66,7 +66,7 @@ protected: SkScalar horizMargin(SkIntToScalar(10)); SkScalar vertMargin(SkIntToScalar(10)); - SkDevice devTmp(SkBitmap::kARGB_8888_Config, 40, 40); + SkBitmapDevice devTmp(SkBitmap::kARGB_8888_Config, 40, 40, false); SkCanvas canvasTmp(&devTmp); draw_checks(&canvasTmp, 40, 40); diff --git a/gm/deviceproperties.cpp b/gm/deviceproperties.cpp index 5739b57..8bca4b7 100644 --- a/gm/deviceproperties.cpp +++ b/gm/deviceproperties.cpp @@ -44,7 +44,7 @@ protected: SkDeviceProperties::Geometry::Make(SkDeviceProperties::Geometry::kVertical_Orientation, SkDeviceProperties::Geometry::kBGR_Layout), SK_Scalar1); - SkDevice device(bitmap, properties); + SkBitmapDevice device(bitmap, properties); SkCanvas canvas(&device); canvas.drawColor(SK_ColorWHITE); diff --git a/gm/displacement.cpp b/gm/displacement.cpp index 888051d..5031720 100644 --- a/gm/displacement.cpp +++ b/gm/displacement.cpp @@ -25,7 +25,7 @@ protected: void make_bitmap() { fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); fBitmap.allocPixels(); - SkDevice device(fBitmap); + SkBitmapDevice device(fBitmap); SkCanvas canvas(&device); canvas.clear(0x00000000); SkPaint paint; @@ -39,7 +39,7 @@ protected: void make_checkerboard() { fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); fCheckerboard.allocPixels(); - SkDevice device(fCheckerboard); + SkBitmapDevice device(fCheckerboard); SkCanvas canvas(&device); canvas.clear(0x00000000); SkPaint darkPaint; diff --git a/gm/extractbitmap.cpp b/gm/extractbitmap.cpp index 59f8a93..5206741 100644 --- a/gm/extractbitmap.cpp +++ b/gm/extractbitmap.cpp @@ -74,7 +74,7 @@ protected: } // Now do the same but with a device bitmap as source image - SkAutoTUnref secondDevice(canvas->createCompatibleDevice( + SkAutoTUnref secondDevice(canvas->createCompatibleDevice( SkBitmap::kARGB_8888_Config, bitmap.width(), bitmap.height(), true)); SkCanvas secondCanvas(secondDevice.get()); diff --git a/gm/gm.h b/gm/gm.h index b19bce3..022536d 100644 --- a/gm/gm.h +++ b/gm/gm.h @@ -9,8 +9,8 @@ #define skiagm_DEFINED #include "SkBitmap.h" +#include "SkBitmapDevice.h" #include "SkCanvas.h" -#include "SkDevice.h" #include "SkPaint.h" #include "SkSize.h" #include "SkString.h" diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp index ea749a5..6fd96f9 100644 --- a/gm/gmmain.cpp +++ b/gm/gmmain.cpp @@ -536,7 +536,7 @@ public: SkAutoTUnref canvas; if (gRec.fBackend == kRaster_Backend) { - SkAutoTUnref device(SkNEW_ARGS(SkDevice, (*bitmap))); + SkAutoTUnref device(SkNEW_ARGS(SkBitmapDevice, (*bitmap))); if (deferred) { canvas.reset(SkDeferredCanvas::Create(device)); } else { @@ -547,7 +547,7 @@ public: } #if SK_SUPPORT_GPU else { // GPU - SkAutoTUnref device(SkGpuDevice::Create(gpuTarget)); + SkAutoTUnref device(SkGpuDevice::Create(gpuTarget)); if (deferred) { canvas.reset(SkDeferredCanvas::Create(device)); } else { diff --git a/gm/imagefiltersgraph.cpp b/gm/imagefiltersgraph.cpp index 38df075..363a414 100644 --- a/gm/imagefiltersgraph.cpp +++ b/gm/imagefiltersgraph.cpp @@ -32,7 +32,7 @@ protected: void make_bitmap() { fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); fBitmap.allocPixels(); - SkDevice device(fBitmap); + SkBitmapDevice device(fBitmap); SkCanvas canvas(&device); canvas.clear(0x00000000); SkPaint paint; diff --git a/gm/lighting.cpp b/gm/lighting.cpp index 330e0ee..891d63a 100644 --- a/gm/lighting.cpp +++ b/gm/lighting.cpp @@ -27,7 +27,7 @@ protected: void make_bitmap() { fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); fBitmap.allocPixels(); - SkDevice device(fBitmap); + SkBitmapDevice device(fBitmap); SkCanvas canvas(&device); canvas.clear(0x00000000); SkPaint paint; diff --git a/gm/matrixconvolution.cpp b/gm/matrixconvolution.cpp index 59bd380..853b57b 100644 --- a/gm/matrixconvolution.cpp +++ b/gm/matrixconvolution.cpp @@ -26,7 +26,7 @@ protected: void make_bitmap() { fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); fBitmap.allocPixels(); - SkDevice device(fBitmap); + SkBitmapDevice device(fBitmap); SkCanvas canvas(&device); canvas.clear(0x00000000); SkPaint paint; diff --git a/gm/morphology.cpp b/gm/morphology.cpp index 83de758..2d29fcd 100644 --- a/gm/morphology.cpp +++ b/gm/morphology.cpp @@ -28,7 +28,7 @@ protected: void make_bitmap() { fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 135, 135); fBitmap.allocPixels(); - SkDevice device(fBitmap); + SkBitmapDevice device(fBitmap); SkCanvas canvas(&device); canvas.clear(0x0); SkPaint paint; diff --git a/gm/ninepatchstretch.cpp b/gm/ninepatchstretch.cpp index c4c5291..551f020 100644 --- a/gm/ninepatchstretch.cpp +++ b/gm/ninepatchstretch.cpp @@ -14,7 +14,7 @@ class GrContext; #endif static void make_bitmap(SkBitmap* bitmap, GrContext* ctx, SkIRect* center) { - SkDevice* dev; + SkBaseDevice* dev; const int kFixed = 28; const int kStretchy = 8; @@ -29,7 +29,7 @@ static void make_bitmap(SkBitmap* bitmap, GrContext* ctx, SkIRect* center) { { bitmap->setConfig(SkBitmap::kARGB_8888_Config, kSize, kSize); bitmap->allocPixels(); - dev = new SkDevice(*bitmap); + dev = new SkBitmapDevice(*bitmap); } SkCanvas canvas(dev); diff --git a/gm/srcmode.cpp b/gm/srcmode.cpp index 66729e2..e8a97e2 100644 --- a/gm/srcmode.cpp +++ b/gm/srcmode.cpp @@ -124,7 +124,7 @@ protected: SkImage::kPremul_AlphaType }; #if SK_SUPPORT_GPU - SkDevice* dev = canvas->getDevice(); + SkBaseDevice* dev = canvas->getDevice(); if (!skipGPU && dev->accessRenderTarget()) { SkGpuDevice* gd = (SkGpuDevice*)dev; GrContext* ctx = gd->context(); diff --git a/gm/texdata.cpp b/gm/texdata.cpp index 612cc64..0e2d7fd 100644 --- a/gm/texdata.cpp +++ b/gm/texdata.cpp @@ -38,7 +38,7 @@ protected: } virtual void onDraw(SkCanvas* canvas) { - SkDevice* device = canvas->getTopDevice(); + SkBaseDevice* device = canvas->getTopDevice(); GrRenderTarget* target = device->accessRenderTarget(); GrContext* ctx = GetGr(); if (ctx && target) { diff --git a/gm/xfermodeimagefilter.cpp b/gm/xfermodeimagefilter.cpp index 86225af..94d60e4 100644 --- a/gm/xfermodeimagefilter.cpp +++ b/gm/xfermodeimagefilter.cpp @@ -31,7 +31,7 @@ protected: void make_bitmap() { fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); fBitmap.allocPixels(); - SkDevice device(fBitmap); + SkBitmapDevice device(fBitmap); SkCanvas canvas(&device); canvas.clear(0x00000000); SkPaint paint; @@ -45,7 +45,7 @@ protected: void make_checkerboard() { fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); fCheckerboard.allocPixels(); - SkDevice device(fCheckerboard); + SkBitmapDevice device(fCheckerboard); SkCanvas canvas(&device); canvas.clear(0x00000000); SkPaint darkPaint; diff --git a/gm/xfermodes3.cpp b/gm/xfermodes3.cpp index f1eff1f..baac3cd 100644 --- a/gm/xfermodes3.cpp +++ b/gm/xfermodes3.cpp @@ -132,7 +132,7 @@ private: desc.fConfig = rt->config(); desc.fFlags = kRenderTarget_GrTextureFlagBit; SkAutoTUnref surface(context->createUncachedTexture(desc, NULL, 0)); - SkAutoTUnref device(SkGpuDevice::Create(surface.get())); + SkAutoTUnref device(SkGpuDevice::Create(surface.get())); if (NULL != device.get()) { tempCanvas = SkNEW_ARGS(SkCanvas, (device.get())); } diff --git a/include/core/SkBitmapDevice.h b/include/core/SkBitmapDevice.h index b97e87b..a288f8a 100644 --- a/include/core/SkBitmapDevice.h +++ b/include/core/SkBitmapDevice.h @@ -11,6 +11,285 @@ #include "SkDevice.h" -typedef SkDevice SkBitmapDevice; +/////////////////////////////////////////////////////////////////////////////// +class SK_API SkBitmapDevice : public SkBaseDevice { +public: + SK_DECLARE_INST_COUNT(SkBitmapDevice) + + /** + * Construct a new device with the specified bitmap as its backend. It is + * valid for the bitmap to have no pixels associated with it. In that case, + * any drawing to this device will have no effect. + */ + SkBitmapDevice(const SkBitmap& bitmap); + + /** + * Construct a new device with the specified bitmap as its backend. It is + * valid for the bitmap to have no pixels associated with it. In that case, + * any drawing to this device will have no effect. + */ + SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties); + + /** + * Create a new raster device and have the pixels be automatically + * allocated. The rowBytes of the device will be computed automatically + * based on the config and the width. + * + * @param config The desired config for the pixels. If the request cannot + * be met, the closest matching support config will be used. + * @param width width (in pixels) of the device + * @param height height (in pixels) of the device + * @param isOpaque Set to true if it is known that all of the pixels will + * be drawn to opaquely. Used as an accelerator when drawing + * these pixels to another device. + */ + SkBitmapDevice(SkBitmap::Config config, int width, int height, bool isOpaque = false); + + /** + * Create a new raster device and have the pixels be automatically + * allocated. The rowBytes of the device will be computed automatically + * based on the config and the width. + * + * @param config The desired config for the pixels. If the request cannot + * be met, the closest matching support config will be used. + * @param width width (in pixels) of the device + * @param height height (in pixels) of the device + * @param isOpaque Set to true if it is known that all of the pixels will + * be drawn to opaquely. Used as an accelerator when drawing + * these pixels to another device. + * @param deviceProperties Properties which affect compositing. + */ + SkBitmapDevice(SkBitmap::Config config, int width, int height, bool isOpaque, + const SkDeviceProperties& deviceProperties); + + virtual ~SkBitmapDevice(); + + virtual uint32_t getDeviceCapabilities() SK_OVERRIDE { return 0; } + + /** Return the width of the device (in pixels). + */ + virtual int width() const SK_OVERRIDE { return fBitmap.width(); } + /** Return the height of the device (in pixels). + */ + 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. + */ + virtual bool isOpaque() const SK_OVERRIDE { return fBitmap.isOpaque(); } + + /** Return the bitmap config of the device's pixels + */ + virtual SkBitmap::Config config() const SK_OVERRIDE { return fBitmap.getConfig(); } + + /** + * DEPRECATED: This will be made protected once WebKit stops using it. + * Instead use Canvas' writePixels method. + * + * Similar to draw sprite, this method will copy the pixels in bitmap onto + * the device, with the top/left corner specified by (x, y). The pixel + * values in the device are completely replaced: there is no blending. + * + * Currently if bitmap is backed by a texture this is a no-op. This may be + * relaxed in the future. + * + * If the bitmap has config kARGB_8888_Config then the config8888 param + * will determines how the pixel valuess are intepreted. If the bitmap is + * not kARGB_8888_Config then this parameter is ignored. + */ + virtual void writePixels(const SkBitmap& bitmap, int x, int y, + SkCanvas::Config8888 config8888) 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). + * Ignores the clip. + */ + virtual void clear(SkColor color) SK_OVERRIDE; + + /** These are called inside the per-device-layer loop for each draw call. + When these are called, we have already applied any saveLayer operations, + and are handling any looping from the paint, and any effects from the + DrawFilter. + */ + 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; + virtual void drawRect(const SkDraw&, const SkRect& r, + 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; + + /** + * If pathIsMutable, then the implementation is allowed to cast path to a + * non-const pointer and modify it in place (as an optimization). Canvas + * may do this to implement helpers such as drawOval, by placing a temp + * path on the stack to hold the representation of the oval. + * + * If prePathMatrix is not null, it should logically be applied before any + * stroking or other effects. If there are no effects on the paint that + * affect the geometry/rasterization, then the pre matrix can just be + * pre-concated with the current matrix. + */ + virtual void drawPath(const SkDraw&, const SkPath& path, + const SkPaint& paint, + const SkMatrix* prePathMatrix = NULL, + bool pathIsMutable = false) SK_OVERRIDE; + virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, + const SkMatrix& matrix, const SkPaint& paint) SK_OVERRIDE; + virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, + int x, int y, const SkPaint& paint) SK_OVERRIDE; + + /** + * The default impl. will create a bitmap-shader from the bitmap, + * and call drawRect with it. + */ + virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, + const SkRect* srcOrNull, const SkRect& dst, + const SkPaint& paint, + SkCanvas::DrawBitmapRectFlags flags) SK_OVERRIDE; + + /** + * Does not handle text decoration. + * Decorations (underline and stike-thru) will be handled by SkCanvas. + */ + virtual void drawText(const SkDraw&, const void* text, size_t len, + SkScalar x, SkScalar y, const SkPaint& paint) SK_OVERRIDE; + virtual void drawPosText(const SkDraw&, const void* text, size_t len, + const SkScalar pos[], SkScalar constY, + int scalarsPerPos, const SkPaint& paint) SK_OVERRIDE; + virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, + const SkPath& path, const SkMatrix* matrix, + const SkPaint& paint) SK_OVERRIDE; +#ifdef SK_BUILD_FOR_ANDROID + virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len, + const SkPoint pos[], const SkPaint& paint, + const SkPath& path, const SkMatrix* matrix) SK_OVERRIDE; +#endif + virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount, + const SkPoint verts[], const SkPoint texs[], + const SkColor colors[], SkXfermode* xmode, + const uint16_t indices[], int indexCount, + const SkPaint& paint) SK_OVERRIDE; + /** The SkBaseDevice passed will be an SkBaseDevice which was returned by a call to + onCreateCompatibleDevice on this device with kSaveLayer_Usage. + */ + virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, + const SkPaint&) SK_OVERRIDE; + + /////////////////////////////////////////////////////////////////////////// + + /** Update as needed the pixel value in the bitmap, so that the caller can + access the pixels directly. Note: only the pixels field should be + altered. The config/width/height/rowbytes must remain unchanged. + @return the device contents as a bitmap + */ + virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE; + + SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } + // just for subclasses, to assign a custom pixelref + SkPixelRef* setPixelRef(SkPixelRef* pr, size_t offset) { + fBitmap.setPixelRef(pr, offset); + return pr; + } + + /** + * Implements readPixels API. The caller will ensure that: + * 1. bitmap has pixel config kARGB_8888_Config. + * 2. bitmap has pixels. + * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is + * contained in the device bounds. + */ + virtual bool onReadPixels(const SkBitmap& bitmap, + int x, int y, + SkCanvas::Config8888 config8888) SK_OVERRIDE; + + /** 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() 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(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(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(SkImageFilter*, const SkBitmap&, const SkMatrix&, + SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; + +private: + friend class SkCanvas; + friend struct DeviceCM; //for setMatrixClip + friend class SkDraw; + friend class SkDrawIter; + friend class SkDeviceFilteredPaint; + friend class SkDeviceImageFilterProxy; + + friend class SkSurface_Raster; + + // 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. + virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRIDE; + + /** + * Subclasses should override this to implement createCompatibleDevice. + */ + virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config, + int width, int height, + bool isOpaque, + Usage usage) SK_OVERRIDE; + + /** Causes any deferred drawing to the device to be completed. + */ + virtual void flush() SK_OVERRIDE {} + + SkBitmap fBitmap; + + typedef SkBaseDevice INHERITED; +}; #endif // SkBitmapDevice_DEFINED diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 827ebe8..cfc252f 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -22,7 +22,7 @@ #include "SkXfermode.h" class SkBounder; -class SkDevice; +class SkBaseDevice; class SkDraw; class SkDrawFilter; class SkMetaData; @@ -55,7 +55,7 @@ public: @param device Specifies a device for the canvas to draw into. */ - explicit SkCanvas(SkDevice* device); + explicit SkCanvas(SkBaseDevice* device); /** Deprecated - Construct a canvas with the specified bitmap to draw into. @param bitmap Specifies a bitmap for the canvas to draw into. Its @@ -84,7 +84,7 @@ public: the bitmap of the pixels that the canvas draws into. The reference count of the returned device is not changed by this call. */ - SkDevice* getDevice() const; + SkBaseDevice* getDevice() const; /** * saveLayer() can create another device (which is later drawn onto @@ -99,15 +99,15 @@ public: * is drawn to, but is optional here, as there is a small perf hit * sometimes. */ - SkDevice* getTopDevice(bool updateMatrixClip = false) const; + SkBaseDevice* getTopDevice(bool updateMatrixClip = false) const; /** * Shortcut for getDevice()->createCompatibleDevice(...). * If getDevice() == NULL, this method does nothing, and returns NULL. */ - SkDevice* createCompatibleDevice(SkBitmap::Config config, - int width, int height, - bool isOpaque); + SkBaseDevice* createCompatibleDevice(SkBitmap::Config config, + int width, int height, + bool isOpaque); /////////////////////////////////////////////////////////////////////////// @@ -994,7 +994,7 @@ public: // These reflect the current device in the iterator - SkDevice* device() const; + SkBaseDevice* device() const; const SkMatrix& matrix() const; const SkRegion& clip() const; const SkPaint& paint() const; @@ -1043,7 +1043,7 @@ protected: reference count is incremented. If the canvas was already holding a device, its reference count is decremented. The new device is returned. */ - virtual SkDevice* setDevice(SkDevice* device); + virtual SkBaseDevice* setDevice(SkBaseDevice* device); private: class MCRec; @@ -1074,10 +1074,10 @@ private: friend class SkDrawIter; // needs setupDrawForLayerDevice() friend class AutoDrawLooper; - SkDevice* createLayerDevice(SkBitmap::Config, int width, int height, - bool isOpaque); + SkBaseDevice* createLayerDevice(SkBitmap::Config, int width, int height, + bool isOpaque); - SkDevice* init(SkDevice*); + SkBaseDevice* init(SkBaseDevice*); // internal methods are not virtual, so they can safely be called by other // canvas apis, without confusing subclasses (like SkPictureRecording) @@ -1090,7 +1090,7 @@ private: void internalDrawPaint(const SkPaint& paint); int internalSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags, bool justForImageFilter); - void internalDrawDevice(SkDevice*, int x, int y, const SkPaint*); + void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*); // shared by save() and saveLayer() int internalSave(SaveFlags flags); diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index 990e833..1f10424 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -25,57 +25,21 @@ class SkRegion; class GrRenderTarget; -class SK_API SkDevice : public SkRefCnt { +class SK_API SkBaseDevice : public SkRefCnt { public: - SK_DECLARE_INST_COUNT(SkDevice) + SK_DECLARE_INST_COUNT(SkBaseDevice) /** - * Construct a new device with the specified bitmap as its backend. It is - * valid for the bitmap to have no pixels associated with it. In that case, - * any drawing to this device will have no effect. + * Construct a new device. */ - SkDevice(const SkBitmap& bitmap); + SkBaseDevice(); /** - * Construct a new device with the specified bitmap as its backend. It is - * valid for the bitmap to have no pixels associated with it. In that case, - * any drawing to this device will have no effect. + * Construct a new device. */ - SkDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties); + SkBaseDevice(const SkDeviceProperties& deviceProperties); - /** - * Create a new raster device and have the pixels be automatically - * allocated. The rowBytes of the device will be computed automatically - * based on the config and the width. - * - * @param config The desired config for the pixels. If the request cannot - * be met, the closest matching support config will be used. - * @param width width (in pixels) of the device - * @param height height (in pixels) of the device - * @param isOpaque Set to true if it is known that all of the pixels will - * be drawn to opaquely. Used as an accelerator when drawing - * these pixels to another device. - */ - SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque = false); - - /** - * Create a new raster device and have the pixels be automatically - * allocated. The rowBytes of the device will be computed automatically - * based on the config and the width. - * - * @param config The desired config for the pixels. If the request cannot - * be met, the closest matching support config will be used. - * @param width width (in pixels) of the device - * @param height height (in pixels) of the device - * @param isOpaque Set to true if it is known that all of the pixels will - * be drawn to opaquely. Used as an accelerator when drawing - * these pixels to another device. - * @param deviceProperties Properties which affect compositing. - */ - SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque, - const SkDeviceProperties& deviceProperties); - - virtual ~SkDevice(); + virtual ~SkBaseDevice(); /** * Creates a device that is of the same type as this device (e.g. SW-raster, @@ -88,9 +52,9 @@ public: * draw into this device such that all of the pixels will * be opaque. */ - SkDevice* createCompatibleDevice(SkBitmap::Config config, - int width, int height, - bool isOpaque); + SkBaseDevice* createCompatibleDevice(SkBitmap::Config config, + int width, int height, + bool isOpaque); SkMetaData& getMetaData(); @@ -99,14 +63,14 @@ public: kVector_Capability = 0x2, //!< mask indicating a vector representation kAll_Capabilities = 0x3 }; - virtual uint32_t getDeviceCapabilities() { return 0; } + virtual uint32_t getDeviceCapabilities() = 0; /** Return the width of the device (in pixels). */ - virtual int width() const { return fBitmap.width(); } + virtual int width() const = 0; /** Return the height of the device (in pixels). */ - virtual int height() const { return fBitmap.height(); } + virtual int height() const = 0; /** Return the image properties of the device. */ virtual const SkDeviceProperties& getDeviceProperties() const { @@ -119,16 +83,16 @@ 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. */ - void getGlobalBounds(SkIRect* bounds) const; + virtual void getGlobalBounds(SkIRect* bounds) const = 0; /** Returns true if the device's bitmap's config treats every pixels as implicitly opaque. */ - bool isOpaque() const { return fBitmap.isOpaque(); } - - /** Return the bitmap config of the device's pixels - */ - SkBitmap::Config config() const { return fBitmap.getConfig(); } + virtual bool isOpaque() const = 0; + + /** DEPRECATED - Return the bitmap config of the device's pixels + */ + virtual SkBitmap::Config config() const = 0; /** Return the bitmap associated with this device. Call this each time you need to access the bitmap, as it notifies the subclass to perform any flushing @@ -154,12 +118,12 @@ public: * not kARGB_8888_Config then this parameter is ignored. */ virtual void writePixels(const SkBitmap& bitmap, int x, int y, - SkCanvas::Config8888 config8888 = SkCanvas::kNative_Premul_Config8888); + SkCanvas::Config8888 config8888 = SkCanvas::kNative_Premul_Config8888) = 0; /** * Return the device's associated gpu render target, or NULL. */ - virtual GrRenderTarget* accessRenderTarget() { return NULL; } + virtual GrRenderTarget* accessRenderTarget() = 0; /** @@ -171,7 +135,7 @@ public: /** * onAttachToCanvas is invoked whenever a device is installed in a canvas * (i.e., setDevice, saveLayer (for the new device created by the save), - * and SkCanvas' SkDevice & SkBitmap -taking ctors). It allows the + * and SkCanvas' SkBaseDevice & SkBitmap -taking ctors). It allows the * devices to prepare for drawing (e.g., locking their pixels, etc.) */ virtual void onAttachToCanvas(SkCanvas*) { @@ -213,9 +177,9 @@ protected: * 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. + * The baseclass SkBaseDevice filters based on its depth and blitters. */ - virtual bool filterTextFlags(const SkPaint& paint, TextFlags*); + virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) = 0; /** * @@ -234,12 +198,12 @@ protected: * passed in). */ virtual void setMatrixClip(const SkMatrix&, const SkRegion&, - const SkClipStack&); + const SkClipStack&) {}; /** Clears the entire device to the specified color (including alpha). * Ignores the clip. */ - virtual void clear(SkColor color); + virtual void clear(SkColor color) = 0; /** * Deprecated name for clear. @@ -251,15 +215,15 @@ protected: and are handling any looping from the paint, and any effects from the DrawFilter. */ - virtual void drawPaint(const SkDraw&, const SkPaint& paint); + virtual void drawPaint(const SkDraw&, const SkPaint& paint) = 0; virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count, - const SkPoint[], const SkPaint& paint); + const SkPoint[], const SkPaint& paint) = 0; virtual void drawRect(const SkDraw&, const SkRect& r, - const SkPaint& paint); + const SkPaint& paint) = 0; virtual void drawOval(const SkDraw&, const SkRect& oval, - const SkPaint& paint); + const SkPaint& paint) = 0; virtual void drawRRect(const SkDraw&, const SkRRect& rr, - const SkPaint& paint); + const SkPaint& paint) = 0; /** * If pathIsMutable, then the implementation is allowed to cast path to a @@ -275,11 +239,11 @@ protected: virtual void drawPath(const SkDraw&, const SkPath& path, const SkPaint& paint, const SkMatrix* prePathMatrix = NULL, - bool pathIsMutable = false); + bool pathIsMutable = false) = 0; virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, - const SkMatrix& matrix, const SkPaint& paint); + const SkMatrix& matrix, const SkPaint& paint) = 0; virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, - int x, int y, const SkPaint& paint); + int x, int y, const SkPaint& paint) = 0; /** * The default impl. will create a bitmap-shader from the bitmap, @@ -288,35 +252,35 @@ protected: virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, const SkRect* srcOrNull, const SkRect& dst, const SkPaint& paint, - SkCanvas::DrawBitmapRectFlags flags); + SkCanvas::DrawBitmapRectFlags flags) = 0; /** * Does not handle text decoration. * Decorations (underline and stike-thru) will be handled by SkCanvas. */ virtual void drawText(const SkDraw&, const void* text, size_t len, - SkScalar x, SkScalar y, const SkPaint& paint); + SkScalar x, SkScalar y, const SkPaint& paint) = 0; virtual void drawPosText(const SkDraw&, const void* text, size_t len, const SkScalar pos[], SkScalar constY, - int scalarsPerPos, const SkPaint& paint); + int scalarsPerPos, const SkPaint& paint) = 0; virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, const SkPath& path, const SkMatrix* matrix, - const SkPaint& paint); + const SkPaint& paint) = 0; #ifdef SK_BUILD_FOR_ANDROID virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len, const SkPoint pos[], const SkPaint& paint, - const SkPath& path, const SkMatrix* matrix); + const SkPath& path, const SkMatrix* matrix) = 0; #endif virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount, const SkPoint verts[], const SkPoint texs[], const SkColor colors[], SkXfermode* xmode, const uint16_t indices[], int indexCount, - const SkPaint& paint); + const SkPaint& paint) = 0; /** The SkDevice passed will be an SkDevice which was returned by a call to onCreateCompatibleDevice on this device with kSaveLayer_Usage. */ - virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, - const SkPaint&); + virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, + const SkPaint&) = 0; /** * On success (returns true), copy the device pixels into the bitmap. @@ -352,20 +316,10 @@ protected: /////////////////////////////////////////////////////////////////////////// /** Update as needed the pixel value in the bitmap, so that the caller can - access the pixels directly. Note: only the pixels field should be - altered. The config/width/height/rowbytes must remain unchanged. - @param bitmap The device's bitmap - @return Echo the bitmap parameter, or an alternate (shadow) bitmap - maintained by the subclass. + access the pixels directly. + @return The device contents as a bitmap */ - virtual const SkBitmap& onAccessBitmap(SkBitmap*); - - SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } - // just for subclasses, to assign a custom pixelref - SkPixelRef* setPixelRef(SkPixelRef* pr, size_t offset) { - fBitmap.setPixelRef(pr, offset); - return pr; - } + virtual const SkBitmap& onAccessBitmap() = 0; /** * Implements readPixels API. The caller will ensure that: @@ -376,13 +330,13 @@ protected: */ virtual bool onReadPixels(const SkBitmap& bitmap, int x, int y, - SkCanvas::Config8888 config8888); + SkCanvas::Config8888 config8888) = 0; /** Called when this device is installed into a Canvas. Balanaced by a call to unlockPixels() when the device is removed from a Canvas. */ - virtual void lockPixels(); - virtual void unlockPixels(); + virtual void lockPixels() = 0; + virtual void unlockPixels() = 0; /** * Returns true if the device allows processing of this imagefilter. If @@ -390,7 +344,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(SkImageFilter*); + virtual bool allowImageFilter(SkImageFilter*) = 0; /** * Override and return true for filters that the device can handle @@ -399,7 +353,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(SkImageFilter*); + virtual bool canHandleImageFilter(SkImageFilter*) = 0; /** * Related (but not required) to canHandleImageFilter, this method returns @@ -409,7 +363,7 @@ protected: * it just returns false and leaves result and offset unchanged. */ virtual bool filterImage(SkImageFilter*, const SkBitmap&, const SkMatrix&, - SkBitmap* result, SkIPoint* offset); + SkBitmap* result, SkIPoint* offset) = 0; // This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if // either is identical to kNative_Premul_Config8888. Otherwise, -1. @@ -424,31 +378,31 @@ private: friend class SkDeviceImageFilterProxy; friend class SkSurface_Raster; + // 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. - void replaceBitmapBackendForRasterSurface(const SkBitmap&); + virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) = 0; // just called by SkCanvas when built as a layer void setOrigin(int x, int y) { fOrigin.set(x, y); } // just called by SkCanvas for saveLayer - SkDevice* createCompatibleDeviceForSaveLayer(SkBitmap::Config config, - int width, int height, - bool isOpaque); + SkBaseDevice* createCompatibleDeviceForSaveLayer(SkBitmap::Config config, + int width, int height, + bool isOpaque); /** * Subclasses should override this to implement createCompatibleDevice. */ - virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config, - int width, int height, - bool isOpaque, - Usage usage); + virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config, + int width, int height, + bool isOpaque, + Usage usage) = 0; /** Causes any deferred drawing to the device to be completed. */ - virtual void flush() {} + virtual void flush() = 0; - SkBitmap fBitmap; SkIPoint fOrigin; SkMetaData* fMetaData; /** @@ -466,6 +420,4 @@ private: typedef SkRefCnt INHERITED; }; -typedef SkDevice SkBaseDevice; - #endif diff --git a/include/core/SkDraw.h b/include/core/SkDraw.h index 8642f0a..1c2c66e 100644 --- a/include/core/SkDraw.h +++ b/include/core/SkDraw.h @@ -17,7 +17,7 @@ class SkBitmap; class SkBounder; class SkClipStack; -class SkDevice; +class SkBaseDevice; class SkMatrix; class SkPath; class SkRegion; @@ -127,7 +127,7 @@ public: const SkRasterClip* fRC; // required const SkClipStack* fClipStack; // optional - SkDevice* fDevice; // optional + SkBaseDevice* fDevice; // optional SkBounder* fBounder; // optional SkDrawProcs* fProcs; // optional diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h index 7b9dd32..3dc145c 100644 --- a/include/core/SkImageFilter.h +++ b/include/core/SkImageFilter.h @@ -13,7 +13,7 @@ class SkBitmap; class SkColorFilter; -class SkDevice; +class SkBaseDevice; class SkMatrix; struct SkIPoint; class SkShader; @@ -35,7 +35,7 @@ public: public: virtual ~Proxy() {}; - virtual SkDevice* createDevice(int width, int height) = 0; + virtual SkBaseDevice* createDevice(int width, int height) = 0; // returns true if the proxy can handle this filter natively virtual bool canHandleImageFilter(SkImageFilter*) = 0; // returns true if the proxy handled the filter itself. if this returns diff --git a/include/core/SkRRect.h b/include/core/SkRRect.h index bce896a..32d6285 100644 --- a/include/core/SkRRect.h +++ b/include/core/SkRRect.h @@ -25,7 +25,7 @@ class SkPath; // use growToInclude to fit skp round rects & generate stats (RRs vs. real paths) // check on # of rectorus's the RRs could handle // rendering work -// add entry points (clipRRect, drawRRect) - plumb down to SkDevice +// add entry points (clipRRect, drawRRect) - plumb down to SkBaseDevice // update SkPath.addRRect() to take an SkRRect - only use quads // -- alternatively add addRRectToPath here // add GM and bench diff --git a/include/device/xps/SkXPSDevice.h b/include/device/xps/SkXPSDevice.h index dab8d1f..c33e450 100644 --- a/include/device/xps/SkXPSDevice.h +++ b/include/device/xps/SkXPSDevice.h @@ -13,10 +13,10 @@ #include #include "SkAutoCoInitialize.h" +#include "SkBitmapDevice.h" #include "SkBitSet.h" #include "SkCanvas.h" #include "SkColor.h" -#include "SkDevice.h" #include "SkPaint.h" #include "SkPath.h" #include "SkPoint.h" @@ -30,7 +30,7 @@ The drawing context for the XPS backend. */ -class SkXPSDevice : public SkDevice { +class SkXPSDevice : public SkBitmapDevice { public: SK_API SkXPSDevice(); SK_API virtual ~SkXPSDevice(); @@ -134,7 +134,7 @@ protected: virtual void drawDevice( const SkDraw&, - SkDevice* device, + SkBaseDevice* device, int x, int y, const SkPaint& paint) SK_OVERRIDE; @@ -307,18 +307,17 @@ private: const SkVector& ppuScale, IXpsOMPath* shadedPath); - // override from SkDevice - virtual SkDevice* onCreateCompatibleDevice( - SkBitmap::Config config, - int width, int height, - bool isOpaque, - Usage usage) SK_OVERRIDE; + // override from SkBaseDevice + virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config, + int width, int height, + bool isOpaque, + Usage usage) SK_OVERRIDE; // Disable the default copy and assign implementation. SkXPSDevice(const SkXPSDevice&); void operator=(const SkXPSDevice&); - typedef SkDevice INHERITED; + typedef SkBitmapDevice INHERITED; }; #endif diff --git a/include/gpu/SkGpuDevice.h b/include/gpu/SkGpuDevice.h index 40d2554..474fc2e 100644 --- a/include/gpu/SkGpuDevice.h +++ b/include/gpu/SkGpuDevice.h @@ -13,7 +13,7 @@ #include "SkGr.h" #include "SkBitmap.h" -#include "SkDevice.h" +#include "SkBitmapDevice.h" #include "SkRegion.h" #include "GrContext.h" @@ -22,10 +22,10 @@ struct GrSkDrawProcs; class GrTextContext; /** - * Subclass of SkDevice, which directs all drawing to the GrGpu owned by the + * Subclass of SkBitmapDevice, which directs all drawing to the GrGpu owned by the * canvas. */ -class SK_API SkGpuDevice : public SkDevice { +class SK_API SkGpuDevice : public SkBitmapDevice { public: /** @@ -62,7 +62,7 @@ public: virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE; - // overrides from SkDevice + // overrides from SkBaseDevice virtual void clear(SkColor color) SK_OVERRIDE; virtual void writePixels(const SkBitmap& bitmap, int x, int y, @@ -101,11 +101,11 @@ public: const SkColor colors[], SkXfermode* xmode, const uint16_t indices[], int indexCount, const SkPaint&) SK_OVERRIDE; - virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, + virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, const SkPaint&) SK_OVERRIDE; virtual bool filterTextFlags(const SkPaint&, TextFlags*) SK_OVERRIDE; - virtual void flush(); + virtual void flush() SK_OVERRIDE; virtual void onAttachToCanvas(SkCanvas* canvas) SK_OVERRIDE; virtual void onDetachFromCanvas() SK_OVERRIDE; @@ -123,7 +123,7 @@ public: class SkAutoCachedTexture; // used internally protected: - // overrides from SkDevice + // overrides from SkBaseDevice virtual bool onReadPixels(const SkBitmap& bitmap, int x, int y, SkCanvas::Config8888 config8888) SK_OVERRIDE; @@ -145,11 +145,11 @@ private: // used by createCompatibleDevice SkGpuDevice(GrContext*, GrTexture* texture, bool needClear); - // override from SkDevice - virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config, - int width, int height, - bool isOpaque, - Usage usage) SK_OVERRIDE; + // override from SkBaseDevice + virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config, + int width, int height, + bool isOpaque, + Usage usage) SK_OVERRIDE; SkDrawProcs* initDrawForText(GrTextContext*); @@ -192,7 +192,7 @@ private: */ GrTextContext* getTextContext(); - typedef SkDevice INHERITED; + typedef SkBitmapDevice INHERITED; }; #endif diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h index e64b83f..978dc1e 100644 --- a/include/pdf/SkPDFDevice.h +++ b/include/pdf/SkPDFDevice.h @@ -10,8 +10,8 @@ #ifndef SkPDFDevice_DEFINED #define SkPDFDevice_DEFINED +#include "SkBitmapDevice.h" #include "SkCanvas.h" -#include "SkDevice.h" #include "SkPaint.h" #include "SkPath.h" #include "SkRect.h" @@ -44,7 +44,7 @@ typedef bool (*EncodeToDCTStream)(SkWStream* stream, const SkBitmap& bitmap, con The drawing context for the PDF backend. */ -class SkPDFDevice : public SkDevice { +class SkPDFDevice : public SkBitmapDevice { public: /** Create a PDF drawing context with the given width and height. * 72 points/in means letter paper is 612x792. @@ -107,7 +107,7 @@ public: const SkPoint texs[], const SkColor colors[], SkXfermode* xmode, const uint16_t indices[], int indexCount, const SkPaint& paint) SK_OVERRIDE; - virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, + virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, const SkPaint&) SK_OVERRIDE; virtual void onAttachToCanvas(SkCanvas* canvas) SK_OVERRIDE; @@ -237,11 +237,11 @@ private: SkPDFDevice(const SkISize& layerSize, const SkClipStack& existingClipStack, const SkRegion& existingClipRegion); - // override from SkDevice - virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config, - int width, int height, - bool isOpaque, - Usage usage) SK_OVERRIDE; + // override from SkBaseDevice + virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config, + int width, int height, + bool isOpaque, + Usage usage) SK_OVERRIDE; void init(); void cleanUp(bool clearFontUsage); @@ -310,7 +310,7 @@ private: void defineNamedDestination(SkData* nameData, const SkPoint& point, const SkMatrix& matrix); - typedef SkDevice INHERITED; + typedef SkBitmapDevice INHERITED; }; #endif diff --git a/include/utils/SkDeferredCanvas.h b/include/utils/SkDeferredCanvas.h index 539e5d3..c0613ed 100644 --- a/include/utils/SkDeferredCanvas.h +++ b/include/utils/SkDeferredCanvas.h @@ -33,7 +33,7 @@ public: */ static SkDeferredCanvas* Create(SkSurface* surface); - static SkDeferredCanvas* Create(SkDevice* device); + static SkDeferredCanvas* Create(SkBaseDevice* device); virtual ~SkDeferredCanvas(); diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 53c28e4..b3632f8 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -269,7 +269,7 @@ public: SampleWindow* win) { #if SK_SUPPORT_GPU if (IsGpuDeviceType(dType) && NULL != fCurContext) { - SkAutoTUnref device(new SkGpuDevice(fCurContext, fCurRenderTarget)); + SkAutoTUnref device(new SkGpuDevice(fCurContext, fCurRenderTarget)); return new SkCanvas(device); } else #endif @@ -1429,7 +1429,7 @@ void SampleWindow::afterChildren(SkCanvas* orig) { if (fRequestGrabImage) { fRequestGrabImage = false; - SkDevice* device = orig->getDevice(); + SkBaseDevice* device = orig->getDevice(); SkBitmap bmp; if (device->accessBitmap(false).copyTo(&bmp, SkBitmap::kARGB_8888_Config)) { static int gSampleGrabCounter; diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h index 61e6c5d..9328f15 100644 --- a/samplecode/SampleApp.h +++ b/samplecode/SampleApp.h @@ -61,7 +61,7 @@ public: /** * SampleApp ports can subclass this manager class if they want to: * * filter the types of devices supported - * * customize plugging of SkDevice objects into an SkCanvas + * * customize plugging of SkBaseDevice objects into an SkCanvas * * customize publishing the results of draw to the OS window * * manage GrContext / GrRenderTarget lifetimes */ diff --git a/samplecode/SampleCircle.cpp b/samplecode/SampleCircle.cpp index f65ba01..87ca487 100644 --- a/samplecode/SampleCircle.cpp +++ b/samplecode/SampleCircle.cpp @@ -74,7 +74,7 @@ protected: } static void blowup(SkCanvas* canvas, const SkIRect& src, const SkRect& dst) { - SkDevice* device = canvas->getDevice(); + SkBaseDevice* device = canvas->getDevice(); const SkBitmap& bm = device->accessBitmap(false); canvas->drawBitmapRect(bm, &src, dst, NULL); } diff --git a/samplecode/SampleTextureDomain.cpp b/samplecode/SampleTextureDomain.cpp index de84c35..5928f3c 100644 --- a/samplecode/SampleTextureDomain.cpp +++ b/samplecode/SampleTextureDomain.cpp @@ -61,7 +61,7 @@ protected: // the constrainted texture domain. // Note: GPU-backed bitmaps follow a different rendering path // when copying from one GPU device to another. - SkAutoTUnref secondDevice(canvas->createCompatibleDevice( + SkAutoTUnref secondDevice(canvas->createCompatibleDevice( SkBitmap::kARGB_8888_Config, 5, 5, true)); SkCanvas secondCanvas(secondDevice.get()); diff --git a/src/core/SkBBoxHierarchyRecord.cpp b/src/core/SkBBoxHierarchyRecord.cpp index 9c02468..61a82ce 100644 --- a/src/core/SkBBoxHierarchyRecord.cpp +++ b/src/core/SkBBoxHierarchyRecord.cpp @@ -11,7 +11,7 @@ SkBBoxHierarchyRecord::SkBBoxHierarchyRecord(uint32_t recordFlags, SkBBoxHierarchy* h, - SkDevice* device) + SkBaseDevice* device) : INHERITED(recordFlags, device) { fStateTree = SkNEW(SkPictureStateTree); fBoundingHierarchy = h; diff --git a/src/core/SkBBoxHierarchyRecord.h b/src/core/SkBBoxHierarchyRecord.h index 27da3c9..7284ab0 100644 --- a/src/core/SkBBoxHierarchyRecord.h +++ b/src/core/SkBBoxHierarchyRecord.h @@ -20,7 +20,7 @@ class SkBBoxHierarchyRecord : public SkBBoxRecord, public SkBBoxHierarchyClient public: /** This will take a ref of h */ SkBBoxHierarchyRecord(uint32_t recordFlags, SkBBoxHierarchy* h, - SkDevice*); + SkBaseDevice*); virtual void handleBBox(const SkRect& bounds) SK_OVERRIDE; diff --git a/src/core/SkBBoxRecord.h b/src/core/SkBBoxRecord.h index 7859df1..fa8b282 100644 --- a/src/core/SkBBoxRecord.h +++ b/src/core/SkBBoxRecord.h @@ -19,7 +19,7 @@ class SkBBoxRecord : public SkPictureRecord { public: - SkBBoxRecord(uint32_t recordFlags, SkDevice* device) + SkBBoxRecord(uint32_t recordFlags, SkBaseDevice* device) : INHERITED(recordFlags, device) { } virtual ~SkBBoxRecord() { } diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index ff688f5..7add524 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -8,8 +8,8 @@ #include "SkCanvas.h" +#include "SkBitmapDevice.h" #include "SkBounder.h" -#include "SkDevice.h" #include "SkDeviceImageFilterProxy.h" #include "SkDraw.h" #include "SkDrawFilter.h" @@ -129,7 +129,7 @@ void SkCanvas::predrawNotify() { /////////////////////////////////////////////////////////////////////////////// -/* This is the record we keep for each SkDevice that the user installs. +/* This is the record we keep for each SkBaseDevice that the user installs. The clip/matrix/proc are fields that reflect the top of the save/restore stack. Whenever the canvas changes, it marks a dirty flag, and then before these are used (assuming we're not on a layer) we rebuild these cache @@ -138,12 +138,12 @@ void SkCanvas::predrawNotify() { */ struct DeviceCM { DeviceCM* fNext; - SkDevice* fDevice; + SkBaseDevice* fDevice; SkRasterClip fClip; const SkMatrix* fMatrix; SkPaint* fPaint; // may be null (in the future) - DeviceCM(SkDevice* device, int x, int y, const SkPaint* paint, SkCanvas* canvas) + DeviceCM(SkBaseDevice* device, int x, int y, const SkPaint* paint, SkCanvas* canvas) : fNext(NULL) { if (NULL != device) { device->ref(); @@ -315,7 +315,7 @@ public: return false; } - SkDevice* getDevice() const { return fDevice; } + SkBaseDevice* getDevice() const { return fDevice; } int getX() const { return fDevice->getOrigin().x(); } int getY() const { return fDevice->getOrigin().y(); } const SkMatrix& getMatrix() const { return *fMatrix; } @@ -482,7 +482,7 @@ private: //////////////////////////////////////////////////////////////////////////// -SkDevice* SkCanvas::init(SkDevice* device) { +SkBaseDevice* SkCanvas::init(SkBaseDevice* device) { fBounder = NULL; fLocalBoundsCompareType.setEmpty(); fLocalBoundsCompareTypeDirty = true; @@ -511,7 +511,7 @@ SkCanvas::SkCanvas() this->init(NULL); } -SkCanvas::SkCanvas(SkDevice* device) +SkCanvas::SkCanvas(SkBaseDevice* device) : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) { inc_canvas(); @@ -522,7 +522,7 @@ SkCanvas::SkCanvas(const SkBitmap& bitmap) : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) { inc_canvas(); - this->init(SkNEW_ARGS(SkDevice, (bitmap)))->unref(); + this->init(SkNEW_ARGS(SkBitmapDevice, (bitmap)))->unref(); } SkCanvas::~SkCanvas() { @@ -564,37 +564,37 @@ SkMetaData& SkCanvas::getMetaData() { /////////////////////////////////////////////////////////////////////////////// void SkCanvas::flush() { - SkDevice* device = this->getDevice(); + SkBaseDevice* device = this->getDevice(); if (device) { device->flush(); } } SkISize SkCanvas::getDeviceSize() const { - SkDevice* d = this->getDevice(); + SkBaseDevice* d = this->getDevice(); return d ? SkISize::Make(d->width(), d->height()) : SkISize::Make(0, 0); } -SkDevice* SkCanvas::getDevice() const { +SkBaseDevice* SkCanvas::getDevice() const { // return root device MCRec* rec = (MCRec*) fMCStack.front(); SkASSERT(rec && rec->fLayer); return rec->fLayer->fDevice; } -SkDevice* SkCanvas::getTopDevice(bool updateMatrixClip) const { +SkBaseDevice* SkCanvas::getTopDevice(bool updateMatrixClip) const { if (updateMatrixClip) { const_cast(this)->updateDeviceCMCache(); } return fMCRec->fTopLayer->fDevice; } -SkDevice* SkCanvas::setDevice(SkDevice* device) { +SkBaseDevice* SkCanvas::setDevice(SkBaseDevice* device) { // return root device SkDeque::F2BIter iter(fMCStack); MCRec* rec = (MCRec*)iter.next(); SkASSERT(rec && rec->fLayer); - SkDevice* rootDevice = rec->fLayer->fDevice; + SkBaseDevice* rootDevice = rec->fLayer->fDevice; if (rootDevice == device) { return device; @@ -644,7 +644,7 @@ SkDevice* SkCanvas::setDevice(SkDevice* device) { bool SkCanvas::readPixels(SkBitmap* bitmap, int x, int y, Config8888 config8888) { - SkDevice* device = this->getDevice(); + SkBaseDevice* device = this->getDevice(); if (!device) { return false; } @@ -652,7 +652,7 @@ bool SkCanvas::readPixels(SkBitmap* bitmap, } bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) { - SkDevice* device = this->getDevice(); + SkBaseDevice* device = this->getDevice(); if (!device) { return false; } @@ -676,7 +676,7 @@ bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) { void SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y, Config8888 config8888) { - SkDevice* device = this->getDevice(); + SkBaseDevice* device = this->getDevice(); if (device) { if (SkIRect::Intersects(SkIRect::MakeSize(this->getDeviceSize()), SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.height()))) { @@ -748,7 +748,7 @@ static SkBitmap::Config resolve_config(SkCanvas* canvas, uint32_t configMask = 0; for (int i = canvas->countLayerDevices() - 1; i >= 0; --i) { - SkDevice* device = canvas->getLayerDevice(i); + SkBaseDevice* device = canvas->getLayerDevice(i); if (device->intersects(bounds)) configMask |= 1 << device->config(); } @@ -849,7 +849,7 @@ int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, bool isOpaque; SkBitmap::Config config = resolve_config(this, ir, flags, &isOpaque); - SkDevice* device; + SkBaseDevice* device; if (paint && paint->getImageFilter()) { device = this->createCompatibleDevice(config, ir.width(), ir.height(), isOpaque); @@ -981,7 +981,7 @@ void SkCanvas::internalDrawBitmap(const SkBitmap& bitmap, LOOPER_END } -void SkCanvas::internalDrawDevice(SkDevice* srcDev, int x, int y, +void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y, const SkPaint* paint) { SkPaint tmp; if (NULL == paint) { @@ -991,7 +991,7 @@ void SkCanvas::internalDrawDevice(SkDevice* srcDev, int x, int y, LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) while (iter.next()) { - SkDevice* dstDev = iter.fDevice; + SkBaseDevice* dstDev = iter.fDevice; paint = &looper.paint(); SkImageFilter* filter = paint->getImageFilter(); SkIPoint pos = { x - iter.getX(), y - iter.getY() }; @@ -1167,7 +1167,7 @@ static bool clipPathHelper(const SkCanvas* canvas, SkRasterClip* currClip, return currClip->op(clip, op); } } else { - const SkDevice* device = canvas->getDevice(); + const SkBaseDevice* device = canvas->getDevice(); if (!device) { return currClip->setEmpty(); } @@ -1361,7 +1361,7 @@ bool SkCanvas::clipRegion(const SkRegion& rgn, SkRegion::Op op) { #ifdef SK_DEBUG void SkCanvas::validateClip() const { // construct clipRgn from the clipstack - const SkDevice* device = this->getDevice(); + const SkBaseDevice* device = this->getDevice(); if (!device) { SkASSERT(this->getTotalClip().isEmpty()); return; @@ -1546,10 +1546,10 @@ const SkRegion& SkCanvas::getTotalClip() const { return fMCRec->fRasterClip->forceGetBW(); } -SkDevice* SkCanvas::createLayerDevice(SkBitmap::Config config, +SkBaseDevice* SkCanvas::createLayerDevice(SkBitmap::Config config, int width, int height, bool isOpaque) { - SkDevice* device = this->getTopDevice(); + SkBaseDevice* device = this->getTopDevice(); if (device) { return device->createCompatibleDeviceForSaveLayer(config, width, height, isOpaque); @@ -1558,10 +1558,10 @@ SkDevice* SkCanvas::createLayerDevice(SkBitmap::Config config, } } -SkDevice* SkCanvas::createCompatibleDevice(SkBitmap::Config config, +SkBaseDevice* SkCanvas::createCompatibleDevice(SkBitmap::Config config, int width, int height, bool isOpaque) { - SkDevice* device = this->getDevice(); + SkBaseDevice* device = this->getDevice(); if (device) { return device->createCompatibleDevice(config, width, height, isOpaque); } else { @@ -1877,8 +1877,8 @@ void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, class SkDeviceFilteredPaint { public: - SkDeviceFilteredPaint(SkDevice* device, const SkPaint& paint) { - SkDevice::TextFlags flags; + SkDeviceFilteredPaint(SkBaseDevice* device, const SkPaint& paint) { + SkBaseDevice::TextFlags flags; if (device->filterTextFlags(paint, &flags)) { SkPaint* newPaint = fLazy.set(paint); newPaint->setFlags(flags.fFlags); @@ -2206,7 +2206,7 @@ void SkCanvas::LayerIter::next() { fDone = !fImpl->next(); } -SkDevice* SkCanvas::LayerIter::device() const { +SkBaseDevice* SkCanvas::LayerIter::device() const { return fImpl->getDevice(); } diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index d06f6e6..69b0f6a 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -5,6 +5,7 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#include "SkBitmapDevice.h" #include "SkDevice.h" #include "SkDeviceProperties.h" #include "SkDraw.h" @@ -15,7 +16,8 @@ #include "SkRRect.h" #include "SkShader.h" -SK_DEFINE_INST_COUNT(SkDevice) +SK_DEFINE_INST_COUNT(SkBaseDevice) +SK_DEFINE_INST_COUNT(SkBitmapDevice) /////////////////////////////////////////////////////////////////////////////// @@ -24,20 +26,13 @@ SK_DEFINE_INST_COUNT(SkDevice) /////////////////////////////////////////////////////////////////////////////// -SkDevice::SkDevice(const SkBitmap& bitmap) - : fBitmap(bitmap), fLeakyProperties(SkDeviceProperties::MakeDefault()) -#ifdef SK_DEBUG - , fAttachedToCanvas(false) -#endif -{ - fOrigin.setZero(); - fMetaData = NULL; - +SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) + : fBitmap(bitmap) { SkASSERT(SkBitmap::kARGB_4444_Config != bitmap.config()); } -SkDevice::SkDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties) - : fBitmap(bitmap), fLeakyProperties(deviceProperties) +SkBaseDevice::SkBaseDevice() + : fLeakyProperties(SkDeviceProperties::MakeDefault()) #ifdef SK_DEBUG , fAttachedToCanvas(false) #endif @@ -46,15 +41,22 @@ SkDevice::SkDevice(const SkBitmap& bitmap, const SkDeviceProperties& devicePrope fMetaData = NULL; } -SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque) - : fLeakyProperties(SkDeviceProperties::MakeDefault()) +SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties) + : SkBaseDevice(deviceProperties) + , fBitmap(bitmap) { +} + +SkBaseDevice::SkBaseDevice(const SkDeviceProperties& deviceProperties) + : fLeakyProperties(deviceProperties) #ifdef SK_DEBUG , fAttachedToCanvas(false) #endif { fOrigin.setZero(); fMetaData = NULL; +} +SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, bool isOpaque) { fBitmap.setConfig(config, width, height); fBitmap.allocPixels(); fBitmap.setIsOpaque(isOpaque); @@ -63,15 +65,9 @@ SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque } } -SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque, - const SkDeviceProperties& deviceProperties) - : fLeakyProperties(deviceProperties) -#ifdef SK_DEBUG - , fAttachedToCanvas(false) -#endif -{ - fOrigin.setZero(); - fMetaData = NULL; +SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, bool isOpaque, + const SkDeviceProperties& deviceProperties) + : SkBaseDevice(deviceProperties) { fBitmap.setConfig(config, width, height); fBitmap.allocPixels(); @@ -81,39 +77,43 @@ SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque } } -SkDevice::~SkDevice() { +SkBaseDevice::~SkBaseDevice() { delete fMetaData; } -void SkDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { +SkBitmapDevice::~SkBitmapDevice() { +} + +void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { SkASSERT(bm.width() == fBitmap.width()); SkASSERT(bm.height() == fBitmap.height()); fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) fBitmap.lockPixels(); } -SkDevice* SkDevice::createCompatibleDevice(SkBitmap::Config config, - int width, int height, - bool isOpaque) { +SkBaseDevice* SkBaseDevice::createCompatibleDevice(SkBitmap::Config config, + int width, int height, + bool isOpaque) { return this->onCreateCompatibleDevice(config, width, height, isOpaque, kGeneral_Usage); } -SkDevice* SkDevice::createCompatibleDeviceForSaveLayer(SkBitmap::Config config, - int width, int height, - bool isOpaque) { +SkBaseDevice* SkBaseDevice::createCompatibleDeviceForSaveLayer(SkBitmap::Config config, + int width, int height, + bool isOpaque) { return this->onCreateCompatibleDevice(config, width, height, isOpaque, kSaveLayer_Usage); } -SkDevice* SkDevice::onCreateCompatibleDevice(SkBitmap::Config config, - int width, int height, - bool isOpaque, - Usage usage) { - return SkNEW_ARGS(SkDevice,(config, width, height, isOpaque, fLeakyProperties)); +SkBaseDevice* SkBitmapDevice::onCreateCompatibleDevice(SkBitmap::Config config, + int width, int height, + bool isOpaque, + Usage usage) { + return SkNEW_ARGS(SkBitmapDevice,(config, width, height, isOpaque, + this->getDeviceProperties())); } -SkMetaData& SkDevice::getMetaData() { +SkMetaData& SkBaseDevice::getMetaData() { // metadata users are rare, so we lazily allocate it. If that changes we // can decide to just make it a field in the device (rather than a ptr) if (NULL == fMetaData) { @@ -122,61 +122,60 @@ SkMetaData& SkDevice::getMetaData() { return *fMetaData; } -void SkDevice::lockPixels() { +void SkBitmapDevice::lockPixels() { if (fBitmap.lockPixelsAreWritable()) { fBitmap.lockPixels(); } } -void SkDevice::unlockPixels() { +void SkBitmapDevice::unlockPixels() { if (fBitmap.lockPixelsAreWritable()) { fBitmap.unlockPixels(); } } -const SkBitmap& SkDevice::accessBitmap(bool changePixels) { - const SkBitmap& bitmap = this->onAccessBitmap(&fBitmap); +const SkBitmap& SkBaseDevice::accessBitmap(bool changePixels) { + const SkBitmap& bitmap = this->onAccessBitmap(); if (changePixels) { bitmap.notifyPixelsChanged(); } return bitmap; } -void SkDevice::getGlobalBounds(SkIRect* bounds) const { +void SkBitmapDevice::getGlobalBounds(SkIRect* bounds) const { if (bounds) { - bounds->setXYWH(fOrigin.x(), fOrigin.y(), + const SkIPoint& origin = this->getOrigin(); + bounds->setXYWH(origin.x(), origin.y(), fBitmap.width(), fBitmap.height()); } } -void SkDevice::clear(SkColor color) { +void SkBitmapDevice::clear(SkColor color) { fBitmap.eraseColor(color); } -const SkBitmap& SkDevice::onAccessBitmap(SkBitmap* bitmap) {return *bitmap;} - -void SkDevice::setMatrixClip(const SkMatrix& matrix, const SkRegion& region, - const SkClipStack& clipStack) { +const SkBitmap& SkBitmapDevice::onAccessBitmap() { + return fBitmap; } -bool SkDevice::canHandleImageFilter(SkImageFilter*) { +bool SkBitmapDevice::canHandleImageFilter(SkImageFilter*) { return false; } -bool SkDevice::filterImage(SkImageFilter* filter, const SkBitmap& src, - const SkMatrix& ctm, SkBitmap* result, - SkIPoint* offset) { +bool SkBitmapDevice::filterImage(SkImageFilter* filter, const SkBitmap& src, + const SkMatrix& ctm, SkBitmap* result, + SkIPoint* offset) { return false; } -bool SkDevice::allowImageFilter(SkImageFilter*) { +bool SkBitmapDevice::allowImageFilter(SkImageFilter*) { return true; } /////////////////////////////////////////////////////////////////////////////// -bool SkDevice::readPixels(SkBitmap* bitmap, int x, int y, - SkCanvas::Config8888 config8888) { +bool SkBaseDevice::readPixels(SkBitmap* bitmap, int x, int y, + SkCanvas::Config8888 config8888) { if (SkBitmap::kARGB_8888_Config != bitmap->config() || NULL != bitmap->getTexture()) { return false; @@ -220,21 +219,21 @@ bool SkDevice::readPixels(SkBitmap* bitmap, int x, int y, } #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) - const SkCanvas::Config8888 SkDevice::kPMColorAlias = + const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias = SkCanvas::kBGRA_Premul_Config8888; #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) - const SkCanvas::Config8888 SkDevice::kPMColorAlias = + const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias = SkCanvas::kRGBA_Premul_Config8888; #else - const SkCanvas::Config8888 SkDevice::kPMColorAlias = + const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias = (SkCanvas::Config8888) -1; #endif #include -bool SkDevice::onReadPixels(const SkBitmap& bitmap, - int x, int y, - SkCanvas::Config8888 config8888) { +bool SkBitmapDevice::onReadPixels(const SkBitmap& bitmap, + int x, int y, + SkCanvas::Config8888 config8888) { 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()))); @@ -257,9 +256,9 @@ bool SkDevice::onReadPixels(const SkBitmap& bitmap, return true; } -void SkDevice::writePixels(const SkBitmap& bitmap, - int x, int y, - SkCanvas::Config8888 config8888) { +void SkBitmapDevice::writePixels(const SkBitmap& bitmap, + int x, int y, + SkCanvas::Config8888 config8888) { if (bitmap.isNull() || bitmap.getTexture()) { return; } @@ -328,22 +327,22 @@ void SkDevice::writePixels(const SkBitmap& bitmap, /////////////////////////////////////////////////////////////////////////////// -void SkDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { +void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { draw.drawPaint(paint); } -void SkDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_t count, - const SkPoint pts[], const SkPaint& paint) { +void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_t count, + const SkPoint pts[], const SkPaint& paint) { CHECK_FOR_NODRAW_ANNOTATION(paint); draw.drawPoints(mode, count, pts, paint); } -void SkDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& paint) { +void SkBitmapDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& paint) { CHECK_FOR_NODRAW_ANNOTATION(paint); draw.drawRect(r, paint); } -void SkDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) { +void SkBitmapDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) { CHECK_FOR_NODRAW_ANNOTATION(paint); SkPath path; @@ -353,7 +352,7 @@ void SkDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& p this->drawPath(draw, path, paint, NULL, true); } -void SkDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const SkPaint& paint) { +void SkBitmapDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const SkPaint& paint) { CHECK_FOR_NODRAW_ANNOTATION(paint); SkPath path; @@ -363,22 +362,22 @@ void SkDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const SkPaint this->drawPath(draw, path, paint, NULL, true); } -void SkDevice::drawPath(const SkDraw& draw, const SkPath& path, - const SkPaint& paint, const SkMatrix* prePathMatrix, - bool pathIsMutable) { +void SkBitmapDevice::drawPath(const SkDraw& draw, const SkPath& path, + const SkPaint& paint, const SkMatrix* prePathMatrix, + bool pathIsMutable) { CHECK_FOR_NODRAW_ANNOTATION(paint); draw.drawPath(path, paint, prePathMatrix, pathIsMutable); } -void SkDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, - const SkMatrix& matrix, const SkPaint& paint) { +void SkBitmapDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, + const SkMatrix& matrix, const SkPaint& paint) { draw.drawBitmap(bitmap, matrix, paint); } -void SkDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, - const SkRect* src, const SkRect& dst, - const SkPaint& paint, - SkCanvas::DrawBitmapRectFlags flags) { +void SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, + const SkRect* src, const SkRect& dst, + const SkPaint& paint, + SkCanvas::DrawBitmapRectFlags flags) { SkMatrix matrix; SkRect bitmapBounds, tmpSrc, tmpDst; SkBitmap tmpBitmap; @@ -462,56 +461,56 @@ void SkDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, this->drawRect(draw, *dstPtr, paintWithShader); } -void SkDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, - int x, int y, const SkPaint& paint) { +void SkBitmapDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, + int x, int y, const SkPaint& paint) { draw.drawSprite(bitmap, x, y, paint); } -void SkDevice::drawText(const SkDraw& draw, const void* text, size_t len, - SkScalar x, SkScalar y, const SkPaint& paint) { +void SkBitmapDevice::drawText(const SkDraw& draw, const void* text, size_t len, + SkScalar x, SkScalar y, const SkPaint& paint) { draw.drawText((const char*)text, len, x, y, paint); } -void SkDevice::drawPosText(const SkDraw& draw, const void* text, size_t len, - const SkScalar xpos[], SkScalar y, - int scalarsPerPos, const SkPaint& paint) { +void SkBitmapDevice::drawPosText(const SkDraw& draw, const void* text, size_t len, + const SkScalar xpos[], SkScalar y, + int scalarsPerPos, const SkPaint& paint) { draw.drawPosText((const char*)text, len, xpos, y, scalarsPerPos, paint); } -void SkDevice::drawTextOnPath(const SkDraw& draw, const void* text, - size_t len, const SkPath& path, - const SkMatrix* matrix, - const SkPaint& paint) { +void SkBitmapDevice::drawTextOnPath(const SkDraw& draw, const void* text, + size_t len, const SkPath& path, + const SkMatrix* matrix, + const SkPaint& paint) { draw.drawTextOnPath((const char*)text, len, path, matrix, paint); } #ifdef SK_BUILD_FOR_ANDROID -void SkDevice::drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len, - const SkPoint pos[], const SkPaint& paint, - const SkPath& path, const SkMatrix* matrix) { +void SkBitmapDevice::drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len, + const SkPoint pos[], const SkPaint& paint, + const SkPath& path, const SkMatrix* matrix) { draw.drawPosTextOnPath((const char*)text, len, pos, paint, path, matrix); } #endif -void SkDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, - int vertexCount, - const SkPoint verts[], const SkPoint textures[], - const SkColor colors[], SkXfermode* xmode, - const uint16_t indices[], int indexCount, - const SkPaint& paint) { +void SkBitmapDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, + int vertexCount, + const SkPoint verts[], const SkPoint textures[], + const SkColor colors[], SkXfermode* xmode, + const uint16_t indices[], int indexCount, + const SkPaint& paint) { draw.drawVertices(vmode, vertexCount, verts, textures, colors, xmode, indices, indexCount, paint); } -void SkDevice::drawDevice(const SkDraw& draw, SkDevice* device, - int x, int y, const SkPaint& paint) { +void SkBitmapDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, + int x, int y, const SkPaint& paint) { const SkBitmap& src = device->accessBitmap(false); draw.drawSprite(src, x, y, paint); } /////////////////////////////////////////////////////////////////////////////// -bool SkDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { +bool SkBitmapDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { // we're cool with the paint as is return false; diff --git a/src/core/SkDeviceImageFilterProxy.h b/src/core/SkDeviceImageFilterProxy.h index 98a120c..03fcb68 100644 --- a/src/core/SkDeviceImageFilterProxy.h +++ b/src/core/SkDeviceImageFilterProxy.h @@ -12,9 +12,9 @@ class SkDeviceImageFilterProxy : public SkImageFilter::Proxy { public: - SkDeviceImageFilterProxy(SkDevice* device) : fDevice(device) {} + SkDeviceImageFilterProxy(SkBaseDevice* device) : fDevice(device) {} - virtual SkDevice* createDevice(int w, int h) SK_OVERRIDE { + virtual SkBaseDevice* createDevice(int w, int h) SK_OVERRIDE { return fDevice->createCompatibleDevice(SkBitmap::kARGB_8888_Config, w, h, false); } @@ -28,7 +28,7 @@ public: } private: - SkDevice* fDevice; + SkBaseDevice* fDevice; }; #endif diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index c94641b..1aa4528 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -11,9 +11,9 @@ #include "SkPicturePlayback.h" #include "SkPictureRecord.h" +#include "SkBitmapDevice.h" #include "SkCanvas.h" #include "SkChunkAlloc.h" -#include "SkDevice.h" #include "SkPicture.h" #include "SkRegion.h" #include "SkStream.h" @@ -205,7 +205,7 @@ SkCanvas* SkPicture::beginRecording(int width, int height, SkBitmap bm; bm.setConfig(SkBitmap::kNo_Config, width, height); - SkAutoTUnref dev(SkNEW_ARGS(SkDevice, (bm))); + SkAutoTUnref dev(SkNEW_ARGS(SkBitmapDevice, (bm))); // Must be set before calling createBBoxHierarchy fWidth = width; diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp index 4134f8d..92a1448 100644 --- a/src/core/SkPictureRecord.cpp +++ b/src/core/SkPictureRecord.cpp @@ -28,7 +28,7 @@ static const uint32_t kSaveSize = 2 * kUInt32Size; static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect); -SkPictureRecord::SkPictureRecord(uint32_t flags, SkDevice* device) : +SkPictureRecord::SkPictureRecord(uint32_t flags, SkBaseDevice* device) : INHERITED(device), fBoundingHierarchy(NULL), fStateTree(NULL), @@ -138,7 +138,7 @@ static inline uint32_t getPaintOffset(DrawType op, uint32_t opSize) { return gPaintOffsets[op] * sizeof(uint32_t) + overflow; } -SkDevice* SkPictureRecord::setDevice(SkDevice* device) { +SkBaseDevice* SkPictureRecord::setDevice(SkBaseDevice* device) { SkDEBUGFAIL("eeek, don't try to change the device on a recording canvas"); return this->INHERITED::setDevice(device); } diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h index b900f4f..a1eb40a 100644 --- a/src/core/SkPictureRecord.h +++ b/src/core/SkPictureRecord.h @@ -30,10 +30,10 @@ class SkBBoxHierarchy; class SkPictureRecord : public SkCanvas { public: - SkPictureRecord(uint32_t recordFlags, SkDevice*); + SkPictureRecord(uint32_t recordFlags, SkBaseDevice*); virtual ~SkPictureRecord(); - virtual SkDevice* setDevice(SkDevice* device) SK_OVERRIDE; + virtual SkBaseDevice* setDevice(SkBaseDevice* device) SK_OVERRIDE; virtual int save(SaveFlags) SK_OVERRIDE; virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE; diff --git a/src/device/xps/SkXPSDevice.cpp b/src/device/xps/SkXPSDevice.cpp index 79bb6ef..0881a0f 100644 --- a/src/device/xps/SkXPSDevice.cpp +++ b/src/device/xps/SkXPSDevice.cpp @@ -111,7 +111,7 @@ static SkBitmap make_fake_bitmap(int width, int height) { } SkXPSDevice::SkXPSDevice() - : SkDevice(make_fake_bitmap(10000, 10000)) + : SkBitmapDevice(make_fake_bitmap(10000, 10000)) , fCurrentPage(0) { } @@ -2375,7 +2375,7 @@ void SkXPSDevice::drawTextOnPath(const SkDraw& d, const void* text, size_t len, d.drawTextOnPath((const char*)text, len, path, matrix, paint); } -void SkXPSDevice::drawDevice(const SkDraw& d, SkDevice* dev, +void SkXPSDevice::drawDevice(const SkDraw& d, SkBaseDevice* dev, int x, int y, const SkPaint&) { SkXPSDevice* that = static_cast(dev); @@ -2407,11 +2407,11 @@ bool SkXPSDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, return false; } -SkDevice* SkXPSDevice::onCreateCompatibleDevice(SkBitmap::Config config, - int width, int height, - bool isOpaque, - Usage usage) { - if (SkDevice::kGeneral_Usage == usage) { +SkBaseDevice* SkXPSDevice::onCreateCompatibleDevice(SkBitmap::Config config, + int width, int height, + bool isOpaque, + Usage usage) { + if (SkBaseDevice::kGeneral_Usage == usage) { return NULL; SK_CRASH(); //To what stream do we write? @@ -2425,7 +2425,7 @@ SkDevice* SkXPSDevice::onCreateCompatibleDevice(SkBitmap::Config config, } SkXPSDevice::SkXPSDevice(IXpsOMObjectFactory* xpsFactory) - : SkDevice(make_fake_bitmap(10000, 10000)) + : SkBitmapDevice(make_fake_bitmap(10000, 10000)) , fCurrentPage(0) { HRVM(CoCreateInstance( diff --git a/src/effects/SkColorFilterImageFilter.cpp b/src/effects/SkColorFilterImageFilter.cpp index 16a36bb..cfda0b7 100755 --- a/src/effects/SkColorFilterImageFilter.cpp +++ b/src/effects/SkColorFilterImageFilter.cpp @@ -111,7 +111,7 @@ bool SkColorFilterImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& sourc return false; } - SkAutoTUnref device(proxy->createDevice(bounds.width(), bounds.height())); + SkAutoTUnref device(proxy->createDevice(bounds.width(), bounds.height())); SkCanvas canvas(device.get()); SkPaint paint; diff --git a/src/effects/SkDropShadowImageFilter.cpp b/src/effects/SkDropShadowImageFilter.cpp index b8bbfd6..75a8668 100644 --- a/src/effects/SkDropShadowImageFilter.cpp +++ b/src/effects/SkDropShadowImageFilter.cpp @@ -46,7 +46,7 @@ bool SkDropShadowImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, loc)) return false; - SkAutoTUnref device(proxy->createDevice(src.width(), src.height())); + SkAutoTUnref device(proxy->createDevice(src.width(), src.height())); SkCanvas canvas(device.get()); SkAutoTUnref blurFilter(new SkBlurImageFilter(fSigma, fSigma)); diff --git a/src/effects/SkMergeImageFilter.cpp b/src/effects/SkMergeImageFilter.cpp index 0c1388f..0c47c91 100755 --- a/src/effects/SkMergeImageFilter.cpp +++ b/src/effects/SkMergeImageFilter.cpp @@ -109,7 +109,7 @@ bool SkMergeImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, const int x0 = bounds.left(); const int y0 = bounds.top(); - SkAutoTUnref dst(proxy->createDevice(bounds.width(), bounds.height())); + SkAutoTUnref dst(proxy->createDevice(bounds.width(), bounds.height())); if (NULL == dst) { return false; } diff --git a/src/effects/SkRectShaderImageFilter.cpp b/src/effects/SkRectShaderImageFilter.cpp index ada861f..2ee1d4a 100644 --- a/src/effects/SkRectShaderImageFilter.cpp +++ b/src/effects/SkRectShaderImageFilter.cpp @@ -56,8 +56,8 @@ bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy, return false; } - SkAutoTUnref device(proxy->createDevice(SkScalarCeilToInt(rect.width()), - SkScalarCeilToInt(rect.height()))); + SkAutoTUnref device(proxy->createDevice(SkScalarCeilToInt(rect.width()), + SkScalarCeilToInt(rect.height()))); SkCanvas canvas(device.get()); SkPaint paint; paint.setShader(fShader); diff --git a/src/effects/SkTestImageFilters.cpp b/src/effects/SkTestImageFilters.cpp index a919ded..788c33a 100755 --- a/src/effects/SkTestImageFilters.cpp +++ b/src/effects/SkTestImageFilters.cpp @@ -9,11 +9,11 @@ // with the following: // // SkCanvas canvas(device); -// SkAutoTUnref aur(device); +// SkAutoTUnref aur(device); // class OwnDeviceCanvas : public SkCanvas { public: - OwnDeviceCanvas(SkDevice* device) : SkCanvas(device) { + OwnDeviceCanvas(SkBaseDevice* device) : SkCanvas(device) { SkSafeUnref(device); } }; @@ -41,7 +41,7 @@ bool SkDownSampleImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, // downsample { - SkDevice* dev = proxy->createDevice(dstW, dstH); + SkBaseDevice* dev = proxy->createDevice(dstW, dstH); if (NULL == dev) { return false; } @@ -56,7 +56,7 @@ bool SkDownSampleImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, // upscale { - SkDevice* dev = proxy->createDevice(src.width(), src.height()); + SkBaseDevice* dev = proxy->createDevice(src.width(), src.height()); if (NULL == dev) { return false; } diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index f77fdf7..571b8a0 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -161,12 +161,12 @@ SkGpuDevice* SkGpuDevice::Create(GrSurface* surface) { } SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture) -: SkDevice(make_bitmap(context, texture->asRenderTarget())) { + : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { this->initFromRenderTarget(context, texture->asRenderTarget(), false); } SkGpuDevice::SkGpuDevice(GrContext* context, GrRenderTarget* renderTarget) -: SkDevice(make_bitmap(context, renderTarget)) { + : SkBitmapDevice(make_bitmap(context, renderTarget)) { this->initFromRenderTarget(context, renderTarget, false); } @@ -203,7 +203,7 @@ SkGpuDevice::SkGpuDevice(GrContext* context, int width, int height, int sampleCount) - : SkDevice(config, width, height, false /*isOpaque*/) { + : SkBitmapDevice(config, width, height, false /*isOpaque*/) { fDrawProcs = NULL; @@ -1436,7 +1436,7 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap, fContext->drawRectToRect(grPaint, dstRect, paintRect, &m); } -static bool filter_texture(SkDevice* device, GrContext* context, +static bool filter_texture(SkBaseDevice* device, GrContext* context, GrTexture* texture, SkImageFilter* filter, int w, int h, const SkMatrix& ctm, SkBitmap* result, SkIPoint* offset) { @@ -1537,7 +1537,7 @@ void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, this->drawBitmapCommon(draw, bitmap, &tmpSrc, matrix, paint, flags); } -void SkGpuDevice::drawDevice(const SkDraw& draw, SkDevice* device, +void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, int x, int y, const SkPaint& paint) { // clear of the source device must occur before CHECK_SHOULD_DRAW SkGpuDevice* dev = static_cast(device); @@ -1822,10 +1822,10 @@ void SkGpuDevice::flush() { /////////////////////////////////////////////////////////////////////////////// -SkDevice* SkGpuDevice::onCreateCompatibleDevice(SkBitmap::Config config, - int width, int height, - bool isOpaque, - Usage usage) { +SkBaseDevice* SkGpuDevice::onCreateCompatibleDevice(SkBitmap::Config config, + int width, int height, + bool isOpaque, + Usage usage) { GrTextureDesc desc; desc.fConfig = fRenderTarget->config(); desc.fFlags = kRenderTarget_GrTextureFlagBit; @@ -1858,7 +1858,7 @@ SkDevice* SkGpuDevice::onCreateCompatibleDevice(SkBitmap::Config config, SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture, bool needClear) - : SkDevice(make_bitmap(context, texture->asRenderTarget())) { + : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { SkASSERT(texture && texture->asRenderTarget()); // This constructor is called from onCreateCompatibleDevice. It has locked the RT in the texture diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index a24c4ec..02dda02 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -566,10 +566,10 @@ void GraphicStackState::updateDrawingState(const GraphicStateEntry& state) { } } -SkDevice* SkPDFDevice::onCreateCompatibleDevice(SkBitmap::Config config, - int width, int height, - bool isOpaque, - Usage usage) { +SkBaseDevice* SkPDFDevice::onCreateCompatibleDevice(SkBitmap::Config config, + int width, int height, + bool isOpaque, + Usage usage) { SkMatrix initialTransform; initialTransform.reset(); SkISize size = SkISize::Make(width, height); @@ -672,7 +672,7 @@ static inline SkBitmap makeContentBitmap(const SkISize& contentSize, // TODO(vandebo) change pageSize to SkSize. SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, const SkMatrix& initialTransform) - : SkDevice(makeContentBitmap(contentSize, &initialTransform)), + : SkBitmapDevice(makeContentBitmap(contentSize, &initialTransform)), fPageSize(pageSize), fContentSize(contentSize), fLastContentEntry(NULL), @@ -696,7 +696,7 @@ SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, SkPDFDevice::SkPDFDevice(const SkISize& layerSize, const SkClipStack& existingClipStack, const SkRegion& existingClipRegion) - : SkDevice(makeContentBitmap(layerSize, NULL)), + : SkBitmapDevice(makeContentBitmap(layerSize, NULL)), fPageSize(layerSize), fContentSize(layerSize), fExistingClipStack(existingClipStack), @@ -1153,11 +1153,11 @@ void SkPDFDevice::drawVertices(const SkDraw& d, SkCanvas::VertexMode, NOT_IMPLEMENTED("drawVerticies", true); } -void SkPDFDevice::drawDevice(const SkDraw& d, SkDevice* device, int x, int y, +void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device, int x, int y, const SkPaint& paint) { if ((device->getDeviceCapabilities() & kVector_Capability) == 0) { // If we somehow get a raster device, do what our parent would do. - SkDevice::drawDevice(d, device, x, y, paint); + INHERITED::drawDevice(d, device, x, y, paint); return; } diff --git a/src/pipe/SkGPipeWrite.cpp b/src/pipe/SkGPipeWrite.cpp index f646bab..58ba102 100644 --- a/src/pipe/SkGPipeWrite.cpp +++ b/src/pipe/SkGPipeWrite.cpp @@ -7,12 +7,12 @@ */ #include "SkAnnotation.h" +#include "SkBitmapDevice.h" #include "SkBitmapHeap.h" #include "SkCanvas.h" #include "SkColorFilter.h" #include "SkData.h" #include "SkDrawLooper.h" -#include "SkDevice.h" #include "SkGPipe.h" #include "SkGPipePriv.h" #include "SkImageFilter.h" @@ -432,7 +432,7 @@ SkGPipeCanvas::SkGPipeCanvas(SkGPipeController* controller, // We don't allocate pixels for the bitmap SkBitmap bitmap; bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); - SkDevice* device = SkNEW_ARGS(SkDevice, (bitmap)); + SkBaseDevice* device = SkNEW_ARGS(SkBitmapDevice, (bitmap)); this->setDevice(device)->unref(); // Tell the reader the appropriate flags to use. diff --git a/src/pipe/utils/SamplePipeControllers.cpp b/src/pipe/utils/SamplePipeControllers.cpp index a23d775..1e25cb6 100644 --- a/src/pipe/utils/SamplePipeControllers.cpp +++ b/src/pipe/utils/SamplePipeControllers.cpp @@ -7,8 +7,8 @@ #include "SamplePipeControllers.h" +#include "SkBitmapDevice.h" #include "SkCanvas.h" -#include "SkDevice.h" #include "SkGPipe.h" #include "SkMatrix.h" @@ -55,7 +55,7 @@ TiledPipeController::TiledPipeController(const SkBitmap& bitmap, SkDEBUGCODE(bool extracted = )bitmap.extractSubset(&fBitmaps[i], rect); SkASSERT(extracted); - SkDevice* device = new SkDevice(fBitmaps[i]); + SkBaseDevice* device = new SkBitmapDevice(fBitmaps[i]); SkCanvas* canvas = new SkCanvas(device); device->unref(); if (initial != NULL) { diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp index e3b761f..4509038 100644 --- a/src/utils/SkDeferredCanvas.cpp +++ b/src/utils/SkDeferredCanvas.cpp @@ -8,9 +8,9 @@ #include "SkDeferredCanvas.h" +#include "SkBitmapDevice.h" #include "SkChunkAlloc.h" #include "SkColorFilter.h" -#include "SkDevice.h" #include "SkDrawFilter.h" #include "SkGPipe.h" #include "SkPaint.h" @@ -137,16 +137,16 @@ void DeferredPipeController::playback(bool silent) { //----------------------------------------------------------------------------- // DeferredDevice //----------------------------------------------------------------------------- -class DeferredDevice : public SkDevice { +class DeferredDevice : public SkBitmapDevice { public: - explicit DeferredDevice(SkDevice* immediateDevice); + explicit DeferredDevice(SkBaseDevice* immediateDevice); explicit DeferredDevice(SkSurface* surface); ~DeferredDevice(); void setNotificationClient(SkDeferredCanvas::NotificationClient* notificationClient); SkCanvas* recordingCanvas(); SkCanvas* immediateCanvas() const {return fImmediateCanvas;} - SkDevice* immediateDevice() const {return fImmediateCanvas->getTopDevice();} + SkBaseDevice* immediateDevice() const {return fImmediateCanvas->getTopDevice();} SkImage* newImageSnapshot(); void setSurface(SkSurface* surface); bool isFreshFrame(); @@ -165,24 +165,24 @@ public: virtual int height() const SK_OVERRIDE; virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE; - virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config, - int width, int height, - bool isOpaque, - Usage usage) SK_OVERRIDE; + virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config, + int width, int height, + bool isOpaque, + Usage usage) SK_OVERRIDE; virtual void writePixels(const SkBitmap& bitmap, int x, int y, SkCanvas::Config8888 config8888) SK_OVERRIDE; protected: - virtual const SkBitmap& onAccessBitmap(SkBitmap*) SK_OVERRIDE; + virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE; virtual bool onReadPixels(const SkBitmap& bitmap, int x, int y, SkCanvas::Config8888 config8888) SK_OVERRIDE; // The following methods are no-ops on a deferred device - virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) - SK_OVERRIDE - {return false;} + virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE { + return false; + } // None of the following drawing methods should ever get called on the // deferred device @@ -234,7 +234,7 @@ protected: SkXfermode* xmode, const uint16_t indices[], int indexCount, const SkPaint& paint) SK_OVERRIDE {SkASSERT(0);} - virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, + virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, const SkPaint&) SK_OVERRIDE {SkASSERT(0);} private: @@ -258,11 +258,11 @@ private: size_t fBitmapSizeThreshold; }; -DeferredDevice::DeferredDevice(SkDevice* immediateDevice) - : SkDevice(SkBitmap::kNo_Config, - immediateDevice->width(), immediateDevice->height(), - immediateDevice->isOpaque(), - immediateDevice->getDeviceProperties()) { +DeferredDevice::DeferredDevice(SkBaseDevice* immediateDevice) + : SkBitmapDevice(SkBitmap::kNo_Config, + immediateDevice->width(), immediateDevice->height(), + immediateDevice->isOpaque(), + immediateDevice->getDeviceProperties()) { fSurface = NULL; fImmediateCanvas = SkNEW_ARGS(SkCanvas, (immediateDevice)); fPipeController.setPlaybackCanvas(fImmediateCanvas); @@ -270,11 +270,11 @@ DeferredDevice::DeferredDevice(SkDevice* immediateDevice) } DeferredDevice::DeferredDevice(SkSurface* surface) - : SkDevice(SkBitmap::kNo_Config, - surface->getCanvas()->getDevice()->width(), - surface->getCanvas()->getDevice()->height(), - surface->getCanvas()->getDevice()->isOpaque(), - surface->getCanvas()->getDevice()->getDeviceProperties()) { + : SkBitmapDevice(SkBitmap::kNo_Config, + surface->getCanvas()->getDevice()->width(), + surface->getCanvas()->getDevice()->height(), + surface->getCanvas()->getDevice()->isOpaque(), + surface->getCanvas()->getDevice()->getDeviceProperties()) { fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; fNotificationClient = NULL; fImmediateCanvas = NULL; @@ -492,12 +492,12 @@ void DeferredDevice::writePixels(const SkBitmap& bitmap, } } -const SkBitmap& DeferredDevice::onAccessBitmap(SkBitmap*) { +const SkBitmap& DeferredDevice::onAccessBitmap() { this->flushPendingCommands(kNormal_PlaybackMode); return immediateDevice()->accessBitmap(false); } -SkDevice* DeferredDevice::onCreateCompatibleDevice( +SkBaseDevice* DeferredDevice::onCreateCompatibleDevice( SkBitmap::Config config, int width, int height, bool isOpaque, Usage usage) { @@ -555,7 +555,7 @@ SkDeferredCanvas* SkDeferredCanvas::Create(SkSurface* surface) { return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice)); } -SkDeferredCanvas* SkDeferredCanvas::Create(SkDevice* device) { +SkDeferredCanvas* SkDeferredCanvas::Create(SkBaseDevice* device) { SkAutoTUnref deferredDevice(SkNEW_ARGS(DeferredDevice, (device))); return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice)); } diff --git a/src/utils/SkPictureUtils.cpp b/src/utils/SkPictureUtils.cpp index 45d3f1b..ce51614 100644 --- a/src/utils/SkPictureUtils.cpp +++ b/src/utils/SkPictureUtils.cpp @@ -5,13 +5,13 @@ * found in the LICENSE file. */ -#include "SkPictureUtils.h" +#include "SkBitmapDevice.h" #include "SkCanvas.h" #include "SkData.h" -#include "SkDevice.h" +#include "SkPictureUtils.h" #include "SkPixelRef.h" -#include "SkShader.h" #include "SkRRect.h" +#include "SkShader.h" class PixelRefSet { public: @@ -47,7 +47,7 @@ static void nothing_to_do() {} * It should never actually draw anything, so there need not be any pixels * behind its device-bitmap. */ -class GatherPixelRefDevice : public SkDevice { +class GatherPixelRefDevice : public SkBitmapDevice { private: PixelRefSet* fPRSet; @@ -70,7 +70,7 @@ private: } public: - GatherPixelRefDevice(const SkBitmap& bm, PixelRefSet* prset) : SkDevice(bm) { + GatherPixelRefDevice(const SkBitmap& bm, PixelRefSet* prset) : SkBitmapDevice(bm) { fPRSet = prset; } @@ -138,7 +138,7 @@ public: const SkPaint& paint) SK_OVERRIDE { this->addBitmapFromPaint(paint); } - virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, + virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, const SkPaint&) SK_OVERRIDE { nothing_to_do(); } @@ -150,11 +150,14 @@ protected: not_supported(); return false; } + +private: + typedef SkBitmapDevice INHERITED; }; class NoSaveLayerCanvas : public SkCanvas { public: - NoSaveLayerCanvas(SkDevice* device) : INHERITED(device) {} + NoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {} // turn saveLayer() into save() for speed, should not affect correctness. virtual int saveLayer(const SkRect* bounds, const SkPaint* paint, diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp index 26896fc..24c3348 100644 --- a/tests/CanvasTest.cpp +++ b/tests/CanvasTest.cpp @@ -779,7 +779,7 @@ public: SkBitmap deferredStore; createBitmap(&deferredStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); - SkDevice deferredDevice(deferredStore); + SkBitmapDevice deferredDevice(deferredStore); SkAutoTUnref deferredCanvas(SkDeferredCanvas::Create(&deferredDevice)); testStep->setAssertMessageFormat(kDeferredDrawAssertMessageFormat); testStep->draw(deferredCanvas, reporter); @@ -821,7 +821,7 @@ static void TestProxyCanvasStateConsistency( SkBitmap indirectStore; createBitmap(&indirectStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); - SkDevice indirectDevice(indirectStore); + SkBitmapDevice indirectDevice(indirectStore); SkCanvas indirectCanvas(&indirectDevice); SkProxyCanvas proxyCanvas(&indirectCanvas); testStep->setAssertMessageFormat(kProxyDrawAssertMessageFormat); @@ -844,12 +844,12 @@ static void TestNWayCanvasStateConsistency( SkBitmap indirectStore1; createBitmap(&indirectStore1, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); - SkDevice indirectDevice1(indirectStore1); + SkBitmapDevice indirectDevice1(indirectStore1); SkCanvas indirectCanvas1(&indirectDevice1); SkBitmap indirectStore2; createBitmap(&indirectStore2, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); - SkDevice indirectDevice2(indirectStore2); + SkBitmapDevice indirectDevice2(indirectStore2); SkCanvas indirectCanvas2(&indirectDevice2); SkISize canvasSize = referenceCanvas.getDeviceSize(); @@ -882,7 +882,7 @@ static void TestOverrideStateConsistency(skiatest::Reporter* reporter, CanvasTestStep* testStep) { SkBitmap referenceStore; createBitmap(&referenceStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); - SkDevice referenceDevice(referenceStore); + SkBitmapDevice referenceDevice(referenceStore); SkCanvas referenceCanvas(&referenceDevice); testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat); testStep->draw(&referenceCanvas, reporter); diff --git a/tests/DeferredCanvasTest.cpp b/tests/DeferredCanvasTest.cpp index 15474f5..7593ba8 100644 --- a/tests/DeferredCanvasTest.cpp +++ b/tests/DeferredCanvasTest.cpp @@ -7,9 +7,9 @@ */ #include "Test.h" #include "SkBitmap.h" +#include "SkBitmapDevice.h" #include "SkBitmapProcShader.h" #include "SkDeferredCanvas.h" -#include "SkDevice.h" #include "SkGradientShader.h" #include "SkShader.h" #include "../src/image/SkSurface_Base.h" @@ -33,7 +33,7 @@ static void TestDeferredCanvasBitmapAccess(skiatest::Reporter* reporter) { SkBitmap store; create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); - SkDevice device(store); + SkBitmapDevice device(store); SkAutoTUnref canvas(SkDeferredCanvas::Create(&device)); canvas->clear(0x00000000); @@ -259,7 +259,7 @@ static void TestDeferredCanvasFlush(skiatest::Reporter* reporter) { SkBitmap store; create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); - SkDevice device(store); + SkBitmapDevice device(store); SkAutoTUnref canvas(SkDeferredCanvas::Create(&device)); canvas->clear(0x00000000); @@ -279,7 +279,7 @@ static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) { partialRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(1), SkIntToScalar(1)); create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); - SkDevice device(store); + SkBitmapDevice device(store); SkAutoTUnref canvas(SkDeferredCanvas::Create(&device)); // verify that frame is intially fresh @@ -433,9 +433,9 @@ static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) { } } -class MockDevice : public SkDevice { +class MockDevice : public SkBitmapDevice { public: - MockDevice(const SkBitmap& bm) : SkDevice(bm) { + MockDevice(const SkBitmap& bm) : SkBitmapDevice(bm) { fDrawBitmapCallCount = 0; } virtual void drawBitmap(const SkDraw&, const SkBitmap&, @@ -502,7 +502,7 @@ static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) { SkBitmap store; store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); store.allocPixels(); - SkDevice device(store); + SkBitmapDevice device(store); NotificationCounter notificationCounter; SkAutoTUnref canvas(SkDeferredCanvas::Create(&device)); canvas->setNotificationClient(¬ificationCounter); @@ -585,7 +585,7 @@ static void TestDeferredCanvasSkip(skiatest::Reporter* reporter) { SkBitmap store; store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); store.allocPixels(); - SkDevice device(store); + SkBitmapDevice device(store); NotificationCounter notificationCounter; SkAutoTUnref canvas(SkDeferredCanvas::Create(&device)); canvas->setNotificationClient(¬ificationCounter); @@ -606,7 +606,7 @@ static void TestDeferredCanvasBitmapShaderNoLeak(skiatest::Reporter* reporter) { SkBitmap store; store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); store.allocPixels(); - SkDevice device(store); + SkBitmapDevice device(store); SkAutoTUnref canvas(SkDeferredCanvas::Create(&device)); // test will fail if nbIterations is not in sync with // BITMAPS_TO_KEEP in SkGPipeWrite.cpp @@ -652,7 +652,7 @@ static void TestDeferredCanvasBitmapSizeThreshold(skiatest::Reporter* reporter) // 1 under : should not store the image { - SkDevice device(store); + SkBitmapDevice device(store); SkAutoTUnref canvas(SkDeferredCanvas::Create(&device)); canvas->setBitmapSizeThreshold(39999); canvas->drawBitmap(sourceImage, 0, 0, NULL); @@ -662,7 +662,7 @@ static void TestDeferredCanvasBitmapSizeThreshold(skiatest::Reporter* reporter) // exact value : should store the image { - SkDevice device(store); + SkBitmapDevice device(store); SkAutoTUnref canvas(SkDeferredCanvas::Create(&device)); canvas->setBitmapSizeThreshold(40000); canvas->drawBitmap(sourceImage, 0, 0, NULL); @@ -672,7 +672,7 @@ static void TestDeferredCanvasBitmapSizeThreshold(skiatest::Reporter* reporter) // 1 over : should still store the image { - SkDevice device(store); + SkBitmapDevice device(store); SkAutoTUnref canvas(SkDeferredCanvas::Create(&device)); canvas->setBitmapSizeThreshold(40001); canvas->drawBitmap(sourceImage, 0, 0, NULL); @@ -807,11 +807,11 @@ static void TestDeferredCanvasCreateCompatibleDevice(skiatest::Reporter* reporte SkBitmap store; store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); store.allocPixels(); - SkDevice device(store); + SkBitmapDevice device(store); NotificationCounter notificationCounter; SkAutoTUnref canvas(SkDeferredCanvas::Create(&device)); canvas->setNotificationClient(¬ificationCounter); - SkAutoTUnref secondaryDevice(canvas->createCompatibleDevice( + SkAutoTUnref secondaryDevice(canvas->createCompatibleDevice( SkBitmap::kARGB_8888_Config, 10, 10, device.isOpaque())); SkCanvas secondaryCanvas(secondaryDevice.get()); SkRect rect = SkRect::MakeWH(5, 5); diff --git a/tests/GradientTest.cpp b/tests/GradientTest.cpp index cf8fbee..24ffb53 100644 --- a/tests/GradientTest.cpp +++ b/tests/GradientTest.cpp @@ -6,12 +6,12 @@ * found in the LICENSE file. */ #include "Test.h" -#include "SkDevice.h" -#include "SkTemplates.h" -#include "SkShader.h" +#include "SkBitmapDevice.h" #include "SkColorShader.h" #include "SkEmptyShader.h" #include "SkGradientShader.h" +#include "SkShader.h" +#include "SkTemplates.h" struct GradRec { int fColorCount; @@ -146,7 +146,7 @@ static void TestConstantGradient(skiatest::Reporter*) { outBitmap.allocPixels(); SkPaint paint; paint.setShader(s.get()); - SkDevice device(outBitmap); + SkBitmapDevice device(outBitmap); SkCanvas canvas(&device); canvas.drawPaint(paint); SkAutoLockPixels alp(outBitmap); diff --git a/tests/LayerDrawLooperTest.cpp b/tests/LayerDrawLooperTest.cpp index daadc86..8b1aa0d 100644 --- a/tests/LayerDrawLooperTest.cpp +++ b/tests/LayerDrawLooperTest.cpp @@ -6,9 +6,9 @@ */ #include "Test.h" #include "SkBitmap.h" +#include "SkBitmapDevice.h" #include "SkCanvas.h" #include "SkDraw.h" -#include "SkDevice.h" #include "SkLayerDrawLooper.h" #include "SkMatrix.h" #include "SkPaint.h" @@ -19,17 +19,20 @@ namespace { -class FakeDevice : public SkDevice { +class FakeDevice : public SkBitmapDevice { public: - FakeDevice() : SkDevice(SkBitmap::kARGB_8888_Config, 100, 100) { } + FakeDevice() : SkBitmapDevice(SkBitmap::kARGB_8888_Config, 100, 100, false) { } virtual void drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& paint) SK_OVERRIDE { fLastMatrix = *draw.fMatrix; - SkDevice::drawRect(draw, r, paint); + INHERITED::drawRect(draw, r, paint); } SkMatrix fLastMatrix; + +private: + typedef SkBitmapDevice INHERITED; }; } // namespace diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp index f823806..349560b 100644 --- a/tests/PictureTest.cpp +++ b/tests/PictureTest.cpp @@ -5,19 +5,19 @@ * found in the LICENSE file. */ #include "Test.h" +#include "SkBitmapDevice.h" #include "SkCanvas.h" #include "SkColorPriv.h" #include "SkData.h" -#include "SkDevice.h" #include "SkError.h" #include "SkPaint.h" #include "SkPicture.h" +#include "SkPictureUtils.h" #include "SkRandom.h" #include "SkRRect.h" #include "SkShader.h" #include "SkStream.h" -#include "SkPictureUtils.h" static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) { bm->setConfig(SkBitmap::kARGB_8888_Config, w, h); @@ -556,7 +556,7 @@ static void test_clip_bound_opt(skiatest::Reporter* reporter) { */ class ClipCountingCanvas : public SkCanvas { public: - explicit ClipCountingCanvas(SkDevice* device) + explicit ClipCountingCanvas(SkBaseDevice* device) : SkCanvas(device) , fClipCount(0){ } @@ -599,7 +599,7 @@ static void test_clip_expansion(skiatest::Reporter* reporter) { p.setColor(SK_ColorBLUE); canvas->drawPaint(p); - SkDevice testDevice(SkBitmap::kNo_Config, 10, 10); + SkBitmapDevice testDevice(SkBitmap::kNo_Config, 10, 10); ClipCountingCanvas testCanvas(&testDevice); picture.draw(&testCanvas); diff --git a/tests/PremulAlphaRoundTripTest.cpp b/tests/PremulAlphaRoundTripTest.cpp index 28150d6..79b32f9 100644 --- a/tests/PremulAlphaRoundTripTest.cpp +++ b/tests/PremulAlphaRoundTripTest.cpp @@ -41,7 +41,7 @@ static const SkCanvas::Config8888 gUnpremulConfigs[] = { }; void PremulAlphaRoundTripTest(skiatest::Reporter* reporter, GrContextFactory* factory) { - SkAutoTUnref device; + SkAutoTUnref device; for (int dtype = 0; dtype < 2; ++dtype) { int glCtxTypeCnt = 1; @@ -52,10 +52,10 @@ void PremulAlphaRoundTripTest(skiatest::Reporter* reporter, GrContextFactory* fa #endif for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) { if (0 == dtype) { - device.reset(new SkDevice(SkBitmap::kARGB_8888_Config, - 256, - 256, - false)); + device.reset(new SkBitmapDevice(SkBitmap::kARGB_8888_Config, + 256, + 256, + false)); } else { #if SK_SUPPORT_GPU GrContextFactory::GLContextType type = diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp index 24f5954..9cc1074 100644 --- a/tests/ReadPixelsTest.cpp +++ b/tests/ReadPixelsTest.cpp @@ -311,9 +311,10 @@ void ReadPixelsTest(skiatest::Reporter* reporter, GrContextFactory* factory) { } #endif for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) { - SkAutoTUnref device; + SkAutoTUnref device; if (0 == dtype) { - device.reset(new SkDevice(SkBitmap::kARGB_8888_Config, DEV_W, DEV_H, false)); + device.reset(new SkBitmapDevice(SkBitmap::kARGB_8888_Config, + DEV_W, DEV_H, false)); } else { #if SK_SUPPORT_GPU GrContextFactory::GLContextType type = diff --git a/tests/ReadWriteAlphaTest.cpp b/tests/ReadWriteAlphaTest.cpp index 7830669..8ae936e 100644 --- a/tests/ReadWriteAlphaTest.cpp +++ b/tests/ReadWriteAlphaTest.cpp @@ -82,7 +82,7 @@ static void ReadWriteAlphaTest(skiatest::Reporter* reporter, GrContextFactory* f REPORTER_ASSERT(reporter, match); // Now try writing on the single channel texture - SkAutoTUnref device(new SkGpuDevice(context, texture->asRenderTarget())); + SkAutoTUnref device(new SkGpuDevice(context, texture->asRenderTarget())); SkCanvas canvas(device); SkPaint paint; diff --git a/tests/TileGridTest.cpp b/tests/TileGridTest.cpp index f4a0af8..ae20cdd 100644 --- a/tests/TileGridTest.cpp +++ b/tests/TileGridTest.cpp @@ -7,10 +7,10 @@ */ #include "Test.h" +#include "SkBitmapDevice.h" +#include "SkCanvas.h" #include "SkTileGrid.h" #include "SkTileGridPicture.h" -#include "SkCanvas.h" -#include "SkDevice.h" enum Tile { kTopLeft_Tile = 0x1, @@ -24,7 +24,7 @@ enum Tile { namespace { class MockCanvas : public SkCanvas { public: - MockCanvas(SkDevice* device) : SkCanvas(device) + MockCanvas(SkBaseDevice* device) : SkCanvas(device) {} virtual void drawRect(const SkRect& rect, const SkPaint&) @@ -80,14 +80,14 @@ public: // Test parts of top-left tile { - SkDevice device(store); + SkBitmapDevice device(store); MockCanvas mockCanvas(&device); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); } { - SkDevice device(store); + SkBitmapDevice device(store); MockCanvas mockCanvas(&device); mockCanvas.translate(SkFloatToScalar(-7.99f), SkFloatToScalar(-7.99f)); picture.draw(&mockCanvas); @@ -96,7 +96,7 @@ public: } // Corner overlap { - SkDevice device(store); + SkBitmapDevice device(store); MockCanvas mockCanvas(&device); mockCanvas.translate(SkFloatToScalar(-9.5f), SkFloatToScalar(-9.5f)); picture.draw(&mockCanvas); @@ -106,7 +106,7 @@ public: } // Intersect bottom right tile, but does not overlap rect 2 { - SkDevice device(store); + SkBitmapDevice device(store); MockCanvas mockCanvas(&device); mockCanvas.translate(SkFloatToScalar(-16.0f), SkFloatToScalar(-16.0f)); picture.draw(&mockCanvas); @@ -115,7 +115,7 @@ public: } // Out of bounds queries, snap to border tiles { - SkDevice device(store); + SkBitmapDevice device(store); MockCanvas mockCanvas(&device); mockCanvas.translate(SkFloatToScalar(2.0f), SkFloatToScalar(0.0f)); picture.draw(&mockCanvas); @@ -123,7 +123,7 @@ public: REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); } { - SkDevice device(store); + SkBitmapDevice device(store); MockCanvas mockCanvas(&device); mockCanvas.translate(SkFloatToScalar(0.0f), SkFloatToScalar(2.0f)); picture.draw(&mockCanvas); @@ -131,7 +131,7 @@ public: REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); } { - SkDevice device(store); + SkBitmapDevice device(store); MockCanvas mockCanvas(&device); mockCanvas.translate(SkFloatToScalar(-22.0f), SkFloatToScalar(-16.0f)); picture.draw(&mockCanvas); @@ -139,7 +139,7 @@ public: REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); } { - SkDevice device(store); + SkBitmapDevice device(store); MockCanvas mockCanvas(&device); mockCanvas.translate(SkFloatToScalar(-16.0f), SkFloatToScalar(-22.0f)); picture.draw(&mockCanvas); @@ -185,7 +185,7 @@ public: { // The offset should cancel the top and left borders of the top left tile // So a look-up at interval 0-10 should be grid aligned, - SkDevice device(tileBitmap); + SkBitmapDevice device(tileBitmap); MockCanvas mockCanvas(&device); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); @@ -193,7 +193,7 @@ public: } { // Encroaching border by one pixel - SkDevice device(moreThanATileBitmap); + SkBitmapDevice device(moreThanATileBitmap); MockCanvas mockCanvas(&device); picture.draw(&mockCanvas); REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); @@ -204,7 +204,7 @@ public: // Tile stride is 8 (tileWidth - 2 * border pixels // so translating by 8, should make query grid-aligned // with middle tile. - SkDevice device(tileBitmap); + SkBitmapDevice device(tileBitmap); MockCanvas mockCanvas(&device); mockCanvas.translate(SkIntToScalar(-8), SkIntToScalar(-8)); picture.draw(&mockCanvas); @@ -212,7 +212,7 @@ public: REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); } { - SkDevice device(tileBitmap); + SkBitmapDevice device(tileBitmap); MockCanvas mockCanvas(&device); mockCanvas.translate(SkFloatToScalar(-7.9f), SkFloatToScalar(-7.9f)); picture.draw(&mockCanvas); @@ -221,7 +221,7 @@ public: REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[1]); } { - SkDevice device(tileBitmap); + SkBitmapDevice device(tileBitmap); MockCanvas mockCanvas(&device); mockCanvas.translate(SkFloatToScalar(-8.1f), SkFloatToScalar(-8.1f)); picture.draw(&mockCanvas); @@ -233,7 +233,7 @@ public: // Regression test for crbug.com/234688 // Once the 2x2 device region is inset by margin, it yields an empty // adjusted region, sitting right on top of the tile boundary. - SkDevice device(tinyBitmap); + SkBitmapDevice device(tinyBitmap); MockCanvas mockCanvas(&device); mockCanvas.translate(SkFloatToScalar(-8.0f), SkFloatToScalar(-8.0f)); picture.draw(&mockCanvas); diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp index 202bfd6..3db3a2a 100644 --- a/tests/WritePixelsTest.cpp +++ b/tests/WritePixelsTest.cpp @@ -227,7 +227,7 @@ bool checkWrite(skiatest::Reporter* reporter, const SkBitmap& bitmap, int writeX, int writeY, SkCanvas::Config8888 config8888) { - SkDevice* dev = canvas->getDevice(); + SkBaseDevice* dev = canvas->getDevice(); if (!dev) { return false; } @@ -305,7 +305,7 @@ static const CanvasConfig gCanvasConfigs[] = { #endif }; -SkDevice* createDevice(const CanvasConfig& c, GrContext* grCtx) { +SkBaseDevice* createDevice(const CanvasConfig& c, GrContext* grCtx) { switch (c.fDevType) { case kRaster_DevType: { SkBitmap bmp; @@ -320,7 +320,7 @@ SkDevice* createDevice(const CanvasConfig& c, GrContext* grCtx) { SkAutoLockPixels alp(bmp); memset(bmp.getPixels(), DEV_PAD, bmp.getSafeSize()); } - return new SkDevice(bmp); + return new SkBitmapDevice(bmp); } #if SK_SUPPORT_GPU case kGpu_BottomLeft_DevType: @@ -435,7 +435,7 @@ void WritePixelsTest(skiatest::Reporter* reporter, GrContextFactory* factory) { } #endif - SkAutoTUnref device(createDevice(gCanvasConfigs[i], context)); + SkAutoTUnref device(createDevice(gCanvasConfigs[i], context)); SkCanvas canvas(device); static const SkCanvas::Config8888 gSrcConfigs[] = {