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