diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkBitmapDevice.h | 2 | ||||
-rw-r--r-- | include/core/SkCanvas.h | 21 | ||||
-rw-r--r-- | include/core/SkDevice.h | 4 | ||||
-rw-r--r-- | include/core/SkSurface.h | 89 | ||||
-rw-r--r-- | include/core/SkSurfaceProps.h | 80 | ||||
-rw-r--r-- | include/pdf/SkPDFDevice.h | 2 | ||||
-rw-r--r-- | include/utils/SkNoSaveLayerCanvas.h | 3 |
7 files changed, 160 insertions, 41 deletions
diff --git a/include/core/SkBitmapDevice.h b/include/core/SkBitmapDevice.h index 39bbab63e5..0ab0234772 100644 --- a/include/core/SkBitmapDevice.h +++ b/include/core/SkBitmapDevice.h @@ -155,7 +155,7 @@ private: virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE; - virtual SkSurface* newSurface(const SkImageInfo&) SK_OVERRIDE; + virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE; virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes) SK_OVERRIDE; virtual SkImageFilter::Cache* getImageFilterCache() SK_OVERRIDE; diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 5088d7ded5..77038c3067 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -16,6 +16,7 @@ #include "SkRefCnt.h" #include "SkPath.h" #include "SkRegion.h" +#include "SkSurfaceProps.h" #include "SkXfermode.h" #ifdef SK_SUPPORT_LEGACY_DRAWTEXT_VIRTUAL @@ -200,8 +201,12 @@ public: * Create a new surface matching the specified info, one that attempts to * be maximally compatible when used with this canvas. If there is no matching Surface type, * NULL is returned. + * + * If surfaceprops is specified, those are passed to the new surface, otherwise the new surface + * inherits the properties of the surface that owns this canvas. If this canvas has no parent + * surface, then the new surface is created with default properties. */ - SkSurface* newSurface(const SkImageInfo&); + SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps* = NULL); /** * Return the GPU context of the device that is associated with the canvas. @@ -1192,7 +1197,7 @@ public: protected: // default impl defers to getDevice()->newSurface(info) - virtual SkSurface* onNewSurface(const SkImageInfo&); + virtual SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&); // default impl defers to its device virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes); @@ -1282,6 +1287,8 @@ private: // the first N recs that can fit here mean we won't call malloc uint32_t fMCRecStorage[32]; + const SkSurfaceProps fProps; + int fSaveLayerCount; // number of successful saveLayer calls int fCullCount; // number of active culls @@ -1311,14 +1318,20 @@ private: kDefault_InitFlags = 0, kConservativeRasterClip_InitFlag = 1 << 0, }; - SkCanvas(int width, int height, InitFlags flags); - SkCanvas(SkBaseDevice*, InitFlags flags); + SkCanvas(int width, int height, InitFlags); + SkCanvas(SkBaseDevice*, const SkSurfaceProps*, InitFlags); + SkCanvas(const SkBitmap&, const SkSurfaceProps&); // needs gettotalclip() friend SkCanvasState* SkCanvasStateUtils::CaptureCanvasState(SkCanvas*); SkBaseDevice* createLayerDevice(const SkImageInfo&); + // call this each time we attach ourselves to a device + // - constructor + // - internalSaveLayer + void setupDevice(SkBaseDevice*); + SkBaseDevice* init(SkBaseDevice*, InitFlags); /** diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index e74e95f2f3..08320bf7b4 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -288,7 +288,7 @@ protected: protected: // default impl returns NULL - virtual SkSurface* newSurface(const SkImageInfo&); + virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&); // default impl returns NULL virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes); @@ -343,6 +343,8 @@ protected: virtual bool EXPERIMENTAL_drawPicture(SkCanvas*, const SkPicture*, const SkMatrix*, const SkPaint*); + void setPixelGeometry(SkPixelGeometry geo); + private: friend class SkCanvas; friend struct DeviceCM; //for setMatrixClip diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h index 1871c676f2..e0e60ab7fb 100644 --- a/include/core/SkSurface.h +++ b/include/core/SkSurface.h @@ -10,6 +10,9 @@ #include "SkRefCnt.h" #include "SkImage.h" +#include "SkSurfaceProps.h" + +//#define SK_SUPPORT_LEGACY_TEXTRENDERMODE class SkCanvas; class SkPaint; @@ -35,7 +38,8 @@ public: * If the requested surface cannot be created, or the request is not a * supported configuration, NULL will be returned. */ - static SkSurface* NewRasterDirect(const SkImageInfo&, void* pixels, size_t rowBytes); + static SkSurface* NewRasterDirect(const SkImageInfo&, void* pixels, size_t rowBytes, + const SkSurfaceProps* = NULL); /** * The same as NewRasterDirect, but also accepts a call-back routine, which is invoked @@ -43,7 +47,7 @@ public: */ static SkSurface* NewRasterDirectReleaseProc(const SkImageInfo&, void* pixels, size_t rowBytes, void (*releaseProc)(void* pixels, void* context), - void* context); + void* context, const SkSurfaceProps* = NULL); /** * Return a new surface, with the memory for the pixels automatically @@ -52,45 +56,36 @@ public: * If the requested surface cannot be created, or the request is not a * supported configuration, NULL will be returned. */ - static SkSurface* NewRaster(const SkImageInfo&); + static SkSurface* NewRaster(const SkImageInfo&, const SkSurfaceProps* = NULL); /** * Helper version of NewRaster. It creates a SkImageInfo with the * specified width and height, and populates the rest of info to match * pixels in SkPMColor format. */ - static SkSurface* NewRasterPMColor(int width, int height) { - return NewRaster(SkImageInfo::MakeN32Premul(width, height)); + static SkSurface* NewRasterPMColor(int width, int height, const SkSurfaceProps* props = NULL) { + return NewRaster(SkImageInfo::MakeN32Premul(width, height), props); } /** - * Text rendering modes that can be passed to NewRenderTarget* - */ - enum TextRenderMode { - /** - * This will use the standard text rendering method - */ - kStandard_TextRenderMode, - /** - * This will use signed distance fields for text rendering when possible - */ - kDistanceField_TextRenderMode, - }; - - /** * Return a new surface using the specified render target. - * The pixels in the rendertarget are not cleared or otherwised changed when the surface - * is created. */ - static SkSurface* NewRenderTargetDirect(GrRenderTarget*, - TextRenderMode trm = kStandard_TextRenderMode); - + static SkSurface* NewRenderTargetDirect(GrRenderTarget*, const SkSurfaceProps*); + + static SkSurface* NewRenderTargetDirect(GrRenderTarget* target) { + return NewRenderTargetDirect(target, NULL); + } + /** * Return a new surface whose contents will be drawn to an offscreen * render target, allocated by the surface. */ - static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sampleCount = 0, - TextRenderMode trm = kStandard_TextRenderMode); + static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sampleCount, + const SkSurfaceProps* = NULL); + + static SkSurface* NewRenderTarget(GrContext* gr, const SkImageInfo& info) { + return NewRenderTarget(gr, info, 0, NULL); + } /** * Return a new surface whose contents will be drawn to an offscreen @@ -104,8 +99,33 @@ public: * Note: Scratch textures count against the GrContext's cached resource * budget. */ - static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int sampleCount = 0, - TextRenderMode trm = kStandard_TextRenderMode); + static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int sampleCount, + const SkSurfaceProps*); + + static SkSurface* NewScratchRenderTarget(GrContext* gr, const SkImageInfo& info) { + return NewScratchRenderTarget(gr, info, 0, NULL); + } + +#ifdef SK_SUPPORT_LEGACY_TEXTRENDERMODE + /** + * Text rendering modes that can be passed to NewRenderTarget* + */ + enum TextRenderMode { + /** + * This will use the standard text rendering method + */ + kStandard_TextRenderMode, + /** + * This will use signed distance fields for text rendering when possible + */ + kDistanceField_TextRenderMode, + }; + static SkSurface* NewRenderTargetDirect(GrRenderTarget*, TextRenderMode); + static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sampleCount, + TextRenderMode); + static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int sampleCount, + TextRenderMode); +#endif int width() const { return fWidth; } int height() const { return fHeight; } @@ -194,9 +214,11 @@ public: */ const void* peekPixels(SkImageInfo* info, size_t* rowBytes); + const SkSurfaceProps& props() const { return fProps; } + protected: - SkSurface(int width, int height); - SkSurface(const SkImageInfo&); + SkSurface(int width, int height, const SkSurfaceProps*); + SkSurface(const SkImageInfo&, const SkSurfaceProps*); // called by subclass if their contents have changed void dirtyGenerationID() { @@ -204,9 +226,10 @@ protected: } private: - const int fWidth; - const int fHeight; - uint32_t fGenerationID; + const SkSurfaceProps fProps; + const int fWidth; + const int fHeight; + uint32_t fGenerationID; typedef SkRefCnt INHERITED; }; diff --git a/include/core/SkSurfaceProps.h b/include/core/SkSurfaceProps.h new file mode 100644 index 0000000000..0154473914 --- /dev/null +++ b/include/core/SkSurfaceProps.h @@ -0,0 +1,80 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkSurfaceProps_DEFINED +#define SkSurfaceProps_DEFINED + +#include "SkTypes.h" + +/** + * Description of how the LCD strips are arranged for each pixel. If this is unknown, or the + * pixels are meant to be "portable" and/or transformed before showing (e.g. rotated, scaled) + * then use kUnknown_SkPixelGeometry. + */ +enum SkPixelGeometry { + kUnknown_SkPixelGeometry, + kRGB_H_SkPixelGeometry, + kBGR_H_SkPixelGeometry, + kRGB_V_SkPixelGeometry, + kBGR_V_SkPixelGeometry, +}; + +// Returns true iff geo is a known geometry and is RGB. +static inline bool SkPixelGeometryIsRGB(SkPixelGeometry geo) { + return kRGB_H_SkPixelGeometry == geo || kRGB_V_SkPixelGeometry == geo; +} + +// Returns true iff geo is a known geometry and is BGR. +static inline bool SkPixelGeometryIsBGR(SkPixelGeometry geo) { + return kBGR_H_SkPixelGeometry == geo || kBGR_V_SkPixelGeometry == geo; +} + +// Returns true iff geo is a known geometry and is horizontal. +static inline bool SkPixelGeometryIsH(SkPixelGeometry geo) { + return kRGB_H_SkPixelGeometry == geo || kBGR_H_SkPixelGeometry == geo; +} + +// Returns true iff geo is a known geometry and is vertical. +static inline bool SkPixelGeometryIsV(SkPixelGeometry geo) { + return kRGB_V_SkPixelGeometry == geo || kBGR_V_SkPixelGeometry == geo; +} + +/** + * Describes properties and constraints of a given SkSurface. The rendering engine can parse these + * during drawing, and can sometimes optimize its performance (e.g. disabling an expensive + * feature). + */ +class SkSurfaceProps { +public: + enum Flags { + kDisallowAntiAlias_Flag = 1 << 0, + kDisallowDither_Flag = 1 << 1, + kUseDistanceFieldFonts_Flag = 1 << 2, + }; + SkSurfaceProps(uint32_t flags, SkPixelGeometry); + + enum InitType { + kLegacyFontHost_InitType + }; + SkSurfaceProps(InitType); + SkSurfaceProps(uint32_t flags, InitType); + + uint32_t flags() const { return fFlags; } + SkPixelGeometry pixelGeometry() const { return fPixelGeometry; } + + bool isDisallowAA() const { return SkToBool(fFlags & kDisallowAntiAlias_Flag); } + bool isDisallowDither() const { return SkToBool(fFlags & kDisallowDither_Flag); } + bool isUseDistanceFieldFonts() const { return SkToBool(fFlags & kUseDistanceFieldFonts_Flag); } + +private: + SkSurfaceProps(); + + uint32_t fFlags; + SkPixelGeometry fPixelGeometry; +}; + +#endif diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h index bcdcfb24e4..0bfbc36d1a 100644 --- a/include/pdf/SkPDFDevice.h +++ b/include/pdf/SkPDFDevice.h @@ -217,7 +217,7 @@ protected: return false; } - virtual SkSurface* newSurface(const SkImageInfo&) SK_OVERRIDE; + virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE; private: // TODO(vandebo): push most of SkPDFDevice's state into a core object in diff --git a/include/utils/SkNoSaveLayerCanvas.h b/include/utils/SkNoSaveLayerCanvas.h index 56a09622a0..b6926973e0 100644 --- a/include/utils/SkNoSaveLayerCanvas.h +++ b/include/utils/SkNoSaveLayerCanvas.h @@ -16,7 +16,8 @@ // It also simplifies the clipping calls to only use rectangles. class SK_API SkNoSaveLayerCanvas : public SkCanvas { public: - SkNoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device, kConservativeRasterClip_InitFlag) + SkNoSaveLayerCanvas(SkBaseDevice* device) + : INHERITED(device, NULL, kConservativeRasterClip_InitFlag) {} protected: |