From b39b09e4477f5c51b27015a17c7ac699028c4d87 Mon Sep 17 00:00:00 2001 From: Hal Canary Date: Wed, 1 Feb 2017 17:04:44 -0500 Subject: SkXPSDevice inherits from SkBaseDevice Change-Id: I81ed36da33821df36d11806a6349a2ede61c6f73 Reviewed-on: https://skia-review.googlesource.com/7942 Reviewed-by: Ben Wagner Commit-Queue: Hal Canary --- src/xps/SkDocument_XPS.cpp | 4 +++- src/xps/SkXPSDevice.cpp | 46 ++++++++++++++++++++++++++++++++++------------ src/xps/SkXPSDevice.h | 46 ++++++++++++++++++++++++++++------------------ 3 files changed, 65 insertions(+), 31 deletions(-) (limited to 'src/xps') diff --git a/src/xps/SkDocument_XPS.cpp b/src/xps/SkDocument_XPS.cpp index d05764a7bf..06fd06710c 100644 --- a/src/xps/SkDocument_XPS.cpp +++ b/src/xps/SkDocument_XPS.cpp @@ -17,7 +17,9 @@ public: SkDocument_XPS(SkWStream* stream, void (*doneProc)(SkWStream*, bool), SkScalar dpi) - : SkDocument(stream, doneProc) { + : SkDocument(stream, doneProc) + , fDevice(SkISize{10000, 10000}) + { const SkScalar kPointsPerMeter = SkDoubleToScalar(360000.0 / 127.0); fUnitsPerMeter.set(kPointsPerMeter, kPointsPerMeter); SkScalar pixelsPerMeterScale = SkDoubleToScalar(dpi * 5000.0 / 127.0); diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp index 37874337e0..aa6ec7cead 100644 --- a/src/xps/SkXPSDevice.cpp +++ b/src/xps/SkXPSDevice.cpp @@ -30,9 +30,10 @@ #include "SkGeometry.h" #include "SkGlyphCache.h" #include "SkHRESULT.h" +#include "SkIStream.h" #include "SkImage.h" #include "SkImageEncoder.h" -#include "SkIStream.h" +#include "SkImagePriv.h" #include "SkMaskFilter.h" #include "SkPaint.h" #include "SkPathEffect.h" @@ -110,20 +111,16 @@ HRESULT SkXPSDevice::createId(wchar_t* buffer, size_t bufferSize, wchar_t sep) { return S_OK; } -static SkBitmap make_fake_bitmap(int width, int height) { - SkBitmap bitmap; - bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); - return bitmap; -} - // TODO: should inherit from SkBaseDevice instead of SkBitmapDevice... -SkXPSDevice::SkXPSDevice() - : INHERITED(make_fake_bitmap(10000, 10000), SkSurfaceProps(0, kUnknown_SkPixelGeometry)) +SkXPSDevice::SkXPSDevice(SkISize s) + : INHERITED(SkImageInfo::MakeUnknown(s.width(), s.height()), + SkSurfaceProps(0, kUnknown_SkPixelGeometry)) , fCurrentPage(0) { } -SkXPSDevice::SkXPSDevice(IXpsOMObjectFactory* xpsFactory) - : INHERITED(make_fake_bitmap(10000, 10000), SkSurfaceProps(0, kUnknown_SkPixelGeometry)) +SkXPSDevice::SkXPSDevice(SkISize s, IXpsOMObjectFactory* xpsFactory) + : INHERITED(SkImageInfo::MakeUnknown(s.width(), s.height()), + SkSurfaceProps(0, kUnknown_SkPixelGeometry)) , fCurrentPage(0) { HRVM(CoCreateInstance( @@ -2281,7 +2278,32 @@ SkBaseDevice* SkXPSDevice::onCreateDevice(const CreateInfo& info, const SkPaint* //return dev; } #endif - return new SkXPSDevice(this->fXpsFactory.get()); + return new SkXPSDevice(info.fInfo.dimensions(), this->fXpsFactory.get()); } +void SkXPSDevice::drawOval(const SkDraw& d, const SkRect& o, const SkPaint& p) { + SkPath path; + path.addOval(o); + this->drawPath(d, path, p, nullptr, true); +} + +void SkXPSDevice::drawBitmapRect(const SkDraw& draw, + const SkBitmap& bitmap, + const SkRect* src, + const SkRect& dst, + const SkPaint& paint, + SkCanvas::SrcRectConstraint constraint) { + SkRect srcBounds = src ? *src : SkRect::Make(bitmap.bounds()); + SkMatrix matrix = SkMatrix::MakeRectToRect(srcBounds, dst, SkMatrix::kFill_ScaleToFit); + + auto bitmapShader = SkMakeBitmapShader(bitmap, SkShader::kClamp_TileMode, + SkShader::kClamp_TileMode, &matrix, + kNever_SkCopyPixelsMode, nullptr); + SkASSERT(bitmapShader); + if (!bitmapShader) { return; } + SkPaint paintWithShader(paint); + paintWithShader.setStyle(SkPaint::kFill_Style); + paintWithShader.setShader(std::move(bitmapShader)); + this->drawRect(draw, dst, paintWithShader); +} #endif//defined(SK_BUILD_FOR_WIN32) diff --git a/src/xps/SkXPSDevice.h b/src/xps/SkXPSDevice.h index bbb0716cdf..db8436d5e8 100644 --- a/src/xps/SkXPSDevice.h +++ b/src/xps/SkXPSDevice.h @@ -35,12 +35,12 @@ The drawing context for the XPS backend. */ -class SkXPSDevice : public SkBitmapDevice { +class SkXPSDevice : public SkBaseDevice { public: - SK_API SkXPSDevice(); + SK_API SkXPSDevice(SkISize); SK_API virtual ~SkXPSDevice(); - virtual bool beginPortfolio(SkWStream* outputStream); + bool beginPortfolio(SkWStream* outputStream); /** @param unitsPerMeter converts geometry units into physical units. @param pixelsPerMeter resolution to use when geometry must be rasterized. @@ -60,7 +60,7 @@ public: Must be contained within the mediaBox. The default is to coincide with the mediaBox. */ - virtual bool beginSheet( + bool beginSheet( const SkVector& unitsPerMeter, const SkVector& pixelsPerMeter, const SkSize& trimSize, @@ -69,60 +69,60 @@ public: const SkRect* artBox = NULL, const SkRect* cropBox = NULL); - virtual bool endSheet(); - virtual bool endPortfolio(); + bool endSheet(); + bool endPortfolio(); protected: void drawPaint(const SkDraw&, const SkPaint& paint) override; - virtual void drawPoints( + void drawPoints( const SkDraw&, SkCanvas::PointMode mode, size_t count, const SkPoint[], const SkPaint& paint) override; - virtual void drawRect( + void drawRect( const SkDraw&, const SkRect& r, const SkPaint& paint) override; - virtual void drawRRect( + void drawRRect( const SkDraw&, const SkRRect&, const SkPaint& paint) override; - virtual void drawPath( + void drawPath( const SkDraw&, const SkPath& platonicPath, const SkPaint& paint, const SkMatrix* prePathMatrix, bool pathIsMutable) override; - virtual void drawBitmap( + void drawBitmap( const SkDraw&, const SkBitmap& bitmap, const SkMatrix& matrix, const SkPaint& paint) override; - virtual void drawSprite( + void drawSprite( const SkDraw&, const SkBitmap& bitmap, int x, int y, const SkPaint& paint) override; - virtual void drawText( + void drawText( const SkDraw&, const void* text, size_t len, SkScalar x, SkScalar y, const SkPaint& paint) override; - virtual void drawPosText( + void drawPosText( const SkDraw&, const void* text, size_t len, const SkScalar pos[], int scalarsPerPos, const SkPoint& offset, const SkPaint& paint) override; - virtual void drawVertices( + void drawVertices( const SkDraw&, SkCanvas::VertexMode, int vertexCount, const SkPoint verts[], @@ -131,12 +131,22 @@ protected: const uint16_t indices[], int indexCount, const SkPaint& paint) override; - virtual void drawDevice( + void drawDevice( const SkDraw&, SkBaseDevice* device, int x, int y, const SkPaint& paint) override; + void drawOval(const SkDraw&, const SkRect&, const SkPaint&) override; + + void drawBitmapRect(const SkDraw&, + const SkBitmap&, + const SkRect*, + const SkRect&, + const SkPaint&, + SkCanvas::SrcRectConstraint) override; + + private: class TypefaceUse : ::SkNoncopyable { public: @@ -151,7 +161,7 @@ private: }; friend HRESULT subset_typeface(TypefaceUse* current); - SkXPSDevice(IXpsOMObjectFactory* xpsFactory); + SkXPSDevice(SkISize, IXpsOMObjectFactory*); SkAutoCoInitialize fAutoCo; SkTScopedComPtr fXpsFactory; @@ -317,7 +327,7 @@ private: SkXPSDevice(const SkXPSDevice&); void operator=(const SkXPSDevice&); - typedef SkBitmapDevice INHERITED; + typedef SkBaseDevice INHERITED; }; #endif // SK_BUILD_FOR_WIN -- cgit v1.2.3