diff options
26 files changed, 138 insertions, 158 deletions
diff --git a/experimental/PdfViewer/SkTrackDevice.h b/experimental/PdfViewer/SkTrackDevice.h index 9280b7f247..e3e78e3097 100644 --- a/experimental/PdfViewer/SkTrackDevice.h +++ b/experimental/PdfViewer/SkTrackDevice.h @@ -13,7 +13,7 @@ /** \class SkTrackDevice * - * A Track Device is used to track that callstack of an operation that affected some pixels. + * A Track Device is used to track the callstack of an operation that affected some pixels. * It can be used with SampleApp to investigate bugs (CL not checked in yet). * * every drawFoo is implemented as such: @@ -22,12 +22,15 @@ * after(); // - checks if pixels of interest, and issue a breakpoint. * */ +// TODO: can this be derived from SkBaseDevice instead? class SkTrackDevice : public SkBitmapDevice { public: SK_DECLARE_INST_COUNT(SkTrackDevice) - SkTrackDevice(const SkBitmap& bitmap) : SkBitmapDevice(bitmap) - , fTracker(NULL) {} + SkTrackDevice(const SkBitmap& bitmap) + : INHERITED(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)) + , fTracker(NULL) { + } virtual ~SkTrackDevice() {} diff --git a/experimental/PdfViewer/pdf_viewer_main.cpp b/experimental/PdfViewer/pdf_viewer_main.cpp index f5bfdbbd7e..94735ac49a 100644 --- a/experimental/PdfViewer/pdf_viewer_main.cpp +++ b/experimental/PdfViewer/pdf_viewer_main.cpp @@ -5,7 +5,6 @@ * found in the LICENSE file. */ -#include "SkBitmapDevice.h" #include "SkCanvas.h" #include "SkCommandLineFlags.h" #include "SkDevice.h" @@ -121,8 +120,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<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap))); - SkNulCanvas canvas(device); + SkNulCanvas canvas(bitmap); renderer.renderPage(page < 0 ? 0 : page, &canvas, rect); } else { // 8888 @@ -143,14 +141,11 @@ static bool render_page(const SkString& outputDir, setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDouble(height), background); #endif - SkAutoTUnref<SkBaseDevice> device; - if (strcmp(FLAGS_config[0], "8888") == 0) { - device.reset(SkNEW_ARGS(SkBitmapDevice, (bitmap))); - } else { + if (strcmp(FLAGS_config[0], "8888") != 0) { SkDebugf("unknown --config: %s\n", FLAGS_config[0]); return false; } - SkCanvas canvas(device); + SkCanvas canvas(bitmap); #ifdef PDF_TRACE_DIFF_IN_PNG gDumpBitmap = &bitmap; diff --git a/experimental/PdfViewer/src/SkPdfRenderer.cpp b/experimental/PdfViewer/src/SkPdfRenderer.cpp index 6a9fd74aba..b77a43ee3c 100644 --- a/experimental/PdfViewer/src/SkPdfRenderer.cpp +++ b/experimental/PdfViewer/src/SkPdfRenderer.cpp @@ -7,7 +7,6 @@ #include "SkPdfRenderer.h" -#include "SkBitmapDevice.h" #include "SkCanvas.h" #include "SkColorPriv.h" #include "SkDevice.h" @@ -2910,8 +2909,7 @@ bool SkPDFNativeRenderToBitmap(SkStream* stream, setup_bitmap(output, SkScalarCeilToInt(width), SkScalarCeilToInt(height)); - SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (*output))); - SkCanvas canvas(device); + SkCanvas canvas(*output); return renderer->renderPage(page, &canvas, rect); } diff --git a/gm/resizeimagefilter.cpp b/gm/resizeimagefilter.cpp index 2edb802838..4a6da53c97 100644 --- a/gm/resizeimagefilter.cpp +++ b/gm/resizeimagefilter.cpp @@ -6,7 +6,6 @@ */ #include "gm.h" -#include "SkBitmapDevice.h" #include "SkBitmapSource.h" #include "SkColor.h" #include "SkRefCnt.h" @@ -91,8 +90,7 @@ protected: bitmap.allocN32Pixels(16, 16); bitmap.eraseARGB(0x00, 0x00, 0x00, 0x00); { - SkBitmapDevice bitmapDevice(bitmap); - SkCanvas bitmapCanvas(&bitmapDevice); + SkCanvas bitmapCanvas(bitmap); SkPaint paint; paint.setColor(0xFF00FF00); SkRect ovalRect = SkRect::MakeWH(16, 16); diff --git a/include/core/SkBitmapDevice.h b/include/core/SkBitmapDevice.h index 3ce06b0cc3..7e2b476611 100644 --- a/include/core/SkBitmapDevice.h +++ b/include/core/SkBitmapDevice.h @@ -20,21 +20,24 @@ public: * 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); -protected: + + /** + * Create a new device along with its requisite pixel memory using + * default SkSurfaceProps (i.e., kLegacyFontHost_InitType-style). + * Note: this entry point is slated for removal - no one should call it. + */ + static SkBitmapDevice* Create(const SkImageInfo& info); + /** * 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 SkSurfaceProps& surfaceProps); -private: - static SkBitmapDevice* Create(const SkImageInfo&, const SkSurfaceProps*); -public: - static SkBitmapDevice* Create(const SkImageInfo& info) { - return Create(info, NULL); - } + + static SkBitmapDevice* Create(const SkImageInfo&, const SkSurfaceProps&); SkImageInfo imageInfo() const override; diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index bcbf47a810..7217e2fa65 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -31,7 +31,6 @@ public: /** * Construct a new device. */ - SkBaseDevice(); explicit SkBaseDevice(const SkSurfaceProps&); virtual ~SkBaseDevice(); diff --git a/include/utils/SkDeferredCanvas.h b/include/utils/SkDeferredCanvas.h index a8330493a7..413f03e7c8 100644 --- a/include/utils/SkDeferredCanvas.h +++ b/include/utils/SkDeferredCanvas.h @@ -33,8 +33,6 @@ public: */ static SkDeferredCanvas* Create(SkSurface* surface); -// static SkDeferredCanvas* Create(SkBaseDevice* device); - virtual ~SkDeferredCanvas(); /** diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index 34bd5b7cec..b94daef41e 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -58,19 +58,24 @@ static bool valid_for_bitmap_device(const SkImageInfo& info, return true; } -SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) : fBitmap(bitmap) { +SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) + : INHERITED(SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)) + , fBitmap(bitmap) { SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); } +SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) { + return Create(info, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)); +} + SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps) - : SkBaseDevice(surfaceProps) - , fBitmap(bitmap) -{ + : INHERITED(surfaceProps) + , fBitmap(bitmap) { SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); } SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, - const SkSurfaceProps* surfaceProps) { + const SkSurfaceProps& surfaceProps) { SkAlphaType newAT = origInfo.alphaType(); if (!valid_for_bitmap_device(origInfo, &newAT)) { return NULL; @@ -92,11 +97,7 @@ SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, } } - if (surfaceProps) { - return SkNEW_ARGS(SkBitmapDevice, (bitmap, *surfaceProps)); - } else { - return SkNEW_ARGS(SkBitmapDevice, (bitmap)); - } + return SkNEW_ARGS(SkBitmapDevice, (bitmap, surfaceProps)); } SkImageInfo SkBitmapDevice::imageInfo() const { @@ -116,8 +117,8 @@ void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { } SkBaseDevice* SkBitmapDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint*) { - const SkSurfaceProps surfaceProps(0, cinfo.fPixelGeometry); - return SkBitmapDevice::Create(cinfo.fInfo, &surfaceProps); + const SkSurfaceProps surfaceProps(this->surfaceProps().flags(), cinfo.fPixelGeometry); + return SkBitmapDevice::Create(cinfo.fInfo, surfaceProps); } const SkBitmap& SkBitmapDevice::onAccessBitmap() { diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 6169492a76..f35727d6f6 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -1049,8 +1049,8 @@ void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav SkBaseDevice* newDev = device->onCreateDevice(createInfo, paint); if (NULL == newDev) { // If onCreateDevice didn't succeed, try raster (e.g. PDF couldn't handle the paint) - const SkSurfaceProps surfaceProps(0, createInfo.fPixelGeometry); - newDev = SkBitmapDevice::Create(createInfo.fInfo, &surfaceProps); + const SkSurfaceProps surfaceProps(fProps.flags(), createInfo.fPixelGeometry); + newDev = SkBitmapDevice::Create(createInfo.fInfo, surfaceProps); if (NULL == newDev) { SkErrorInternals::SetError(kInternalError_SkError, "Unable to create device for layer."); diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 5c4f2f0bf5..4e9d4a21e8 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -17,16 +17,6 @@ #include "SkTextBlob.h" #include "SkTextToPathIter.h" -SkBaseDevice::SkBaseDevice() - : fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType) -#ifdef SK_DEBUG - , fAttachedToCanvas(false) -#endif -{ - fOrigin.setZero(); - fMetaData = NULL; -} - SkBaseDevice::SkBaseDevice(const SkSurfaceProps& surfaceProps) : fSurfaceProps(surfaceProps) #ifdef SK_DEBUG diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index f5122040e9..7233ec6706 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -8,6 +8,7 @@ #include "SkImageFilter.h" #include "SkBitmap.h" +#include "SkBitmapDevice.h" #include "SkChecksum.h" #include "SkDevice.h" #include "SkLazyPtr.h" @@ -526,8 +527,6 @@ void SkImageFilter::PurgeCache() { /////////////////////////////////////////////////////////////////////////////////////////////////// -#include "SkBitmapDevice.h" - SkBaseDevice* SkImageFilter::Proxy::createDevice(int w, int h) { SkBaseDevice::CreateInfo cinfo(SkImageInfo::MakeN32Premul(w, h), SkBaseDevice::kNever_TileUsage, @@ -535,7 +534,9 @@ SkBaseDevice* SkImageFilter::Proxy::createDevice(int w, int h) { true /*forImageFilter*/); SkBaseDevice* dev = fDevice->onCreateDevice(cinfo, NULL); if (NULL == dev) { - dev = SkBitmapDevice::Create(cinfo.fInfo); + const SkSurfaceProps surfaceProps(fDevice->fSurfaceProps.flags(), + kUnknown_SkPixelGeometry); + dev = SkBitmapDevice::Create(cinfo.fInfo, surfaceProps); } return dev; } diff --git a/src/device/xps/SkXPSDevice.cpp b/src/device/xps/SkXPSDevice.cpp index 1c06235aef..d1525479c4 100644 --- a/src/device/xps/SkXPSDevice.cpp +++ b/src/device/xps/SkXPSDevice.cpp @@ -112,10 +112,25 @@ static SkBitmap make_fake_bitmap(int width, int height) { // TODO: should inherit from SkBaseDevice instead of SkBitmapDevice... SkXPSDevice::SkXPSDevice() - : SkBitmapDevice(make_fake_bitmap(10000, 10000)) + : INHERITED(make_fake_bitmap(10000, 10000), SkSurfaceProps(0, kUnknown_SkPixelGeometry)) , fCurrentPage(0) { } +SkXPSDevice::SkXPSDevice(IXpsOMObjectFactory* xpsFactory) + : INHERITED(make_fake_bitmap(10000, 10000), SkSurfaceProps(0, kUnknown_SkPixelGeometry)) + , fCurrentPage(0) { + + HRVM(CoCreateInstance( + CLSID_XpsOMObjectFactory, + NULL, + CLSCTX_INPROC_SERVER, + IID_PPV_ARGS(&this->fXpsFactory)), + "Could not create factory for layer."); + + HRVM(this->fXpsFactory->CreateCanvas(&this->fCurrentXpsCanvas), + "Could not create canvas for layer."); +} + SkXPSDevice::~SkXPSDevice() { } @@ -2259,18 +2274,3 @@ SkBaseDevice* SkXPSDevice::onCreateDevice(const CreateInfo& info, const SkPaint* return new SkXPSDevice(this->fXpsFactory.get()); } -SkXPSDevice::SkXPSDevice(IXpsOMObjectFactory* xpsFactory) - : SkBitmapDevice(make_fake_bitmap(10000, 10000)) - , fCurrentPage(0) { - - HRVM(CoCreateInstance( - CLSID_XpsOMObjectFactory, - NULL, - CLSCTX_INPROC_SERVER, - IID_PPV_ARGS(&this->fXpsFactory)), - "Could not create factory for layer."); - - HRVM(this->fXpsFactory->CreateCanvas(&this->fCurrentXpsCanvas), - "Could not create canvas for layer."); -} - diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 7062e66752..c1c77e2031 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -708,7 +708,8 @@ SkPDFDevice::SkPDFDevice(SkISize pageSize, SkScalar rasterDpi, SkPDFCanon* canon, bool flip) - : fPageSize(pageSize) + : INHERITED(SkSurfaceProps(0, kUnknown_SkPixelGeometry)) + , fPageSize(pageSize) , fContentSize(pageSize) , fExistingClipRegion(SkIRect::MakeSize(pageSize)) , fAnnotations(NULL) diff --git a/src/pipe/SkGPipeWrite.cpp b/src/pipe/SkGPipeWrite.cpp index 9fd81b05eb..2c11c41444 100644 --- a/src/pipe/SkGPipeWrite.cpp +++ b/src/pipe/SkGPipeWrite.cpp @@ -7,7 +7,6 @@ */ #include "SkAnnotation.h" -#include "SkBitmapDevice.h" #include "SkBitmapHeap.h" #include "SkCanvas.h" #include "SkColorFilter.h" diff --git a/src/pipe/utils/SamplePipeControllers.cpp b/src/pipe/utils/SamplePipeControllers.cpp index ea2c39cff0..b85ceb6790 100644 --- a/src/pipe/utils/SamplePipeControllers.cpp +++ b/src/pipe/utils/SamplePipeControllers.cpp @@ -7,7 +7,6 @@ #include "SamplePipeControllers.h" -#include "SkBitmapDevice.h" #include "SkCanvas.h" #include "SkGPipe.h" #include "SkMatrix.h" @@ -55,9 +54,7 @@ TiledPipeController::TiledPipeController(const SkBitmap& bitmap, SkDEBUGCODE(bool extracted = )bitmap.extractSubset(&fBitmaps[i], rect); SkASSERT(extracted); - SkBaseDevice* device = new SkBitmapDevice(fBitmaps[i]); - SkCanvas* canvas = new SkCanvas(device); - device->unref(); + SkCanvas* canvas = new SkCanvas(fBitmaps[i]); if (initial != NULL) { canvas->setMatrix(*initial); } diff --git a/src/svg/SkSVGDevice.cpp b/src/svg/SkSVGDevice.cpp index 480dd92b38..6038353c9c 100644 --- a/src/svg/SkSVGDevice.cpp +++ b/src/svg/SkSVGDevice.cpp @@ -569,7 +569,8 @@ SkBaseDevice* SkSVGDevice::Create(const SkISize& size, SkXMLWriter* writer) { } SkSVGDevice::SkSVGDevice(const SkISize& size, SkXMLWriter* writer) - : fWriter(writer) + : INHERITED(SkSurfaceProps(0, kUnknown_SkPixelGeometry)) + , fWriter(writer) , fResourceBucket(SkNEW(ResourceBucket)) { SkASSERT(writer); diff --git a/src/svg/SkSVGDevice.h b/src/svg/SkSVGDevice.h index 249cd65f9d..e3691a957f 100644 --- a/src/svg/SkSVGDevice.h +++ b/src/svg/SkSVGDevice.h @@ -70,6 +70,8 @@ private: SkAutoTDelete<AutoElement> fRootElement; SkAutoTDelete<ResourceBucket> fResourceBucket; SkBitmap fLegacyBitmap; + + typedef SkBaseDevice INHERITED; }; #endif // SkSVGDevice_DEFINED diff --git a/src/utils/SkCanvasStateUtils.cpp b/src/utils/SkCanvasStateUtils.cpp index 759ba92fc8..12ceefcf2f 100644 --- a/src/utils/SkCanvasStateUtils.cpp +++ b/src/utils/SkCanvasStateUtils.cpp @@ -7,9 +7,9 @@ #include "SkCanvasStateUtils.h" -#include "SkBitmapDevice.h" #include "SkCanvas.h" #include "SkCanvasStack.h" +#include "SkDevice.h" #include "SkErrorInternals.h" #include "SkWriter32.h" diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp index 4c9b270adb..dd22cf951f 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 "SkImage_Base.h" @@ -283,9 +283,12 @@ private: bool fIsDrawingToLayer; size_t fMaxRecordingStorageBytes; size_t fPreviousStorageAllocated; + + typedef SkBaseDevice INHERITED; }; -SkDeferredDevice::SkDeferredDevice(SkSurface* surface) { +SkDeferredDevice::SkDeferredDevice(SkSurface* surface) + : INHERITED(surface->props()) { fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; fNotificationClient = NULL; fImmediateCanvas = NULL; @@ -537,6 +540,10 @@ private: }; SkDeferredCanvas* SkDeferredCanvas::Create(SkSurface* surface) { + if (!surface) { + return NULL; + } + SkAutoTUnref<SkDeferredDevice> deferredDevice(SkNEW_ARGS(SkDeferredDevice, (surface))); return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice)); } diff --git a/tests/DeferredCanvasTest.cpp b/tests/DeferredCanvasTest.cpp index 60d7d0a038..fff213b607 100644 --- a/tests/DeferredCanvasTest.cpp +++ b/tests/DeferredCanvasTest.cpp @@ -8,7 +8,6 @@ #include "../src/image/SkImagePriv.h" #include "../src/image/SkSurface_Base.h" #include "SkBitmap.h" -#include "SkBitmapDevice.h" #include "SkBitmapProcShader.h" #include "SkDeferredCanvas.h" #include "SkGradientShader.h" @@ -440,19 +439,6 @@ static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) { } } -class MockDevice : public SkBitmapDevice { -public: - MockDevice(const SkBitmap& bm) : SkBitmapDevice(bm) { - fDrawBitmapCallCount = 0; - } - virtual void drawBitmap(const SkDraw&, const SkBitmap&, - const SkMatrix&, const SkPaint&) override { - fDrawBitmapCallCount++; - } - - int fDrawBitmapCallCount; -}; - class NotificationCounter : public SkDeferredCanvas::NotificationClient { public: NotificationCounter() { diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index 20bf0aa6d3..63e3aaa6f0 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -264,14 +264,13 @@ DEF_TEST(ImageFilter, reporter) { } } -static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter) { +static void test_crop_rects(SkImageFilter::Proxy* proxy, skiatest::Reporter* reporter) { // Check that all filters offset to their absolute crop rect, // unaffected by the input crop rect. // Tests pass by not asserting. SkBitmap bitmap; bitmap.allocN32Pixels(100, 100); bitmap.eraseARGB(0, 0, 0, 0); - SkImageFilter::Proxy proxy(device, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)); SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80)); SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60)); @@ -316,7 +315,7 @@ static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter) SkString str; str.printf("filter %d", static_cast<int>(i)); SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL); - REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(&proxy, bitmap, ctx, + REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(proxy, bitmap, ctx, &result, &offset), str.c_str()); REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, str.c_str()); } @@ -347,11 +346,10 @@ static SkBitmap make_gradient_circle(int width, int height) { return bitmap; } -static void test_negative_blur_sigma(SkBaseDevice* device, skiatest::Reporter* reporter) { +static void test_negative_blur_sigma(SkImageFilter::Proxy* proxy, skiatest::Reporter* reporter) { // Check that SkBlurImageFilter will accept a negative sigma, either in // the given arguments or after CTM application. int width = 32, height = 32; - SkImageFilter::Proxy proxy(device, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)); SkScalar five = SkIntToScalar(5); SkAutoTUnref<SkBlurImageFilter> positiveFilter( @@ -367,13 +365,13 @@ static void test_negative_blur_sigma(SkBaseDevice* device, skiatest::Reporter* r SkBitmap positiveResult2, negativeResult2; SkIPoint offset; SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL); - positiveFilter->filterImage(&proxy, gradient, ctx, &positiveResult1, &offset); - negativeFilter->filterImage(&proxy, gradient, ctx, &negativeResult1, &offset); + positiveFilter->filterImage(proxy, gradient, ctx, &positiveResult1, &offset); + negativeFilter->filterImage(proxy, gradient, ctx, &negativeResult1, &offset); SkMatrix negativeScale; negativeScale.setScale(-SK_Scalar1, SK_Scalar1); SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeLargest(), NULL); - positiveFilter->filterImage(&proxy, gradient, negativeCTX, &negativeResult2, &offset); - negativeFilter->filterImage(&proxy, gradient, negativeCTX, &positiveResult2, &offset); + positiveFilter->filterImage(proxy, gradient, negativeCTX, &negativeResult2, &offset); + negativeFilter->filterImage(proxy, gradient, negativeCTX, &positiveResult2, &offset); SkAutoLockPixels lockP1(positiveResult1); SkAutoLockPixels lockP2(positiveResult2); SkAutoLockPixels lockN1(negativeResult1); @@ -398,10 +396,13 @@ static void test_negative_blur_sigma(SkBaseDevice* device, skiatest::Reporter* r } DEF_TEST(TestNegativeBlurSigma, reporter) { - SkBitmap temp; - temp.allocN32Pixels(100, 100); - SkBitmapDevice device(temp); - test_negative_blur_sigma(&device, reporter); + const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); + const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); + + SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props)); + SkImageFilter::Proxy proxy(device, props); + + test_negative_blur_sigma(&proxy, reporter); } DEF_TEST(ImageFilterDrawTiled, reporter) { @@ -768,17 +769,19 @@ DEF_TEST(ImageFilterMatrixConvolutionBorder, reporter) { } DEF_TEST(ImageFilterCropRect, reporter) { - SkBitmap temp; - temp.allocN32Pixels(100, 100); - SkBitmapDevice device(temp); - test_crop_rects(&device, reporter); + const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); + const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); + + SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props)); + SkImageFilter::Proxy proxy(device, props); + + test_crop_rects(&proxy, reporter); } DEF_TEST(ImageFilterMatrix, reporter) { SkBitmap temp; temp.allocN32Pixels(100, 100); - SkBitmapDevice device(temp); - SkCanvas canvas(&device); + SkCanvas canvas(temp); canvas.scale(SkIntToScalar(2), SkIntToScalar(2)); SkMatrix expectedMatrix = canvas.getTotalMatrix(); @@ -833,8 +836,7 @@ DEF_TEST(ImageFilterCrossProcessPictureImageFilter, reporter) { SkBitmap bitmap; bitmap.allocN32Pixels(1, 1); - SkBitmapDevice device(bitmap); - SkCanvas canvas(&device); + SkCanvas canvas(bitmap); // The result here should be green, since the filter replaces the primitive's red interior. canvas.clear(0x0); @@ -876,15 +878,14 @@ DEF_TEST(ImageFilterClippedPictureImageFilter, reporter) { recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint); SkAutoTUnref<SkPicture> picture(recorder.endRecording()); - SkAutoTUnref<SkImageFilter> imageFilter( - SkPictureImageFilter::Create(picture.get())); + SkAutoTUnref<SkImageFilter> imageFilter(SkPictureImageFilter::Create(picture.get())); SkBitmap result; SkIPoint offset; SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), NULL); SkBitmap bitmap; bitmap.allocN32Pixels(2, 2); - SkBitmapDevice device(bitmap); + SkBitmapDevice device(bitmap, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)); SkImageFilter::Proxy proxy(&device, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)); REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, bitmap, ctx, &result, &offset)); } @@ -895,8 +896,7 @@ DEF_TEST(ImageFilterEmptySaveLayer, reporter) { SkBitmap bitmap; bitmap.allocN32Pixels(10, 10); - SkBitmapDevice device(bitmap); - SkCanvas canvas(&device); + SkCanvas canvas(bitmap); SkRTreeFactory factory; SkPictureRecorder recorder; @@ -943,9 +943,7 @@ DEF_TEST(ImageFilterEmptySaveLayer, reporter) { REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); } -static void test_huge_blur(SkBaseDevice* device, skiatest::Reporter* reporter) { - SkCanvas canvas(device); - +static void test_huge_blur(SkCanvas* canvas, skiatest::Reporter* reporter) { SkBitmap bitmap; bitmap.allocN32Pixels(100, 100); bitmap.eraseARGB(0, 0, 0, 0); @@ -955,14 +953,14 @@ static void test_huge_blur(SkBaseDevice* device, skiatest::Reporter* reporter) { SkPaint paint; paint.setImageFilter(blur); - canvas.drawSprite(bitmap, 0, 0, &paint); + canvas->drawSprite(bitmap, 0, 0, &paint); } DEF_TEST(HugeBlurImageFilter, reporter) { SkBitmap temp; temp.allocN32Pixels(100, 100); - SkBitmapDevice device(temp); - test_huge_blur(&device, reporter); + SkCanvas canvas(temp); + test_huge_blur(&canvas, reporter); } DEF_TEST(MatrixConvolutionSanityTest, reporter) { @@ -1019,9 +1017,8 @@ DEF_TEST(MatrixConvolutionSanityTest, reporter) { REPORTER_ASSERT(reporter, NULL == conv.get()); } -static void test_xfermode_cropped_input(SkBaseDevice* device, skiatest::Reporter* reporter) { - SkCanvas canvas(device); - canvas.clear(0); +static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* reporter) { + canvas->clear(0); SkBitmap bitmap; bitmap.allocN32Pixels(1, 1); @@ -1047,29 +1044,28 @@ static void test_xfermode_cropped_input(SkBaseDevice* device, skiatest::Reporter SkPaint paint; paint.setImageFilter(xfermodeNoFg); - canvas.drawSprite(bitmap, 0, 0, &paint); + canvas->drawSprite(bitmap, 0, 0, &paint); uint32_t pixel; SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul_SkAlphaType); - canvas.readPixels(info, &pixel, 4, 0, 0); + canvas->readPixels(info, &pixel, 4, 0, 0); REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); paint.setImageFilter(xfermodeNoBg); - canvas.drawSprite(bitmap, 0, 0, &paint); - canvas.readPixels(info, &pixel, 4, 0, 0); + canvas->drawSprite(bitmap, 0, 0, &paint); + canvas->readPixels(info, &pixel, 4, 0, 0); REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); paint.setImageFilter(xfermodeNoFgNoBg); - canvas.drawSprite(bitmap, 0, 0, &paint); - canvas.readPixels(info, &pixel, 4, 0, 0); + canvas->drawSprite(bitmap, 0, 0, &paint); + canvas->readPixels(info, &pixel, 4, 0, 0); REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); } DEF_TEST(ImageFilterNestedSaveLayer, reporter) { SkBitmap temp; temp.allocN32Pixels(50, 50); - SkBitmapDevice device(temp); - SkCanvas canvas(&device); + SkCanvas canvas(temp); canvas.clear(0x0); SkBitmap bitmap; @@ -1119,15 +1115,15 @@ DEF_TEST(ImageFilterNestedSaveLayer, reporter) { DEF_TEST(XfermodeImageFilterCroppedInput, reporter) { SkBitmap temp; temp.allocN32Pixels(100, 100); - SkBitmapDevice device(temp); - test_xfermode_cropped_input(&device, reporter); + SkCanvas canvas(temp); + test_xfermode_cropped_input(&canvas, reporter); } DEF_TEST(ComposedImageFilterOffset, reporter) { SkBitmap bitmap; bitmap.allocN32Pixels(100, 100); bitmap.eraseARGB(0, 0, 0, 0); - SkBitmapDevice device(bitmap); + SkBitmapDevice device(bitmap, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)); SkImageFilter::Proxy proxy(&device, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)); SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); @@ -1154,7 +1150,9 @@ DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { SkImageInfo::MakeN32Premul(100, 100), 0, &gProps)); - test_crop_rects(device, reporter); + SkImageFilter::Proxy proxy(device, gProps); + + test_crop_rects(&proxy, reporter); } DEF_GPUTEST(HugeBlurImageFilterGPU, reporter, factory) { @@ -1167,7 +1165,9 @@ DEF_GPUTEST(HugeBlurImageFilterGPU, reporter, factory) { SkImageInfo::MakeN32Premul(100, 100), 0, &gProps)); - test_huge_blur(device, reporter); + SkCanvas canvas(device); + + test_huge_blur(&canvas, reporter); } DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { @@ -1180,7 +1180,9 @@ DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { SkImageInfo::MakeN32Premul(1, 1), 0, &gProps)); - test_xfermode_cropped_input(device, reporter); + SkCanvas canvas(device); + + test_xfermode_cropped_input(&canvas, reporter); } DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) { @@ -1193,6 +1195,8 @@ DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) { SkImageInfo::MakeN32Premul(1, 1), 0, &gProps)); - test_negative_blur_sigma(device, reporter); + SkImageFilter::Proxy proxy(device, gProps); + + test_negative_blur_sigma(&proxy, reporter); } #endif diff --git a/tests/LayerDrawLooperTest.cpp b/tests/LayerDrawLooperTest.cpp index 2c9b525aa2..391db7ce7f 100644 --- a/tests/LayerDrawLooperTest.cpp +++ b/tests/LayerDrawLooperTest.cpp @@ -25,12 +25,13 @@ static SkBitmap make_bm(int w, int h) { return bm; } +// TODO: can this be derived from SkBaseDevice? class FakeDevice : public SkBitmapDevice { public: - FakeDevice() : SkBitmapDevice(make_bm(100, 100)) { } + FakeDevice() : INHERITED(make_bm(100, 100), SkSurfaceProps(0, kUnknown_SkPixelGeometry)) { + } - virtual void drawRect(const SkDraw& draw, const SkRect& r, - const SkPaint& paint) override { + void drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& paint) override { fLastMatrix = *draw.fMatrix; this->INHERITED::drawRect(draw, r, paint); } diff --git a/tests/PremulAlphaRoundTripTest.cpp b/tests/PremulAlphaRoundTripTest.cpp index 9f5d6ff338..e48885c930 100644 --- a/tests/PremulAlphaRoundTripTest.cpp +++ b/tests/PremulAlphaRoundTripTest.cpp @@ -74,10 +74,11 @@ DEF_GPUTEST(PremulAlphaRoundTrip, reporter, factory) { glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt; } #endif + SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) { SkAutoTUnref<SkBaseDevice> device; if (0 == dtype) { - device.reset(SkBitmapDevice::Create(info)); + device.reset(SkBitmapDevice::Create(info, props)); } else { #if SK_SUPPORT_GPU GrContextFactory::GLContextType type = @@ -89,7 +90,6 @@ DEF_GPUTEST(PremulAlphaRoundTrip, reporter, factory) { if (NULL == ctx) { continue; } - SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); device.reset(SkGpuDevice::Create(ctx, SkSurface::kNo_Budgeted, info, 0, &props)); #else continue; diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp index a45e9ee9cd..59c826fbf0 100644 --- a/tests/ReadPixelsTest.cpp +++ b/tests/ReadPixelsTest.cpp @@ -5,7 +5,6 @@ * found in the LICENSE file. */ -#include "SkBitmapDevice.h" #include "SkCanvas.h" #include "SkColorPriv.h" #include "SkMathPriv.h" diff --git a/tests/SkImageTest.cpp b/tests/SkImageTest.cpp index 3ba63b4258..c058ef062b 100644 --- a/tests/SkImageTest.cpp +++ b/tests/SkImageTest.cpp @@ -5,7 +5,7 @@ * found in the LICENSE file. */ -#include "SkBitmapDevice.h" +#include "SkCanvas.h" #include "SkImagePriv.h" #include "Test.h" @@ -19,8 +19,7 @@ DEF_TEST(SkImageFromBitmap_extractSubset, reporter) { SkBitmap srcBitmap; srcBitmap.allocN32Pixels(gWidth, gHeight); srcBitmap.eraseColor(SK_ColorRED); - SkBitmapDevice dev(srcBitmap); - SkCanvas canvas(&dev); + SkCanvas canvas(srcBitmap); SkIRect r = SkIRect::MakeXYWH(5, 5, gWidth - 5, gWidth - 5); SkPaint p; p.setColor(SK_ColorGREEN); @@ -32,8 +31,7 @@ DEF_TEST(SkImageFromBitmap_extractSubset, reporter) { SkBitmap tgt; tgt.allocN32Pixels(gWidth, gHeight); - SkBitmapDevice dev(tgt); - SkCanvas canvas(&dev); + SkCanvas canvas(tgt); canvas.clear(SK_ColorTRANSPARENT); canvas.drawImage(image, 0, 0, NULL); diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp index d1c328e6ec..fa99d4c9ec 100644 --- a/tests/WritePixelsTest.cpp +++ b/tests/WritePixelsTest.cpp @@ -5,7 +5,6 @@ * found in the LICENSE file. */ -#include "SkBitmapDevice.h" #include "SkCanvas.h" #include "SkColorPriv.h" #include "SkMathPriv.h" |