[PATCH 1/6] Bug 985217 - Update Skia to r13827 r=upstream

This commit is contained in:
George Wright 2014-03-17 07:34:32 -04:00
Родитель cab6fcbcfb
Коммит 3c5f3ef4aa
374 изменённых файлов: 11743 добавлений и 10929 удалений

Просмотреть файл

@ -2,7 +2,7 @@ The source from this directory was copied from the skia subversion trunk
using the update.sh script. The changes made were those applied by update.sh,
the addition/update of Makefile.in files for the Mozilla build system.
The subversion revision used was r13424.
The subversion revision used was r13827.
To update to a new version of Skia:

Просмотреть файл

@ -166,7 +166,7 @@ def generate_separated_sources(platform_sources):
'SkBitmapHasher',
'SkWGL',
'SkImages',
'SkDiscardableMemory_ashmem'
'SkDiscardableMemory_ashmem',
'SkMemory_malloc'
]

Просмотреть файл

@ -5,7 +5,6 @@ EXPORTS.skia += [
'trunk/include/animator/SkAnimator.h',
'trunk/include/animator/SkAnimatorView.h',
'trunk/include/config/SkUserConfig.h',
'trunk/include/core/Sk64.h',
'trunk/include/core/SkAdvancedTypefaceMetrics.h',
'trunk/include/core/SkAnnotation.h',
'trunk/include/core/SkBitmap.h',
@ -51,7 +50,6 @@ EXPORTS.skia += [
'trunk/include/core/SkImageDecoder.h',
'trunk/include/core/SkImageEncoder.h',
'trunk/include/core/SkImageFilter.h',
'trunk/include/core/SkImageFilterUtils.h',
'trunk/include/core/SkImageGenerator.h',
'trunk/include/core/SkImageInfo.h',
'trunk/include/core/SkInstCnt.h',
@ -84,7 +82,6 @@ EXPORTS.skia += [
'trunk/include/core/SkRegion.h',
'trunk/include/core/SkRRect.h',
'trunk/include/core/SkScalar.h',
'trunk/include/core/SkScalarCompare.h',
'trunk/include/core/SkShader.h',
'trunk/include/core/SkSize.h',
'trunk/include/core/SkStream.h',
@ -98,7 +95,6 @@ EXPORTS.skia += [
'trunk/include/core/SkTDStack.h',
'trunk/include/core/SkTemplates.h',
'trunk/include/core/SkThread.h',
'trunk/include/core/SkThread_platform.h',
'trunk/include/core/SkTileGridPicture.h',
'trunk/include/core/SkTime.h',
'trunk/include/core/SkTInternalLList.h',
@ -123,7 +119,6 @@ EXPORTS.skia += [
'trunk/include/effects/SkArithmeticMode.h',
'trunk/include/effects/SkAvoidXfermode.h',
'trunk/include/effects/SkBicubicImageFilter.h',
'trunk/include/effects/SkBitmapAlphaThresholdShader.h',
'trunk/include/effects/SkBitmapSource.h',
'trunk/include/effects/SkBlurDrawLooper.h',
'trunk/include/effects/SkBlurImageFilter.h',
@ -177,14 +172,12 @@ EXPORTS.skia += [
'trunk/include/gpu/gl/SkNativeGLContext.h',
'trunk/include/gpu/gl/SkNullGLContext.h',
'trunk/include/gpu/GrBackendEffectFactory.h',
'trunk/include/gpu/GrBitmapTextContext.h',
'trunk/include/gpu/GrClipData.h',
'trunk/include/gpu/GrColor.h',
'trunk/include/gpu/GrConfig.h',
'trunk/include/gpu/GrContext.h',
'trunk/include/gpu/GrContextFactory.h',
'trunk/include/gpu/GrCoordTransform.h',
'trunk/include/gpu/GrDistanceFieldTextContext.h',
'trunk/include/gpu/GrDrawEffect.h',
'trunk/include/gpu/GrEffect.h',
'trunk/include/gpu/GrEffectStage.h',
@ -200,7 +193,6 @@ EXPORTS.skia += [
'trunk/include/gpu/GrResource.h',
'trunk/include/gpu/GrSurface.h',
'trunk/include/gpu/GrTBackendEffectFactory.h',
'trunk/include/gpu/GrTextContext.h',
'trunk/include/gpu/GrTexture.h',
'trunk/include/gpu/GrTextureAccess.h',
'trunk/include/gpu/GrTypes.h',
@ -257,6 +249,7 @@ EXPORTS.skia += [
'trunk/include/utils/SkMatrix44.h',
'trunk/include/utils/SkMeshUtils.h',
'trunk/include/utils/SkNinePatch.h',
'trunk/include/utils/SkNoSaveLayerCanvas.h',
'trunk/include/utils/SkNullCanvas.h',
'trunk/include/utils/SkNWayCanvas.h',
'trunk/include/utils/SkParse.h',
@ -358,6 +351,7 @@ SOURCES += [
'trunk/src/core/SkDevice.cpp',
'trunk/src/core/SkDeviceLooper.cpp',
'trunk/src/core/SkDeviceProfile.cpp',
'trunk/src/core/SkDistanceFieldGen.cpp',
'trunk/src/core/SkDither.cpp',
'trunk/src/core/SkDraw.cpp',
'trunk/src/core/SkDrawLooper.cpp',
@ -378,7 +372,6 @@ SOURCES += [
'trunk/src/core/SkGlyphCache.cpp',
'trunk/src/core/SkGraphics.cpp',
'trunk/src/core/SkImageFilter.cpp',
'trunk/src/core/SkImageFilterUtils.cpp',
'trunk/src/core/SkImageInfo.cpp',
'trunk/src/core/SkInstCnt.cpp',
'trunk/src/core/SkLineClipper.cpp',
@ -515,6 +508,8 @@ SOURCES += [
'trunk/src/gpu/effects/GrConvexPolyEffect.cpp',
'trunk/src/gpu/effects/GrConvolutionEffect.cpp',
'trunk/src/gpu/effects/GrCustomCoordsTextureEffect.cpp',
'trunk/src/gpu/effects/GrDistanceFieldTextureEffect.cpp',
'trunk/src/gpu/effects/GrRRectEffect.cpp',
'trunk/src/gpu/effects/GrSimpleTextureEffect.cpp',
'trunk/src/gpu/effects/GrSingleTextureEffect.cpp',
'trunk/src/gpu/effects/GrTextureDomain.cpp',
@ -570,6 +565,7 @@ SOURCES += [
'trunk/src/gpu/GrClipMaskManager.cpp',
'trunk/src/gpu/GrContext.cpp',
'trunk/src/gpu/GrDefaultPathRenderer.cpp',
'trunk/src/gpu/GrDistanceFieldTextContext.cpp',
'trunk/src/gpu/GrDrawState.cpp',
'trunk/src/gpu/GrDrawTarget.cpp',
'trunk/src/gpu/GrEffect.cpp',
@ -693,7 +689,6 @@ SOURCES += [
'trunk/src/utils/SkProxyCanvas.cpp',
'trunk/src/utils/SkRTConf.cpp',
'trunk/src/utils/SkSHA1.cpp',
'trunk/src/utils/SkThreadPool.cpp',
'trunk/src/utils/SkUnitMappers.cpp',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gonk'):

Просмотреть файл

@ -1,230 +0,0 @@
/*
* Copyright 2006 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef Sk64_DEFINED
#define Sk64_DEFINED
#include "SkFixed.h"
/** \class Sk64
Sk64 is a 64-bit math package that does not require long long support from the compiler.
*/
struct SK_API Sk64 {
int32_t fHi; //!< the high 32 bits of the number (including sign)
uint32_t fLo; //!< the low 32 bits of the number
/** Returns non-zero if the Sk64 can be represented as a signed 32 bit integer
*/
SkBool is32() const { return fHi == ((int32_t)fLo >> 31); }
/** Returns non-zero if the Sk64 cannot be represented as a signed 32 bit integer
*/
SkBool is64() const { return fHi != ((int32_t)fLo >> 31); }
/** Returns non-zero if the Sk64 can be represented as a signed 48 bit integer. Used to know
if we can shift the value down by 16 to treat it as a SkFixed.
*/
SkBool isFixed() const;
/** Return the signed 32 bit integer equivalent. Asserts that is32() returns non-zero.
*/
int32_t get32() const { SkASSERT(this->is32()); return (int32_t)fLo; }
/** Return the number >> 16. Asserts that this does not loose any significant high bits.
*/
SkFixed getFixed() const {
SkASSERT(this->isFixed());
uint32_t sum = fLo + (1 << 15);
int32_t hi = fHi;
if (sum < fLo) {
hi += 1;
}
return (hi << 16) | (sum >> 16);
}
/** Return the number >> 30. Asserts that this does not loose any
significant high bits.
*/
SkFract getFract() const;
/** Returns the square-root of the number as a signed 32 bit value. */
int32_t getSqrt() const;
/** Returns the number of leading zeros of the absolute value of this.
Will return in the range [0..64]
*/
int getClzAbs() const;
/** Returns non-zero if the number is zero */
SkBool isZero() const { return (fHi | fLo) == 0; }
/** Returns non-zero if the number is non-zero */
SkBool nonZero() const { return fHi | fLo; }
/** Returns non-zero if the number is negative (number < 0) */
SkBool isNeg() const { return (uint32_t)fHi >> 31; }
/** Returns non-zero if the number is positive (number > 0) */
SkBool isPos() const { return ~(fHi >> 31) & (fHi | fLo); }
/** Returns -1,0,+1 based on the sign of the number */
int getSign() const { return (fHi >> 31) | Sk32ToBool(fHi | fLo); }
/** Negate the number */
void negate();
/** If the number < 0, negate the number
*/
void abs();
/** Returns the number of bits needed to shift the Sk64 to the right
in order to make it fit in a signed 32 bit integer.
*/
int shiftToMake32() const;
/** Set the number to zero */
void setZero() { fHi = fLo = 0; }
/** Set the high and low 32 bit values of the number */
void set(int32_t hi, uint32_t lo) { fHi = hi; fLo = lo; }
/** Set the number to the specified 32 bit integer */
void set(int32_t a) { fHi = a >> 31; fLo = a; }
/** Set the number to the product of the two 32 bit integers */
void setMul(int32_t a, int32_t b);
/** extract 32bits after shifting right by bitCount.
Note: itCount must be [0..63].
Asserts that no significant high bits were lost.
*/
int32_t getShiftRight(unsigned bitCount) const;
/** Shift the number left by the specified number of bits.
@param bits How far to shift left, must be [0..63]
*/
void shiftLeft(unsigned bits);
/** Shift the number right by the specified number of bits.
@param bits How far to shift right, must be [0..63]. This
performs an arithmetic right-shift (sign extending).
*/
void shiftRight(unsigned bits);
/** Shift the number right by the specified number of bits, but
round the result.
@param bits How far to shift right, must be [0..63]. This
performs an arithmetic right-shift (sign extending).
*/
void roundRight(unsigned bits);
/** Add the specified 32 bit integer to the number */
void add(int32_t lo) {
int32_t hi = lo >> 31; // 0 or -1
uint32_t sum = fLo + (uint32_t)lo;
fHi = fHi + hi + (sum < fLo);
fLo = sum;
}
/** Add the specified Sk64 to the number */
void add(int32_t hi, uint32_t lo) {
uint32_t sum = fLo + lo;
fHi = fHi + hi + (sum < fLo);
fLo = sum;
}
/** Add the specified Sk64 to the number */
void add(const Sk64& other) { this->add(other.fHi, other.fLo); }
/** Subtract the specified Sk64 from the number. (*this) = (*this) - num
*/
void sub(const Sk64& num);
/** Subtract the number from the specified Sk64. (*this) = num - (*this)
*/
void rsub(const Sk64& num);
/** Multiply the number by the specified 32 bit integer
*/
void mul(int32_t);
enum DivOptions {
kTrunc_DivOption, //!< truncate the result when calling div()
kRound_DivOption //!< round the result when calling div()
};
/** Divide the number by the specified 32 bit integer, using the specified
divide option (either truncate or round).
*/
void div(int32_t, DivOptions);
/** return (this + other >> 16) as a 32bit result */
SkFixed addGetFixed(const Sk64& other) const {
return this->addGetFixed(other.fHi, other.fLo);
}
/** return (this + Sk64(hi, lo) >> 16) as a 32bit result */
SkFixed addGetFixed(int32_t hi, uint32_t lo) const {
#ifdef SK_DEBUG
Sk64 tmp(*this);
tmp.add(hi, lo);
#endif
uint32_t sum = fLo + lo;
hi += fHi + (sum < fLo);
lo = sum;
sum = lo + (1 << 15);
if (sum < lo)
hi += 1;
hi = (hi << 16) | (sum >> 16);
SkASSERT(hi == tmp.getFixed());
return hi;
}
/** Return the result of dividing the number by denom, treating the answer
as a SkFixed. (*this) << 16 / denom. It is an error for denom to be 0.
*/
SkFixed getFixedDiv(const Sk64& denom) const;
friend bool operator==(const Sk64& a, const Sk64& b) {
return a.fHi == b.fHi && a.fLo == b.fLo;
}
friend bool operator!=(const Sk64& a, const Sk64& b) {
return a.fHi != b.fHi || a.fLo != b.fLo;
}
friend bool operator<(const Sk64& a, const Sk64& b) {
return a.fHi < b.fHi || (a.fHi == b.fHi && a.fLo < b.fLo);
}
friend bool operator<=(const Sk64& a, const Sk64& b) {
return a.fHi < b.fHi || (a.fHi == b.fHi && a.fLo <= b.fLo);
}
friend bool operator>(const Sk64& a, const Sk64& b) {
return a.fHi > b.fHi || (a.fHi == b.fHi && a.fLo > b.fLo);
}
friend bool operator>=(const Sk64& a, const Sk64& b) {
return a.fHi > b.fHi || (a.fHi == b.fHi && a.fLo >= b.fLo);
}
#ifdef SkLONGLONG
SkLONGLONG getLongLong() const;
#endif
};
#endif

Просмотреть файл

@ -24,18 +24,27 @@ struct SkPoint;
*/
class SkAnnotation : public SkRefCnt {
public:
SkAnnotation(const char key[], SkData* value);
virtual ~SkAnnotation();
static SkAnnotation* Create(const char key[], SkData* value) {
return SkNEW_ARGS(SkAnnotation, (key, value));
}
static SkAnnotation* Create(SkReadBuffer& buffer) {
return SkNEW_ARGS(SkAnnotation, (buffer));
}
/**
* Return the data for the specified key, or NULL.
*/
SkData* find(const char key[]) const;
SkAnnotation(SkReadBuffer&);
void writeToBuffer(SkWriteBuffer&) const;
private:
SkAnnotation(const char key[], SkData* value);
SkAnnotation(SkReadBuffer&);
SkString fKey;
SkData* fData;

Просмотреть файл

@ -14,6 +14,7 @@
#include "SkPoint.h"
#include "SkRefCnt.h"
struct SkMask;
struct SkIRect;
struct SkRect;
class SkPaint;
@ -21,7 +22,6 @@ class SkPixelRef;
class SkPixelRefFactory;
class SkRegion;
class SkString;
class GrTexture;
/** \class SkBitmap
@ -308,6 +308,22 @@ public:
void (*ReleaseProc)(void* addr, void* context),
void* context);
/**
* Call installPixels with no ReleaseProc specified. This means that the
* caller must ensure that the specified pixels are valid for the lifetime
* of the created bitmap (and its pixelRef).
*/
bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) {
return this->installPixels(info, pixels, rowBytes, NULL, NULL);
}
/**
* Calls installPixels() with the value in the SkMask. The caller must
* ensure that the specified mask pixels are valid for the lifetime
* of the created bitmap (and its pixelRef).
*/
bool installMaskPixels(const SkMask&);
/**
* DEPRECATED: call info().
*/
@ -455,7 +471,7 @@ public:
*/
bool readyToDraw() const {
return this->getPixels() != NULL &&
(this->config() != kIndex8_Config || NULL != fColorTable);
(this->colorType() != kIndex_8_SkColorType || NULL != fColorTable);
}
/** Returns the pixelRef's texture, or NULL
@ -599,33 +615,37 @@ public:
*/
bool extractSubset(SkBitmap* dst, const SkIRect& subset) const;
/** Makes a deep copy of this bitmap, respecting the requested config,
/** Makes a deep copy of this bitmap, respecting the requested colorType,
* and allocating the dst pixels on the cpu.
* Returns false if either there is an error (i.e. the src does not have
* pixels) or the request cannot be satisfied (e.g. the src has per-pixel
* alpha, and the requested config does not support alpha).
* @param dst The bitmap to be sized and allocated
* @param c The desired config for dst
* @param ct The desired colorType for dst
* @param allocator Allocator used to allocate the pixelref for the dst
* bitmap. If this is null, the standard HeapAllocator
* will be used.
* @return true if the copy could be made.
* @return true if the copy was made.
*/
bool copyTo(SkBitmap* dst, Config c, Allocator* allocator = NULL) const;
bool copyTo(SkBitmap* dst, SkColorType ct, Allocator* = NULL) const;
/** Makes a deep copy of this bitmap, respecting the requested config, and
* with custom allocation logic that will keep the copied pixels
bool copyTo(SkBitmap* dst, Allocator* allocator = NULL) const {
return this->copyTo(dst, this->colorType(), allocator);
}
/**
* Returns true if this bitmap's pixels can be converted into the requested
* colorType, such that copyTo() could succeed.
*/
bool canCopyTo(SkColorType colorType) const;
/** Makes a deep copy of this bitmap, keeping the copied pixels
* in the same domain as the source: If the src pixels are allocated for
* the cpu, then so will the dst. If the src pixels are allocated on the
* gpu (typically as a texture), the it will do the same for the dst.
* If the request cannot be fulfilled, returns false and dst is unmodified.
*/
bool deepCopyTo(SkBitmap* dst, Config c) const;
/** Returns true if this bitmap can be deep copied into the requested config
by calling copyTo().
*/
bool canCopyTo(Config newConfig) const;
bool deepCopyTo(SkBitmap* dst) const;
SK_ATTR_DEPRECATED("use setFilterLevel on SkPaint")
void buildMipMap(bool forceRebuild = false);
@ -727,7 +747,7 @@ public:
int fHeight;
};
SkDEVCODE(void toString(SkString* str) const;)
SK_TO_STRING_NONVIRT()
private:
struct MipMap;
@ -870,31 +890,38 @@ private:
inline uint32_t* SkBitmap::getAddr32(int x, int y) const {
SkASSERT(fPixels);
SkASSERT(this->config() == kARGB_8888_Config);
SkASSERT(4 == this->bytesPerPixel());
SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height());
return (uint32_t*)((char*)fPixels + y * fRowBytes + (x << 2));
}
inline uint16_t* SkBitmap::getAddr16(int x, int y) const {
SkASSERT(fPixels);
SkASSERT(this->config() == kRGB_565_Config || this->config() == kARGB_4444_Config);
SkASSERT(2 == this->bytesPerPixel());
SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height());
return (uint16_t*)((char*)fPixels + y * fRowBytes + (x << 1));
}
inline uint8_t* SkBitmap::getAddr8(int x, int y) const {
SkASSERT(fPixels);
SkASSERT(this->config() == kA8_Config || this->config() == kIndex8_Config);
SkASSERT(1 == this->bytesPerPixel());
SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height());
return (uint8_t*)fPixels + y * fRowBytes + x;
}
inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const {
SkASSERT(fPixels);
SkASSERT(this->config() == kIndex8_Config);
SkASSERT(kIndex_8_SkColorType == this->colorType());
SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height());
SkASSERT(fColorTable);
return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)];
}
///////////////////////////////////////////////////////////////////////////////
//
// Helpers until we can fully deprecate SkBitmap::Config
//
extern SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType);
extern SkColorType SkBitmapConfigToColorType(SkBitmap::Config);
#endif

Просмотреть файл

@ -30,6 +30,7 @@ public:
*/
SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties);
#ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG
/**
* Create a new raster device and have the pixels be automatically
* allocated. The rowBytes of the device will be computed automatically
@ -61,10 +62,9 @@ public:
*/
SkBitmapDevice(SkBitmap::Config config, int width, int height, bool isOpaque,
const SkDeviceProperties& deviceProperties);
virtual ~SkBitmapDevice();
virtual uint32_t getDeviceCapabilities() SK_OVERRIDE { return 0; }
#endif
static SkBitmapDevice* Create(const SkImageInfo&,
const SkDeviceProperties* = NULL);
/** Return the width of the device (in pixels).
*/
@ -82,6 +82,9 @@ public:
*/
virtual SkBitmap::Config config() const SK_OVERRIDE { return fBitmap.config(); }
virtual SkImageInfo imageInfo() const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
/**
* DEPRECATED: This will be made protected once WebKit stops using it.
* Instead use Canvas' writePixels method.
@ -99,7 +102,7 @@ public:
*/
virtual void writePixels(const SkBitmap& bitmap, int x, int y,
SkCanvas::Config8888 config8888) SK_OVERRIDE;
#endif
/**
* Return the device's associated gpu render target, or NULL.
*/
@ -183,7 +186,7 @@ protected:
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.
onCreateDevice on this device with kSaveLayer_Usage.
*/
virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
const SkPaint&) SK_OVERRIDE;
@ -211,9 +214,9 @@ protected:
* 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;
virtual bool onReadPixels(const SkBitmap&, int x, int y, SkCanvas::Config8888) SK_OVERRIDE;
virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) SK_OVERRIDE;
virtual void* onAccessPixels(SkImageInfo* info, size_t* rowBytes) 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.
@ -245,7 +248,7 @@ protected:
* 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 SkMatrix&,
virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter::Context&,
SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
private:
@ -258,26 +261,24 @@ private:
friend class SkSurface_Raster;
void init(SkBitmap::Config config, int width, int height, bool isOpaque);
// 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;
#ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG
// in support of legacy constructors
void init(SkBitmap::Config config, int width, int height, bool isOpaque);
#endif
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 const void* peekPixels(SkImageInfo*, size_t* rowBytes) SK_OVERRIDE;
SkBitmap fBitmap;

Просмотреть файл

@ -18,6 +18,15 @@
#include "SkRegion.h"
#include "SkXfermode.h"
// if not defined, we always assume ClipToLayer for saveLayer()
//#define SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
//#define SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
//#define SK_SUPPORT_LEGACY_GETCLIPTYPE
//#define SK_SUPPORT_LEGACY_GETTOTALCLIP
//#define SK_SUPPORT_LEGACY_GETTOPDEVICE
class SkBounder;
class SkBaseDevice;
class SkDraw;
@ -28,6 +37,7 @@ class SkRRect;
class SkSurface;
class SkSurface_Base;
class GrContext;
class GrRenderTarget;
/** \class SkCanvas
@ -48,6 +58,56 @@ class SK_API SkCanvas : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(SkCanvas)
/**
* Attempt to allocate an offscreen raster canvas, matching the ImageInfo.
* On success, return a new canvas that will draw into that offscreen.
*
* The caller can access the pixels after drawing into this canvas by
* calling readPixels() or peekPixels().
*
* If the requested ImageInfo is opaque (either the colortype is
* intrinsically opaque like RGB_565, or the info's alphatype is kOpaque)
* then the pixel memory may be uninitialized. Otherwise, the pixel memory
* will be initialized to 0, which is interpreted as transparent.
*
* On failure, return NULL. This can fail for several reasons:
* 1. the memory allocation failed (e.g. request is too large)
* 2. invalid ImageInfo (e.g. negative dimensions)
* 3. unsupported ImageInfo for a canvas
* - kUnknown_SkColorType, kIndex_8_SkColorType
* - kIgnore_SkAlphaType
* - this list is not complete, so others may also be unsupported
*
* Note: it is valid to request a supported ImageInfo, but with zero
* dimensions.
*/
static SkCanvas* NewRaster(const SkImageInfo&);
static SkCanvas* NewRasterN32(int width, int height) {
return NewRaster(SkImageInfo::MakeN32Premul(width, height));
}
/**
* Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the
* specified pixels. To access the pixels after drawing to them, the caller should call
* flush() or call peekPixels(...).
*
* On failure, return NULL. This can fail for several reasons:
* 1. invalid ImageInfo (e.g. negative dimensions)
* 2. unsupported ImageInfo for a canvas
* - kUnknown_SkColorType, kIndex_8_SkColorType
* - kIgnore_SkAlphaType
* - this list is not complete, so others may also be unsupported
*
* Note: it is valid to request a supported ImageInfo, but with zero
* dimensions.
*/
static SkCanvas* NewRasterDirect(const SkImageInfo&, void*, size_t);
static SkCanvas* NewRasterDirectN32(int width, int height, SkPMColor* pixels, size_t rowBytes) {
return NewRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
}
/**
* Creates an empty canvas with no backing device/pixels, and zero
* dimensions.
@ -76,6 +136,12 @@ public:
SkMetaData& getMetaData();
/**
* Return ImageInfo for this canvas. If the canvas is not backed by pixels
* (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
*/
SkImageInfo imageInfo() const;
///////////////////////////////////////////////////////////////////////////
/**
@ -84,16 +150,23 @@ public:
void flush();
/**
* Return the width/height of the underlying device. The current drawable
* area may be small (due to clipping or saveLayer). For a canvas with
* no device, 0,0 will be returned.
* Gets the size of the base or root layer in global canvas coordinates. The
* origin of the base layer is always (0,0). The current drawable area may be
* smaller (due to clipping or saveLayer).
*/
SkISize getDeviceSize() const;
SkISize getBaseLayerSize() const;
/** Return the canvas' device object, which may be null. The device holds
the bitmap of the pixels that the canvas draws into. The reference count
of the returned device is not changed by this call.
*/
/**
* DEPRECATED: call getBaseLayerSize
*/
SkISize getDeviceSize() const { return this->getBaseLayerSize(); }
/**
* DEPRECATED.
* Return the canvas' device object, which may be null. The device holds
* the bitmap of the pixels that the canvas draws into. The reference count
* of the returned device is not changed by this call.
*/
SkBaseDevice* getDevice() const;
/**
@ -109,7 +182,11 @@ public:
* is drawn to, but is optional here, as there is a small perf hit
* sometimes.
*/
#ifndef SK_SUPPORT_LEGACY_GETTOPDEVICE
private:
#endif
SkBaseDevice* getTopDevice(bool updateMatrixClip = false) const;
public:
/**
* Create a new surface matching the specified info, one that attempts to
@ -125,6 +202,34 @@ public:
///////////////////////////////////////////////////////////////////////////
/**
* If the canvas has writable pixels in its top layer (and is not recording to a picture
* or other non-raster target) and has direct access to its pixels (i.e. they are in
* local RAM) return the address of those pixels, and if not null,
* return the ImageInfo and rowBytes. The returned address is only valid
* while the canvas object is in scope and unchanged. Any API calls made on
* canvas (or its parent surface if any) will invalidate the
* returned address (and associated information).
*
* On failure, returns NULL and the info and rowBytes parameters are
* ignored.
*/
void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes);
/**
* If the canvas has readable pixels in its base layer (and is not recording to a picture
* or other non-raster target) and has direct access to its pixels (i.e. they are in
* local RAM) return the const-address of those pixels, and if not null,
* return the ImageInfo and rowBytes. The returned address is only valid
* while the canvas object is in scope and unchanged. Any API calls made on
* canvas (or its parent surface if any) will invalidate the
* returned address (and associated information).
*
* On failure, returns NULL and the info and rowBytes parameters are
* ignored.
*/
const void* peekPixels(SkImageInfo* info, size_t* rowBytes);
/**
* This enum can be used with read/writePixels to perform a pixel ops to or
* from an 8888 config other than Skia's native config (SkPMColor). There
@ -208,7 +313,9 @@ public:
*/
bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
#ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
/**
* DEPRECATED
* Similar to draw sprite, this method will copy the pixels in bitmap onto
* the canvas, with the top/left corner specified by (x, y). The canvas'
* pixel values are completely replaced: there is no blending.
@ -223,9 +330,34 @@ public:
* Note: If you are recording drawing commands on this canvas to
* SkPicture, writePixels() is ignored!
*/
void writePixels(const SkBitmap& bitmap,
int x, int y,
Config8888 config8888 = kNative_Premul_Config8888);
void writePixels(const SkBitmap& bitmap, int x, int y, Config8888 config8888);
#endif
/**
* This method affects the pixels in the base-layer, and operates in pixel coordinates,
* ignoring the matrix and clip.
*
* The specified ImageInfo and (x,y) offset specifies a rectangle: target.
*
* target.setXYWH(x, y, info.width(), info.height());
*
* Target is intersected with the bounds of the base-layer. If this intersection is not empty,
* then we have two sets of pixels (of equal size), the "src" specified by info+pixels+rowBytes
* and the "dst" by the canvas' backend. Replace the dst pixels with the corresponding src
* pixels, performing any colortype/alphatype transformations needed (in the case where the
* src and dst have different colortypes or alphatypes).
*
* This call can fail, returning false, for several reasons:
* - If the src colortype/alphatype cannot be converted to the canvas' types
* - If this canvas is not backed by pixels (e.g. picture or PDF)
*/
bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, int x, int y);
/**
* Helper for calling writePixels(info, ...) by passing its pixels and rowbytes. If the bitmap
* is just wrapping a texture, returns false and does nothing.
*/
bool writePixels(const SkBitmap& bitmap, int x, int y);
///////////////////////////////////////////////////////////////////////////
@ -238,12 +370,18 @@ public:
kHasAlphaLayer_SaveFlag = 0x04,
/** the layer needs to support 8-bits per color component */
kFullColorLayer_SaveFlag = 0x08,
/** the layer should clip against the bounds argument */
/**
* the layer should clip against the bounds argument
*
* if SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG is undefined, this is treated as always on.
*/
kClipToLayer_SaveFlag = 0x10,
// helper masks for common choices
kMatrixClip_SaveFlag = 0x03,
#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
kARGB_NoClipLayer_SaveFlag = 0x0F,
#endif
kARGB_ClipLayer_SaveFlag = 0x1F
};
@ -261,7 +399,7 @@ public:
by calls to save/restore.
@return The value to pass to restoreToCount() to balance this save()
*/
virtual int save(SaveFlags flags = kMatrixClip_SaveFlag);
int save(SaveFlags flags = kMatrixClip_SaveFlag);
/** This behaves the same as save(), but in addition it allocates an
offscreen bitmap. All drawing calls are directed there, and only when
@ -276,8 +414,8 @@ public:
@param flags LayerFlags
@return The value to pass to restoreToCount() to balance this save()
*/
virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags = kARGB_ClipLayer_SaveFlag);
int saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags = kARGB_ClipLayer_SaveFlag);
/** This behaves the same as save(), but in addition it allocates an
offscreen bitmap. All drawing calls are directed there, and only when
@ -299,16 +437,18 @@ public:
call.
It is an error to call restore() more times than save() was called.
*/
virtual void restore();
void restore();
/** Returns the number of matrix/clip states on the SkCanvas' private stack.
This will equal # save() calls - # restore() calls.
This will equal # save() calls - # restore() calls + 1. The save count on
a new canvas is 1.
*/
int getSaveCount() const;
/** Efficient way to pop any calls to save() that happened after the save
count reached saveCount. It is an error for saveCount to be less than
getSaveCount()
count reached saveCount. It is an error for saveCount to be greater than
getSaveCount(). To pop all the way back to the initial matrix/clip context
pass saveCount == 1.
@param saveCount The number of save() levels to restore from
*/
void restoreToCount(int saveCount);
@ -323,38 +463,38 @@ public:
@param dy The distance to translate in Y
returns true if the operation succeeded (e.g. did not overflow)
*/
virtual bool translate(SkScalar dx, SkScalar dy);
bool translate(SkScalar dx, SkScalar dy);
/** Preconcat the current matrix with the specified scale.
@param sx The amount to scale in X
@param sy The amount to scale in Y
returns true if the operation succeeded (e.g. did not overflow)
*/
virtual bool scale(SkScalar sx, SkScalar sy);
bool scale(SkScalar sx, SkScalar sy);
/** Preconcat the current matrix with the specified rotation.
@param degrees The amount to rotate, in degrees
returns true if the operation succeeded (e.g. did not overflow)
*/
virtual bool rotate(SkScalar degrees);
bool rotate(SkScalar degrees);
/** Preconcat the current matrix with the specified skew.
@param sx The amount to skew in X
@param sy The amount to skew in Y
returns true if the operation succeeded (e.g. did not overflow)
*/
virtual bool skew(SkScalar sx, SkScalar sy);
bool skew(SkScalar sx, SkScalar sy);
/** Preconcat the current matrix with the specified matrix.
@param matrix The matrix to preconcatenate with the current matrix
@return true if the operation succeeded (e.g. did not overflow)
*/
virtual bool concat(const SkMatrix& matrix);
bool concat(const SkMatrix& matrix);
/** Replace the current matrix with a copy of the specified matrix.
@param matrix The matrix that will be copied into the current matrix.
*/
virtual void setMatrix(const SkMatrix& matrix);
void setMatrix(const SkMatrix& matrix);
/** Helper for setMatrix(identity). Sets the current matrix to identity.
*/
@ -365,33 +505,30 @@ public:
* @param rect The rect to combine with the current clip
* @param op The region op to apply to the current clip
* @param doAntiAlias true if the clip should be antialiased
* @return true if the canvas' clip is non-empty
*/
virtual bool clipRect(const SkRect& rect,
SkRegion::Op op = SkRegion::kIntersect_Op,
bool doAntiAlias = false);
void clipRect(const SkRect& rect,
SkRegion::Op op = SkRegion::kIntersect_Op,
bool doAntiAlias = false);
/**
* Modify the current clip with the specified SkRRect.
* @param rrect The rrect to combine with the current clip
* @param op The region op to apply to the current clip
* @param doAntiAlias true if the clip should be antialiased
* @return true if the canvas' clip is non-empty
*/
virtual bool clipRRect(const SkRRect& rrect,
SkRegion::Op op = SkRegion::kIntersect_Op,
bool doAntiAlias = false);
void clipRRect(const SkRRect& rrect,
SkRegion::Op op = SkRegion::kIntersect_Op,
bool doAntiAlias = false);
/**
* Modify the current clip with the specified path.
* @param path The path to combine with the current clip
* @param op The region op to apply to the current clip
* @param doAntiAlias true if the clip should be antialiased
* @return true if the canvas' new clip is non-empty
*/
virtual bool clipPath(const SkPath& path,
SkRegion::Op op = SkRegion::kIntersect_Op,
bool doAntiAlias = false);
void clipPath(const SkPath& path,
SkRegion::Op op = SkRegion::kIntersect_Op,
bool doAntiAlias = false);
/** EXPERIMENTAL -- only used for testing
Set to false to force clips to be hard, even if doAntiAlias=true is
@ -414,19 +551,17 @@ public:
coordinates, and so no transformation is performed.
@param deviceRgn The region to apply to the current clip
@param op The region op to apply to the current clip
@return true if the canvas' new clip is non-empty
*/
virtual bool clipRegion(const SkRegion& deviceRgn,
SkRegion::Op op = SkRegion::kIntersect_Op);
void clipRegion(const SkRegion& deviceRgn,
SkRegion::Op op = SkRegion::kIntersect_Op);
/** Helper for clipRegion(rgn, kReplace_Op). Sets the current clip to the
specified region. This does not intersect or in any other way account
for the existing clip region.
@param deviceRgn The region to copy into the current clip.
@return true if the new clip region is non-empty
*/
bool setClipRegion(const SkRegion& deviceRgn) {
return this->clipRegion(deviceRgn, SkRegion::kReplace_Op);
void setClipRegion(const SkRegion& deviceRgn) {
this->clipRegion(deviceRgn, SkRegion::kReplace_Op);
}
/** Return true if the specified rectangle, after being transformed by the
@ -463,6 +598,20 @@ public:
*/
bool quickRejectY(SkScalar top, SkScalar bottom) const {
SkASSERT(top <= bottom);
#ifndef SK_WILL_NEVER_DRAW_PERSPECTIVE_TEXT
// TODO: add a hasPerspective method similar to getLocalClipBounds. This
// would cache the SkMatrix::hasPerspective result. Alternatively, have
// the MC stack just set a hasPerspective boolean as it is updated.
if (this->getTotalMatrix().hasPerspective()) {
// TODO: consider implementing some half-plane test between the
// two Y planes and the device-bounds (i.e., project the top and
// bottom Y planes and then determine if the clip bounds is completely
// outside either one).
return false;
}
#endif
const SkRect& clipR = this->getLocalClipBounds();
// In the case where the clip is empty and we are provided with a
// negative top and positive bottom parameter then this test will return
@ -476,13 +625,13 @@ public:
in a way similar to quickReject, in that it tells you that drawing
outside of these bounds will be clipped out.
*/
bool getClipBounds(SkRect* bounds) const;
virtual bool getClipBounds(SkRect* bounds) const;
/** Return the bounds of the current clip, in device coordinates; returns
true if non-empty. Maybe faster than getting the clip explicitly and
then taking its bounds.
*/
bool getClipDeviceBounds(SkIRect* bounds) const;
virtual bool getClipDeviceBounds(SkIRect* bounds) const;
/** Fill the entire canvas' bitmap (restricted to the current clip) with the
@ -596,8 +745,7 @@ public:
@param rect The rect to be drawn
@param paint The paint used to draw the rect
*/
void drawIRect(const SkIRect& rect, const SkPaint& paint)
{
void drawIRect(const SkIRect& rect, const SkPaint& paint) {
SkRect r;
r.set(rect); // promotes the ints to scalars
this->drawRect(r, paint);
@ -630,6 +778,12 @@ public:
*/
virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint);
/**
* Draw the annulus formed by the outer and inner rrects. The results
* are undefined if the outer does not contain the inner.
*/
void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint&);
/** Draw the specified circle using the specified paint. If radius is <= 0,
then nothing will be drawn. The circle will be filled
or framed based on the Style in the paint.
@ -829,6 +983,14 @@ public:
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint);
/** PRIVATE / EXPERIMENTAL -- do not call
Perform back-end analysis/optimization of a picture. This may attach
optimization data to the picture which can be used by a later
drawPicture call.
@param picture The recorded drawing commands to analyze/optimize
*/
void EXPERIMENTAL_optimize(SkPicture* picture);
/** Draw the picture into this canvas. This method effective brackets the
playback of the picture's draw calls with save/restore, so the state
of this canvas will be unchanged after this call.
@ -891,7 +1053,26 @@ public:
// do nothing. Subclasses may do something
}
/**
* With this call the client asserts that subsequent draw operations (up to the
* matching popCull()) are fully contained within the given bounding box. The assertion
* is not enforced, but the information might be used to quick-reject command blocks,
* so an incorrect bounding box may result in incomplete rendering.
*/
void pushCull(const SkRect& cullRect) {
++fCullCount;
this->onPushCull(cullRect);
}
/**
* Terminates the current culling block, and restores the previous one (if any).
*/
void popCull() {
if (fCullCount > 0) {
--fCullCount;
this->onPopCull();
}
}
//////////////////////////////////////////////////////////////////////////
/** Get the current bounder object.
@ -928,29 +1109,47 @@ public:
//////////////////////////////////////////////////////////////////////////
/**
* Return true if the current clip is empty (i.e. nothing will draw).
* Note: this is not always a free call, so it should not be used
* more often than necessary. However, once the canvas has computed this
* result, subsequent calls will be cheap (until the clip state changes,
* which can happen on any clip..() or restore() call.
*/
virtual bool isClipEmpty() const;
/**
* Returns true if the current clip is just a (non-empty) rectangle.
* Returns false if the clip is empty, or if it is complex.
*/
virtual bool isClipRect() const;
/** Return the current matrix on the canvas.
This does not account for the translate in any of the devices.
@return The current matrix on the canvas.
*/
const SkMatrix& getTotalMatrix() const;
#ifdef SK_SUPPORT_LEGACY_GETCLIPTYPE
enum ClipType {
kEmpty_ClipType = 0,
kRect_ClipType,
kComplex_ClipType
};
/** Returns a description of the total clip; may be cheaper than
getting the clip and querying it directly.
*/
ClipType getClipType() const;
virtual ClipType getClipType() const;
#endif
#ifdef SK_SUPPORT_LEGACY_GETTOTALCLIP
/** DEPRECATED -- need to move this guy to private/friend
* Return the current device clip (concatenation of all clip calls).
* This does not account for the translate in any of the devices.
* @return the current device clip (concatenation of all clip calls).
*/
const SkRegion& getTotalClip() const;
#endif
/** Return the clip stack. The clip stack stores all the individual
* clips organized by the save/restore frame in which they were
@ -965,6 +1164,7 @@ public:
public:
virtual ~ClipVisitor();
virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0;
virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0;
virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0;
};
@ -1015,10 +1215,51 @@ public:
bool fDone;
};
// don't call
const SkRegion& internal_private_getTotalClip() const;
// don't call
void internal_private_getTotalClipAsPath(SkPath*) const;
// don't call
GrRenderTarget* internal_private_accessTopLayerRenderTarget();
protected:
// default impl defers to getDevice()->newSurface(info)
virtual SkSurface* onNewSurface(const SkImageInfo&);
// default impl defers to its device
virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes);
virtual void* onAccessTopLayerPixels(SkImageInfo*, size_t* rowBytes);
// Subclass save/restore notifiers.
// Overriders should call the corresponding INHERITED method up the inheritance chain.
// willSaveLayer()'s return value may suppress full layer allocation.
enum SaveLayerStrategy {
kFullLayer_SaveLayerStrategy,
kNoLayer_SaveLayerStrategy
};
virtual void willSave(SaveFlags);
virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags);
virtual void willRestore();
virtual void didTranslate(SkScalar, SkScalar);
virtual void didScale(SkScalar, SkScalar);
virtual void didRotate(SkScalar);
virtual void didSkew(SkScalar, SkScalar);
virtual void didConcat(const SkMatrix&);
virtual void didSetMatrix(const SkMatrix&);
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&);
enum ClipEdgeStyle {
kHard_ClipEdgeStyle,
kSoft_ClipEdgeStyle
};
virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle);
virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle);
virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle);
virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op);
// Returns the canvas to be used by DrawIter. Default implementation
// returns this. Subclasses that encapsulate an indirect canvas may
// need to overload this method. The impl must keep track of this, as it
@ -1035,23 +1276,15 @@ protected:
// Called by child classes that override clipPath and clipRRect to only
// track fast conservative clip bounds, rather than exact clips.
bool updateClipConservativelyUsingBounds(const SkRect&, SkRegion::Op,
void updateClipConservativelyUsingBounds(const SkRect&, SkRegion::Op,
bool inverseFilled);
// notify our surface (if we have one) that we are about to draw, so it
// can perform copy-on-write or invalidate any cached images
void predrawNotify();
/**
DEPRECATED -- need to remove when subclass stop relying on it.
Marked as 'protected' to avoid new clients using this before we can
completely remove it.
Specify a device for this canvas to draw into. If it is not null, its
reference count is incremented. If the canvas was already holding a
device, its reference count is decremented. The new device is returned.
*/
virtual SkBaseDevice* setDevice(SkBaseDevice* device);
virtual void onPushCull(const SkRect& cullRect);
virtual void onPopCull();
private:
class MCRec;
@ -1065,6 +1298,7 @@ private:
SkBounder* fBounder;
int fSaveLayerCount; // number of successful saveLayer calls
int fCullCount; // number of active culls
SkMetaData* fMetaData;
@ -1079,14 +1313,31 @@ private:
bool fDeviceCMDirty; // cleared by updateDeviceCMCache()
void updateDeviceCMCache();
friend class SkDrawIter; // needs setupDrawForLayerDevice()
friend class SkDrawIter; // needs setupDrawForLayerDevice()
friend class AutoDrawLooper;
friend class SkLua; // needs top layer size and offset
friend class SkDeferredDevice; // needs getTopDevice()
SkBaseDevice* createLayerDevice(SkBitmap::Config, int width, int height,
bool isOpaque);
SkBaseDevice* createLayerDevice(const SkImageInfo&);
SkBaseDevice* init(SkBaseDevice*);
/**
* DEPRECATED
*
* Specify a device for this canvas to draw into. If it is not null, its
* reference count is incremented. If the canvas was already holding a
* device, its reference count is decremented. The new device is returned.
*/
SkBaseDevice* setRootDevice(SkBaseDevice* device);
/**
* Gets the size/origin of the top level layer in global canvas coordinates. We don't want this
* to be public because it exposes decisions about layer sizes that are internal to the canvas.
*/
SkISize getTopLayerSize() const;
SkIPoint getTopLayerOrigin() const;
// internal methods are not virtual, so they can safely be called by other
// canvas apis, without confusing subclasses (like SkPictureRecording)
void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* paint);
@ -1097,7 +1348,7 @@ private:
const SkRect& dst, const SkPaint* paint);
void internalDrawPaint(const SkPaint& paint);
int internalSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags, bool justForImageFilter);
SaveFlags, bool justForImageFilter, SaveLayerStrategy strategy);
void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*);
// shared by save() and saveLayer()
@ -1206,4 +1457,47 @@ private:
};
#define SkAutoCommentBlock(...) SK_REQUIRE_LOCAL_VAR(SkAutoCommentBlock)
/**
* If the caller wants read-only access to the pixels in a canvas, it can just
* call canvas->peekPixels(), since that is the fastest way to "peek" at the
* pixels on a raster-backed canvas.
*
* If the canvas has pixels, but they are not readily available to the CPU
* (e.g. gpu-backed), then peekPixels() will fail, but readPixels() will
* succeed (though be slower, since it will return a copy of the pixels).
*
* SkAutoROCanvasPixels encapsulates these two techniques, trying first to call
* peekPixels() (for performance), but if that fails, calling readPixels() and
* storing the copy locally.
*
* The caller must respect the restrictions associated with peekPixels(), since
* that may have been called: The returned information is invalidated if...
* - any API is called on the canvas (or its parent surface if present)
* - the canvas goes out of scope
*/
class SkAutoROCanvasPixels : SkNoncopyable {
public:
SkAutoROCanvasPixels(SkCanvas* canvas);
// returns NULL on failure
const void* addr() const { return fAddr; }
// undefined if addr() == NULL
size_t rowBytes() const { return fRowBytes; }
// undefined if addr() == NULL
const SkImageInfo& info() const { return fInfo; }
// helper that, if returns true, installs the pixels into the bitmap. Note
// that the bitmap may reference the address returned by peekPixels(), so
// the caller must respect the restrictions associated with peekPixels().
bool asROBitmap(SkBitmap*) const;
private:
SkBitmap fBitmap; // used if peekPixels() fails
const void* fAddr; // NULL on failure
SkImageInfo fInfo;
size_t fRowBytes;
};
#endif

Просмотреть файл

@ -11,8 +11,10 @@
#include "SkDeque.h"
#include "SkPath.h"
#include "SkRect.h"
#include "SkRRect.h"
#include "SkRegion.h"
#include "SkTDArray.h"
#include "SkTLazy.h"
// Because a single save/restore state can have multiple clips, this class
@ -41,6 +43,8 @@ public:
kEmpty_Type,
//!< This element combines a rect with the current clip using a set operation
kRect_Type,
//!< This element combines a round-rect with the current clip using a set operation
kRRect_Type,
//!< This element combines a path with the current clip using a set operation
kPath_Type,
};
@ -50,50 +54,44 @@ public:
this->setEmpty();
}
Element(const Element&);
Element(const SkRect& rect, SkRegion::Op op, bool doAA) {
this->initRect(0, rect, op, doAA);
}
Element(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
this->initRRect(0, rrect, op, doAA);
}
Element(const SkPath& path, SkRegion::Op op, bool doAA) {
this->initPath(0, path, op, doAA);
}
bool operator== (const Element& element) const {
if (this == &element) {
return true;
}
if (fOp != element.fOp ||
fType != element.fType ||
fDoAA != element.fDoAA ||
fSaveCount != element.fSaveCount) {
return false;
}
switch (fType) {
case kPath_Type:
return fPath == element.fPath;
case kRect_Type:
return fRect == element.fRect;
case kEmpty_Type:
return true;
default:
SkDEBUGFAIL("Unexpected type.");
return false;
}
}
bool operator== (const Element& element) const;
bool operator!= (const Element& element) const { return !(*this == element); }
//!< Call to get the type of the clip element.
Type getType() const { return fType; }
//!< Call if getType() is kPath to get the path.
const SkPath& getPath() const { return fPath; }
const SkPath& getPath() const { SkASSERT(kPath_Type == fType); return *fPath.get(); }
//!< Call if getType() is kRRect to get the round-rect.
const SkRRect& getRRect() const { SkASSERT(kRRect_Type == fType); return fRRect; }
//!< Call if getType() is kRect to get the rect.
const SkRect& getRect() const { return fRect; }
const SkRect& getRect() const {
SkASSERT(kRect_Type == fType && (fRRect.isRect() || fRRect.isEmpty()));
return fRRect.getBounds();
}
//!< Call if getType() is not kEmpty to get the set operation used to combine this element.
SkRegion::Op getOp() const { return fOp; }
//!< Call to get the element as a path, regardless of its type.
void asPath(SkPath* path) const;
/** If getType() is not kEmpty this indicates whether the clip shape should be anti-aliased
when it is rasterized. */
bool isAA() const { return fDoAA; }
@ -118,10 +116,11 @@ public:
const SkRect& getBounds() const {
static const SkRect kEmpty = { 0, 0, 0, 0 };
switch (fType) {
case kRect_Type:
return fRect;
case kRect_Type: // fallthrough
case kRRect_Type:
return fRRect.getBounds();
case kPath_Type:
return fPath.getBounds();
return fPath.get()->getBounds();
case kEmpty_Type:
return kEmpty;
default:
@ -137,9 +136,11 @@ public:
bool contains(const SkRect& rect) const {
switch (fType) {
case kRect_Type:
return fRect.contains(rect);
return this->getRect().contains(rect);
case kRRect_Type:
return fRRect.contains(rect);
case kPath_Type:
return fPath.conservativelyContainsRect(rect);
return fPath.get()->conservativelyContainsRect(rect);
case kEmpty_Type:
return false;
default:
@ -152,14 +153,14 @@ public:
* Is the clip shape inverse filled.
*/
bool isInverseFilled() const {
return kPath_Type == fType && fPath.isInverseFillType();
return kPath_Type == fType && fPath.get()->isInverseFillType();
}
private:
friend class SkClipStack;
SkPath fPath;
SkRect fRect;
SkTLazy<SkPath> fPath;
SkRRect fRRect;
int fSaveCount; // save count of stack when this element was added.
SkRegion::Op fOp;
Type fType;
@ -189,6 +190,10 @@ public:
this->setEmpty();
}
Element(int saveCount, const SkRRect& rrect, SkRegion::Op op, bool doAA) {
this->initRRect(saveCount, rrect, op, doAA);
}
Element(int saveCount, const SkRect& rect, SkRegion::Op op, bool doAA) {
this->initRect(saveCount, rect, op, doAA);
}
@ -210,26 +215,25 @@ public:
}
void initRect(int saveCount, const SkRect& rect, SkRegion::Op op, bool doAA) {
fRect = rect;
fRRect.setRect(rect);
fType = kRect_Type;
this->initCommon(saveCount, op, doAA);
}
void initPath(int saveCount, const SkPath& path, SkRegion::Op op, bool doAA) {
fPath = path;
fType = kPath_Type;
void initRRect(int saveCount, const SkRRect& rrect, SkRegion::Op op, bool doAA) {
SkRRect::Type type = rrect.getType();
fRRect = rrect;
if (SkRRect::kRect_Type == type || SkRRect::kEmpty_Type == type) {
fType = kRect_Type;
} else {
fType = kRRect_Type;
}
this->initCommon(saveCount, op, doAA);
}
void setEmpty() {
fType = kEmpty_Type;
fFiniteBound.setEmpty();
fFiniteBoundType = kNormal_BoundsType;
fIsIntersectionOfRects = false;
fRect.setEmpty();
fPath.reset();
fGenID = kEmptyGenID;
}
void initPath(int saveCount, const SkPath& path, SkRegion::Op op, bool doAA);
void setEmpty();
// All Element methods below are only used within SkClipStack.cpp
inline void checkEmpty() const;
@ -305,6 +309,7 @@ public:
this->clipDevRect(r, op, false);
}
void clipDevRect(const SkRect&, SkRegion::Op, bool doAA);
void clipDevRRect(const SkRRect&, SkRegion::Op, bool doAA);
void clipDevPath(const SkPath&, SkRegion::Op, bool doAA);
// An optimized version of clipDevRect(emptyRect, kIntersect, ...)
void clipEmpty();
@ -427,6 +432,11 @@ private:
// invalid ID.
static int32_t gGenID;
/**
* Helper for clipDevPath, etc.
*/
void pushElement(const Element& element);
/**
* Restore the stack back to the specified save count.
*/

Просмотреть файл

@ -128,7 +128,7 @@ public:
*/
virtual GrEffectRef* asNewEffect(GrContext*) const;
SkDEVCODE(virtual void toString(SkString* str) const = 0;)
SK_TO_STRING_PUREVIRT()
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
SK_DEFINE_FLATTENABLE_TYPE(SkColorFilter)

Просмотреть файл

@ -48,7 +48,7 @@ public:
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader)
protected:

Просмотреть файл

@ -39,7 +39,7 @@ public:
virtual void endContext() SK_OVERRIDE;
virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeShader)
protected:

Просмотреть файл

@ -15,6 +15,14 @@
#include "SkCanvas.h"
#include "SkColor.h"
#include "SkDeviceProperties.h"
#include "SkImageFilter.h"
// getDeviceCapabilities() is not called by skia, but this flag keeps it around
// for clients that have "override" annotations on their subclass. These overrides
// should be deleted.
//#define SK_SUPPORT_LEGACY_GETDEVICECAPABILITIES
//#define SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG
class SkClipStack;
class SkDraw;
@ -41,6 +49,7 @@ public:
virtual ~SkBaseDevice();
#ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG
/**
* Creates a device that is of the same type as this device (e.g. SW-raster,
* GPU, or PDF). The backing store for this device is created automatically
@ -55,13 +64,17 @@ public:
SkBaseDevice* createCompatibleDevice(SkBitmap::Config config,
int width, int height,
bool isOpaque);
#endif
SkBaseDevice* createCompatibleDevice(const SkImageInfo&);
SkMetaData& getMetaData();
#ifdef SK_SUPPORT_LEGACY_GETDEVICECAPABILITIES
enum Capabilities {
kVector_Capability = 0x1, //!< mask indicating a vector representation
kVector_Capability = 0x1,
};
virtual uint32_t getDeviceCapabilities() = 0;
virtual uint32_t getDeviceCapabilities() { return 0; }
#endif
/** Return the width of the device (in pixels).
*/
@ -76,6 +89,12 @@ public:
return fLeakyProperties;
}
/**
* Return ImageInfo for this device. If the canvas is not backed by pixels
* (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
*/
virtual SkImageInfo imageInfo() const;
/**
* 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
@ -95,7 +114,6 @@ public:
/** Return the bitmap config of the device's pixels
*/
SK_ATTR_DEPRECATED("want to hide configness of the device -- don't use")
virtual SkBitmap::Config config() const = 0;
/** Return the bitmap associated with this device. Call this each time you need
@ -106,6 +124,7 @@ public:
*/
const SkBitmap& accessBitmap(bool changePixels);
#ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
/**
* DEPRECATED: This will be made protected once WebKit stops using it.
* Instead use Canvas' writePixels method.
@ -122,7 +141,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) = 0;
SkCanvas::Config8888 config8888 = SkCanvas::kNative_Premul_Config8888);
#endif
bool writePixelsDirect(const SkImageInfo&, const void*, size_t rowBytes, int x, int y);
void* accessPixels(SkImageInfo* info, size_t* rowBytes);
/**
* Return the device's associated gpu render target, or NULL.
@ -227,6 +251,10 @@ protected:
virtual void drawRRect(const SkDraw&, const SkRRect& rr,
const SkPaint& paint) = 0;
// Default impl calls drawPath()
virtual void drawDRRect(const SkDraw&, const SkRRect& outer,
const SkRRect& inner, const SkPaint&);
/**
* If pathIsMutable, then the implementation is allowed to cast path to a
* non-const pointer and modify it in place (as an optimization). Canvas
@ -274,7 +302,7 @@ protected:
const uint16_t indices[], int indexCount,
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.
onCreateDevice on this device with kSaveLayer_Usage.
*/
virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
const SkPaint&) = 0;
@ -318,17 +346,6 @@ protected:
*/
virtual const SkBitmap& onAccessBitmap() = 0;
/**
* 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) = 0;
/** Called when this device is installed into a Canvas. Balanced by a call
to unlockPixels() when the device is removed from a Canvas.
*/
@ -359,7 +376,8 @@ protected:
* 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 SkMatrix&,
virtual bool filterImage(const SkImageFilter*, const SkBitmap&,
const SkImageFilter::Context& ctx,
SkBitmap* result, SkIPoint* offset) = 0;
// This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if
@ -370,6 +388,33 @@ protected:
// default impl returns NULL
virtual SkSurface* newSurface(const SkImageInfo&);
// default impl returns NULL
virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes);
/**
* 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);
/**
* The caller is responsible for "pre-clipping" the src. The impl can assume that the src
* image at the specified x,y offset will fit within the device's bounds.
*
* This is explicitly asserted in writePixelsDirect(), the public way to call this.
*/
virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int x, int y);
/**
* Default impl returns NULL.
*/
virtual void* onAccessPixels(SkImageInfo* info, size_t* rowBytes);
/**
* Leaky properties are those which the device should be applying but it isn't.
* These properties will be applied by the draw, when and as it can.
@ -378,6 +423,24 @@ protected:
*/
SkDeviceProperties fLeakyProperties;
/**
* PRIVATE / EXPERIMENTAL -- do not call
* Construct an acceleration object and attach it to 'picture'
*/
virtual void EXPERIMENTAL_optimize(SkPicture* picture);
/**
* PRIVATE / EXPERIMENTAL -- do not call
* This entry point gives the backend an opportunity to take over the rendering
* of 'picture'. If optimization data is available (due to an earlier
* 'optimize' call) this entry point should make use of it and return true
* if all rendering has been done. If false is returned, SkCanvas will
* perform its own rendering pass. It is acceptable for the backend
* to perform some device-specific warm up tasks and then let SkCanvas
* perform the main rendering loop (by return false from here).
*/
virtual bool EXPERIMENTAL_drawPicture(const SkPicture& picture);
private:
friend class SkCanvas;
friend struct DeviceCM; //for setMatrixClip
@ -385,7 +448,7 @@ private:
friend class SkDrawIter;
friend class SkDeviceFilteredPaint;
friend class SkDeviceImageFilterProxy;
friend class DeferredDevice; // for newSurface
friend class SkDeferredDevice; // for newSurface
friend class SkSurface_Raster;
@ -398,17 +461,23 @@ private:
// 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
SkBaseDevice* createCompatibleDeviceForSaveLayer(SkBitmap::Config config,
int width, int height,
bool isOpaque);
SkBaseDevice* createCompatibleDeviceForSaveLayer(const SkImageInfo&);
#ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG
/**
* Subclasses should override this to implement createCompatibleDevice.
* Justs exists during the period where clients still "override" this
* signature. They are supported by our base-impl calling this old
* signature from the new one (using ImageInfo).
*/
virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config,
int width, int height,
bool isOpaque,
Usage usage) = 0;
bool isOpaque, Usage) {
return NULL;
}
#endif
virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) {
return NULL;
}
/** Causes any deferred drawing to the device to be completed.
*/

Просмотреть файл

@ -30,24 +30,49 @@ public:
SK_DECLARE_INST_COUNT(SkDrawLooper)
/**
* Called right before something is being drawn. This will be followed by
* calls to next() until next() returns false.
* Holds state during a draw. Users call next() until it returns false.
*
* Subclasses of SkDrawLooper should create a subclass of this object to
* hold state specific to their subclass.
*/
virtual void init(SkCanvas*) = 0;
class SK_API Context : public SkNoncopyable {
public:
Context() {}
virtual ~Context() {}
/**
* Called in a loop on objects returned by SkDrawLooper::createContext().
* Each time true is returned, the object is drawn (possibly with a modified
* canvas and/or paint). When false is finally returned, drawing for the object
* stops.
*
* On each call, the paint will be in its original state, but the
* canvas will be as it was following the previous call to next() or
* createContext().
*
* The implementation must ensure that, when next() finally returns
* false, the canvas has been restored to the state it was
* initially, before createContext() was first called.
*/
virtual bool next(SkCanvas* canvas, SkPaint* paint) = 0;
};
/**
* Called in a loop (after init()). Each time true is returned, the object
* is drawn (possibly with a modified canvas and/or paint). When false is
* finally returned, drawing for the object stops.
*
* On each call, the paint will be in its original state, but the canvas
* will be as it was following the previous call to next() or init().
*
* The implementation must ensure that, when next() finally returns false,
* that the canvas has been restored to the state it was initially, before
* init() was first called.
* Called right before something is being drawn. Returns a Context
* whose next() method should be called until it returns false.
* The caller has to ensure that the storage pointer provides enough
* memory for the Context. The required size can be queried by calling
* contextSize(). It is also the caller's responsibility to destroy the
* object after use.
*/
virtual bool next(SkCanvas*, SkPaint* paint) = 0;
virtual Context* createContext(SkCanvas*, void* storage) const = 0;
/**
* Returns the number of bytes needed to store subclasses of Context (belonging to the
* corresponding SkDrawLooper subclass).
*/
virtual size_t contextSize() const = 0;
/**
* The fast bounds functions are used to enable the paint to be culled early
@ -59,11 +84,11 @@ public:
* storage rect, where the storage rect is with the union of the src rect
* and the looper's bounding rect.
*/
virtual bool canComputeFastBounds(const SkPaint& paint);
virtual bool canComputeFastBounds(const SkPaint& paint) const;
virtual void computeFastBounds(const SkPaint& paint,
const SkRect& src, SkRect* dst);
const SkRect& src, SkRect* dst) const;
SkDEVCODE(virtual void toString(SkString* str) const = 0;)
SK_TO_STRING_PUREVIRT()
SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper)
protected:

Просмотреть файл

@ -30,7 +30,7 @@ public:
virtual void shadeSpan16(int x, int y, uint16_t span[], int count) SK_OVERRIDE;
virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkEmptyShader)
protected:

Просмотреть файл

@ -255,6 +255,15 @@ struct SkConic {
void computeTightBounds(SkRect* bounds) const;
void computeFastBounds(SkRect* bounds) const;
/** Find the parameter value where the conic takes on its maximum curvature.
*
* @param t output scalar for max curvature. Will be unchanged if
* max curvature outside 0..1 range.
*
* @return true if max curvature found inside 0..1 range, false otherwise
*/
bool findMaxCurvature(SkScalar* t) const;
};
#include "SkTemplates.h"

Просмотреть файл

@ -9,12 +9,12 @@
#define SkImageFilter_DEFINED
#include "SkFlattenable.h"
#include "SkMatrix.h"
#include "SkRect.h"
class SkBitmap;
class SkColorFilter;
class SkBaseDevice;
class SkMatrix;
struct SkIPoint;
class SkShader;
class GrEffectRef;
@ -49,6 +49,18 @@ public:
uint32_t fFlags;
};
class Context {
public:
Context(const SkMatrix& ctm, const SkIRect& clipBounds) :
fCTM(ctm), fClipBounds(clipBounds) {
}
const SkMatrix& ctm() const { return fCTM; }
const SkIRect& clipBounds() const { return fClipBounds; }
private:
SkMatrix fCTM;
SkIRect fClipBounds;
};
class Proxy {
public:
virtual ~Proxy() {};
@ -59,7 +71,7 @@ public:
// returns true if the proxy handled the filter itself. if this returns
// false then the filter's code will be called.
virtual bool filterImage(const SkImageFilter*, const SkBitmap& src,
const SkMatrix& ctm,
const Context&,
SkBitmap* result, SkIPoint* offset) = 0;
};
@ -76,7 +88,7 @@ public:
* If the result image cannot be created, return false, in which case both
* the result and offset parameters will be ignored by the caller.
*/
bool filterImage(Proxy*, const SkBitmap& src, const SkMatrix& ctm,
bool filterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const;
/**
@ -104,7 +116,7 @@ public:
* relative to the src when it is drawn. The default implementation does
* single-pass processing using asNewEffect().
*/
virtual bool filterImageGPU(Proxy*, const SkBitmap& src, const SkMatrix& ctm,
virtual bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const;
/**
@ -146,6 +158,20 @@ public:
// Default impl returns union of all input bounds.
virtual void computeFastBounds(const SkRect&, SkRect*) const;
#ifdef SK_SUPPORT_GPU
/**
* Wrap the given texture in a texture-backed SkBitmap.
*/
static void WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result);
/**
* Recursively evaluate this filter on the GPU. If the filter has no GPU
* implementation, it will be processed in software and uploaded to the GPU.
*/
bool getInputResultGPU(SkImageFilter::Proxy* proxy, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const;
#endif
SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter)
protected:
@ -186,7 +212,7 @@ protected:
* case both the result and offset parameters will be ignored by the
* caller.
*/
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const;
// Given the bounds of the destination rect to be filled in device
// coordinates (first parameter), and the CTM, compute (conservatively)
@ -197,10 +223,25 @@ protected:
// no inputs.
virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) const;
// Applies "matrix" to the crop rect, and sets "rect" to the intersection of
// "rect" and the transformed crop rect. If there is no overlap, returns
// false and leaves "rect" unchanged.
bool applyCropRect(SkIRect* rect, const SkMatrix& matrix) const;
/** Computes source bounds as the src bitmap bounds offset by srcOffset.
* Apply the transformed crop rect to the bounds if any of the
* corresponding edge flags are set. Intersects the result against the
* context's clipBounds, and returns the result in "bounds". If there is
* no intersection, returns false and leaves "bounds" unchanged.
*/
bool applyCropRect(const Context&, const SkBitmap& src, const SkIPoint& srcOffset,
SkIRect* bounds) const;
/** Same as the above call, except that if the resulting crop rect is not
* entirely contained by the source bitmap's bounds, it creates a new
* bitmap in "result" and pads the edges with transparent black. In that
* case, the srcOffset is modified to be the same as the bounds, since no
* further adjustment is needed by the caller. This version should only
* be used by filters which are not capable of processing a smaller
* source bitmap into a larger destination.
*/
bool applyCropRect(const Context&, Proxy* proxy, const SkBitmap& src, SkIPoint* srcOffset,
SkIRect* bounds, SkBitmap* result) const;
/**
* Returns true if the filter can be expressed a single-pass
@ -222,6 +263,7 @@ protected:
const SkMatrix& matrix,
const SkIRect& bounds) const;
private:
typedef SkFlattenable INHERITED;
int fInputCount;

Просмотреть файл

@ -1,38 +0,0 @@
/*
* Copyright 2013 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkImageFilterUtils_DEFINED
#define SkImageFilterUtils_DEFINED
#if SK_SUPPORT_GPU
#include "SkImageFilter.h"
class SkBitmap;
class GrTexture;
class SkImageFilter;
class SK_API SkImageFilterUtils {
public:
/**
* Wrap the given texture in a texture-backed SkBitmap.
*/
static bool WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result);
/**
* Recursively evaluate the given filter on the GPU. If filter is NULL,
* this function returns src. If the filter has no GPU implementation, it
* will be processed in software and uploaded to the GPU.
*/
static bool GetInputResultGPU(const SkImageFilter* filter, SkImageFilter::Proxy* proxy,
const SkBitmap& src, const SkMatrix& ctm, SkBitmap* result,
SkIPoint* offset);
};
#endif
#endif

Просмотреть файл

@ -165,6 +165,13 @@ struct SkImageInfo {
return info;
}
static SkImageInfo MakeUnknown(int width, int height) {
SkImageInfo info = {
width, height, kUnknown_SkColorType, kIgnore_SkAlphaType
};
return info;
}
int width() const { return fWidth; }
int height() const { return fHeight; }
SkColorType colorType() const { return fColorType; }

Просмотреть файл

@ -40,8 +40,6 @@ class SK_API SkMaskFilter : public SkFlattenable {
public:
SK_DECLARE_INST_COUNT(SkMaskFilter)
SkMaskFilter() {}
/** Returns the format of the resulting mask that this subclass will return
when its filterMask() method is called.
*/
@ -103,6 +101,14 @@ public:
GrPaint* grp,
const SkStrokeRec& strokeRec,
const SkPath& path) const;
/**
* Try to directly render a rounded rect mask filter into the target. Returns
* true if drawing was successful.
*/
virtual bool directFilterRRectMaskGPU(GrContext* context,
GrPaint* grp,
const SkStrokeRec& strokeRec,
const SkRRect& rrect) const;
/**
* This function is used to implement filters that require an explicit src mask. It should only
@ -132,10 +138,11 @@ public:
*/
virtual void computeFastBounds(const SkRect& src, SkRect* dest) const;
SkDEVCODE(virtual void toString(SkString* str) const = 0;)
SK_TO_STRING_PUREVIRT()
SK_DEFINE_FLATTENABLE_TYPE(SkMaskFilter)
protected:
SkMaskFilter() {}
// empty for now, but lets get our subclass to remember to init us for the future
SkMaskFilter(SkReadBuffer& buffer) : INHERITED(buffer) {}

Просмотреть файл

@ -560,7 +560,7 @@ public:
size_t readFromMemory(const void* buffer, size_t length);
SkDEVCODE(void dump() const;)
SkDEVCODE(void toString(SkString*) const;)
SK_TO_STRING_NONVIRT()
/**
* Calculates the minimum stretching factor of the matrix. If the matrix has

Просмотреть файл

@ -118,6 +118,8 @@ public:
kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter
kVerticalText_Flag = 0x1000,
kGenA8FromLCD_Flag = 0x2000, // hack for GDI -- do not use if you can help it
kDistanceFieldTextTEMP_Flag = 0x4000, //!< TEMPORARY mask to enable distance fields
// currently overrides LCD and subpixel rendering
// when adding extra flags, note that the fFlags member is specified
// with a bit-width and you'll have to expand it.
@ -284,6 +286,19 @@ public:
*/
void setDevKernText(bool devKernText);
/** Helper for getFlags(), returns true if kDistanceFieldTextTEMP_Flag bit is set
@return true if the distanceFieldText bit is set in the paint's flags.
*/
bool isDistanceFieldTextTEMP() const {
return SkToBool(this->getFlags() & kDistanceFieldTextTEMP_Flag);
}
/** Helper for setFlags(), setting or clearing the kDistanceFieldTextTEMP_Flag bit
@param distanceFieldText true to set the kDistanceFieldTextTEMP_Flag bit in the paint's
flags, false to clear it.
*/
void setDistanceFieldTextTEMP(bool distanceFieldText);
enum FilterLevel {
kNone_FilterLevel,
kLow_FilterLevel,
@ -731,17 +746,60 @@ public:
void setTextEncoding(TextEncoding encoding);
struct FontMetrics {
/** Flags which indicate the confidence level of various metrics.
A set flag indicates that the metric may be trusted.
*/
enum FontMetricsFlags {
kUnderlineThinknessIsValid_Flag = 1 << 0,
kUnderlinePositionIsValid_Flag = 1 << 1,
};
uint32_t fFlags; //!< Bit field to identify which values are unknown
SkScalar fTop; //!< The greatest distance above the baseline for any glyph (will be <= 0)
SkScalar fAscent; //!< The recommended distance above the baseline (will be <= 0)
SkScalar fDescent; //!< The recommended distance below the baseline (will be >= 0)
SkScalar fBottom; //!< The greatest distance below the baseline for any glyph (will be >= 0)
SkScalar fLeading; //!< The recommended distance to add between lines of text (will be >= 0)
SkScalar fAvgCharWidth; //!< the average charactor width (>= 0)
SkScalar fMaxCharWidth; //!< the max charactor width (>= 0)
SkScalar fAvgCharWidth; //!< the average character width (>= 0)
SkScalar fMaxCharWidth; //!< the max character width (>= 0)
SkScalar fXMin; //!< The minimum bounding box x value for all glyphs
SkScalar fXMax; //!< The maximum bounding box x value for all glyphs
SkScalar fXHeight; //!< The height of an 'x' in px, or 0 if no 'x' in face
SkScalar fCapHeight; //!< The cap height (> 0), or 0 if cannot be determined.
SkScalar fUnderlineThickness; //!< underline thickness, or 0 if cannot be determined
/** Underline Position - position of the top of the Underline stroke
relative to the baseline, this can have following values
- Negative - means underline should be drawn above baseline.
- Positive - means below baseline.
- Zero - mean underline should be drawn on baseline.
*/
SkScalar fUnderlinePosition; //!< underline position, or 0 if cannot be determined
/** If the fontmetrics has a valid underlinethickness, return true, and set the
thickness param to that value. If it doesn't return false and ignore the
thickness param.
*/
bool hasUnderlineThickness(SkScalar* thickness) const {
if (SkToBool(fFlags & kUnderlineThinknessIsValid_Flag)) {
*thickness = fUnderlineThickness;
return true;
}
return false;
}
/** If the fontmetrics has a valid underlineposition, return true, and set the
thickness param to that value. If it doesn't return false and ignore the
thickness param.
*/
bool hasUnderlinePosition(SkScalar* position) const {
if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
*position = fUnderlinePosition;
return true;
}
return false;
}
};
/** Return the recommend spacing between lines (which will be
@ -880,10 +938,6 @@ public:
const SkPoint pos[], SkPath* path) const;
#ifdef SK_BUILD_FOR_ANDROID
const SkGlyph& getUnicharMetrics(SkUnichar, const SkMatrix*);
const SkGlyph& getGlyphMetrics(uint16_t, const SkMatrix*);
const void* findImage(const SkGlyph&, const SkMatrix*);
uint32_t getGenerationID() const;
void setGenerationID(uint32_t generationID);
@ -978,7 +1032,12 @@ public:
return SetTextMatrix(matrix, fTextSize, fTextScaleX, fTextSkewX);
}
SkDEVCODE(void toString(SkString*) const;)
SK_TO_STRING_NONVIRT()
struct FlatteningTraits {
static void Flatten(SkWriteBuffer& buffer, const SkPaint& paint);
static void Unflatten(SkReadBuffer& buffer, SkPaint* paint);
};
private:
SkTypeface* fTypeface;
@ -999,16 +1058,25 @@ private:
SkColor fColor;
SkScalar fWidth;
SkScalar fMiterLimit;
// all of these bitfields should add up to 32
unsigned fFlags : 16;
unsigned fTextAlign : 2;
unsigned fCapType : 2;
unsigned fJoinType : 2;
unsigned fStyle : 2;
unsigned fTextEncoding : 2; // 3 values
unsigned fHinting : 2;
//unsigned fFreeBits : 4;
union {
struct {
// all of these bitfields should add up to 32
unsigned fFlags : 16;
unsigned fTextAlign : 2;
unsigned fCapType : 2;
unsigned fJoinType : 2;
unsigned fStyle : 2;
unsigned fTextEncoding : 2; // 3 values
unsigned fHinting : 2;
//unsigned fFreeBits : 4;
};
uint32_t fBitfields;
};
uint32_t getBitfields() const { return fBitfields; }
void setBitfields(uint32_t bitfields);
uint32_t fDirtyBits;
SkDrawCacheProc getDrawCacheProc() const;
SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir,

Просмотреть файл

@ -31,8 +31,6 @@ class SK_API SkPathEffect : public SkFlattenable {
public:
SK_DECLARE_INST_COUNT(SkPathEffect)
SkPathEffect() {}
/**
* Given a src path (input) and a stroke-rec (input and output), apply
* this effect to the src path, returning the new path in dst, and return
@ -109,6 +107,7 @@ public:
SK_DEFINE_FLATTENABLE_TYPE(SkPathEffect)
protected:
SkPathEffect() {}
SkPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {}
private:
@ -127,10 +126,10 @@ private:
*/
class SkPairPathEffect : public SkPathEffect {
public:
SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1);
virtual ~SkPairPathEffect();
protected:
SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1);
SkPairPathEffect(SkReadBuffer&);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
@ -153,8 +152,9 @@ public:
The reference counts for outer and inner are both incremented in the constructor,
and decremented in the destructor.
*/
SkComposePathEffect(SkPathEffect* outer, SkPathEffect* inner)
: INHERITED(outer, inner) {}
static SkComposePathEffect* Create(SkPathEffect* outer, SkPathEffect* inner) {
return SkNEW_ARGS(SkComposePathEffect, (outer, inner));
}
virtual bool filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
@ -164,6 +164,12 @@ public:
protected:
SkComposePathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {}
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkComposePathEffect(SkPathEffect* outer, SkPathEffect* inner)
: INHERITED(outer, inner) {}
private:
// illegal
SkComposePathEffect(const SkComposePathEffect&);
@ -184,8 +190,9 @@ public:
The reference counts for first and second are both incremented in the constructor,
and decremented in the destructor.
*/
SkSumPathEffect(SkPathEffect* first, SkPathEffect* second)
: INHERITED(first, second) {}
static SkSumPathEffect* Create(SkPathEffect* first, SkPathEffect* second) {
return SkNEW_ARGS(SkSumPathEffect, (first, second));
}
virtual bool filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
@ -195,6 +202,12 @@ public:
protected:
SkSumPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {}
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkSumPathEffect(SkPathEffect* first, SkPathEffect* second)
: INHERITED(first, second) {}
private:
// illegal
SkSumPathEffect(const SkSumPathEffect&);

Просмотреть файл

@ -34,6 +34,27 @@ class SK_API SkPicture : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(SkPicture)
// AccelData provides a base class for device-specific acceleration
// data. It is added to the picture via a call to a device's optimize
// method.
class AccelData : public SkRefCnt {
public:
typedef uint8_t Domain;
typedef uint32_t Key;
AccelData(Key key) : fKey(key) { }
const Key& getKey() const { return fKey; }
// This entry point allows user's to get a unique domain prefix
// for their keys
static Domain GenerateDomain();
private:
Key fKey;
typedef SkRefCnt INHERITED;
};
/** The constructor prepares the picture to record.
@param width the width of the virtual device the picture records.
@param height the height of the virtual device the picture records.
@ -44,6 +65,18 @@ public:
*/
SkPicture(const SkPicture& src);
/** PRIVATE / EXPERIMENTAL -- do not call */
void EXPERIMENTAL_addAccelData(const AccelData* data) {
SkRefCnt_SafeAssign(fAccelData, data);
}
/** PRIVATE / EXPERIMENTAL -- do not call */
const AccelData* EXPERIMENTAL_getAccelData(AccelData::Key key) const {
if (NULL != fAccelData && fAccelData->getKey() == key) {
return fAccelData;
}
return NULL;
}
/**
* Function signature defining a function that sets up an SkBitmap from encoded data. On
* success, the SkBitmap should have its Config, width, height, rowBytes and pixelref set.
@ -125,15 +158,6 @@ public:
discarded if you serialize into a stream and then deserialize.
*/
kOptimizeForClippedPlayback_RecordingFlag = 0x02,
/*
This flag disables all the picture recording optimizations (i.e.,
those in SkPictureRecord). It is mainly intended for testing the
existing optimizations (i.e., to actually have the pattern
appear in an .skp we have to disable the optimization). This
option doesn't affect the optimizations controlled by
'kOptimizeForClippedPlayback_RecordingFlag'.
*/
kDisableRecordOptimizations_RecordingFlag = 0x04
};
/** Returns the canvas that records the drawing commands.
@ -217,6 +241,25 @@ public:
void abortPlayback();
#endif
/** Return true if the SkStream/Buffer represents a serialized picture, and
fills out SkPictInfo. After this function returns, the data source is not
rewound so it will have to be manually reset before passing to
CreateFromStream or CreateFromBuffer. Note, CreateFromStream and
CreateFromBuffer perform this check internally so these entry points are
intended for stand alone tools.
If false is returned, SkPictInfo is unmodified.
*/
static bool InternalOnly_StreamIsSKP(SkStream*, SkPictInfo*);
static bool InternalOnly_BufferIsSKP(SkReadBuffer&, SkPictInfo*);
/** Enable/disable all the picture recording optimizations (i.e.,
those in SkPictureRecord). It is mainly intended for testing the
existing optimizations (i.e., to actually have the pattern
appear in an .skp we have to disable the optimization). Call right
after 'beginRecording'.
*/
void internalOnly_EnableOpts(bool enableOpts);
protected:
// V2 : adds SkPixelRef's generation ID.
// V3 : PictInfo tag at beginning, and EOF tag at the end
@ -239,14 +282,23 @@ protected:
// V18: SkBitmap now records x,y for its pixelref origin, instead of offset.
// V19: encode matrices and regions into the ops stream
// V20: added bool to SkPictureImageFilter's serialization (to allow SkPicture serialization)
static const uint32_t PICTURE_VERSION = 20;
// V21: add pushCull, popCull
// V22: SK_PICT_FACTORY_TAG's size is now the chunk size in bytes
// Note: If the picture version needs to be increased then please follow the
// steps to generate new SKPs in (only accessible to Googlers): http://goo.gl/qATVcw
// Only SKPs within the min/current picture version range (inclusive) can be read.
static const uint32_t MIN_PICTURE_VERSION = 19;
static const uint32_t CURRENT_PICTURE_VERSION = 22;
// fPlayback, fRecord, fWidth & fHeight are protected to allow derived classes to
// install their own SkPicturePlayback-derived players,SkPictureRecord-derived
// recorders and set the picture size
SkPicturePlayback* fPlayback;
SkPictureRecord* fRecord;
int fWidth, fHeight;
SkPicturePlayback* fPlayback;
SkPictureRecord* fRecord;
int fWidth, fHeight;
const AccelData* fAccelData;
// Create a new SkPicture from an existing SkPicturePlayback. Ref count of
// playback is unchanged.
@ -255,15 +307,9 @@ protected:
// For testing. Derived classes may instantiate an alternate
// SkBBoxHierarchy implementation
virtual SkBBoxHierarchy* createBBoxHierarchy() const;
// Return true if the SkStream represents a serialized picture, and fills out
// SkPictInfo. After this function returns, the SkStream is not rewound; it
// will be ready to be parsed to create an SkPicturePlayback.
// If false is returned, SkPictInfo is unmodified.
static bool StreamIsSKP(SkStream*, SkPictInfo*);
static bool BufferIsSKP(SkReadBuffer&, SkPictInfo*);
private:
void createHeader(void* header) const;
void createHeader(SkPictInfo* info) const;
static bool IsValidPictInfo(const SkPictInfo& info);
friend class SkFlatPicture;
friend class SkPicturePlayback;

Просмотреть файл

@ -116,40 +116,30 @@
// Are we in GCC?
#ifndef SK_CPU_SSE_LEVEL
#if defined(__SSE2__)
#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2
// These checks must be done in descending order to ensure we set the highest
// available SSE level.
#if defined(__SSSE3__)
#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3
#elif defined(__SSE3__)
#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3
#elif defined(__SSSE3__)
#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3
#elif defined(__SSE2__)
#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2
#endif
#endif
// Are we in VisualStudio?
#ifndef SK_CPU_SSE_LEVEL
// These checks must be done in descending order to ensure we set the highest
// available SSE level.
#if defined (_M_IX86_FP)
#if _M_IX86_FP == 1
#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1
#elif _M_IX86_FP >= 2
#if _M_IX86_FP >= 2
#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2
#elif _M_IX86_FP == 1
#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1
#endif
#endif
#endif
// 64bit intel guarantees at least SSE2
#if defined(__x86_64__) || defined(_WIN64)
#if !defined(SK_CPU_SSE_LEVEL) || (SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_SSE2)
#undef SK_CPU_SSE_LEVEL
#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2
#endif
#endif
// Android x86 NDK ABI requires SSE3 support
#if defined(SK_BUILD_FOR_ANDROID)
#undef SK_CPU_SSE_LEVEL
#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3
#endif
//////////////////////////////////////////////////////////////////////
// ARM defines

Просмотреть файл

@ -26,15 +26,9 @@ class SkMatrix;
// 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 SkBaseDevice
// update SkPath.addRRect() to take an SkRRect - only use quads
// -- alternatively add addRRectToPath here
// update SkPath.addRRect() to only use quads
// add GM and bench
// clipping opt
// update SkClipStack to perform logic with RRs
// further out
// add RR rendering shader to Ganesh (akin to cicle drawing code)
// - only for simple RRs
// detect and triangulate RRectorii rather than falling back to SW in Ganesh
//
@ -102,8 +96,24 @@ public:
inline bool isRect() const { return kRect_Type == this->getType(); }
inline bool isOval() const { return kOval_Type == this->getType(); }
inline bool isSimple() const { return kSimple_Type == this->getType(); }
inline bool isSimpleCircular() const {
return this->isSimple() && fRadii[0].fX == fRadii[0].fY;
}
inline bool isComplex() const { return kComplex_Type == this->getType(); }
bool allCornersCircular() const;
/**
* Are both x-radii the same on the two left corners, and similar for the top, right, and
* bottom. When this is the case the four ellipse centers form a rectangle.
*/
bool isNinePatch() const {
return fRadii[kUpperLeft_Corner].fX == fRadii[kLowerLeft_Corner].fX &&
fRadii[kUpperRight_Corner].fX == fRadii[kLowerRight_Corner].fX &&
fRadii[kUpperLeft_Corner].fY == fRadii[kUpperRight_Corner].fY &&
fRadii[kLowerLeft_Corner].fY == fRadii[kLowerRight_Corner].fY;
}
SkScalar width() const { return fRect.width(); }
SkScalar height() const { return fRect.height(); }
@ -228,6 +238,13 @@ public:
this->inset(-dx, -dy, this);
}
/**
* Translate the rrect by (dx, dy).
*/
void offset(SkScalar dx, SkScalar dy) {
fRect.offset(dx, dy);
}
/**
* Returns true if 'rect' is wholy inside the RR, and both
* are not empty.

Просмотреть файл

@ -22,8 +22,6 @@ class SK_API SkRasterizer : public SkFlattenable {
public:
SK_DECLARE_INST_COUNT(SkRasterizer)
SkRasterizer() {}
/** Turn the path into a mask, respecting the specified local->device matrix.
*/
bool rasterize(const SkPath& path, const SkMatrix& matrix,
@ -33,6 +31,7 @@ public:
SK_DEFINE_FLATTENABLE_TYPE(SkRasterizer)
protected:
SkRasterizer() {}
SkRasterizer(SkReadBuffer& buffer) : INHERITED(buffer) {}
virtual bool onRasterize(const SkPath& path, const SkMatrix& matrix,

Просмотреть файл

@ -177,12 +177,14 @@ public:
virtual bool isValid() const { return true; }
virtual bool validateAvailable(size_t size) { return true; }
protected:
SkReader32 fReader;
private:
bool readArray(void* value, size_t size, size_t elementSize);
uint32_t fFlags;
SkReader32 fReader;
void* fMemoryPtr;
SkBitmapHeapReader* fBitmapStorage;

Просмотреть файл

@ -1,38 +0,0 @@
/*
* Copyright 2006 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkScalarCompare_DEFINED
#define SkScalarCompare_DEFINED
#include "SkFloatBits.h"
#include "SkRect.h"
/** Skia can spend a lot of time just comparing scalars (e.g. quickReject).
When scalar==fixed, this is very fast, and when scalar==hardware-float, this
is also reasonable, but if scalar==software-float, then each compare can be
a function call and take real time. To account for that, we have the flag
SK_SCALAR_SLOW_COMPARES.
If this is defined, we have a special trick where we quickly convert floats
to a 2's compliment form, and then treat them as signed 32bit integers. In
this form we lose a few subtlties (e.g. NaNs always comparing false) but
we gain the speed of integer compares.
*/
#ifdef SK_SCALAR_SLOW_COMPARES
typedef int32_t SkScalarCompareType;
typedef SkIRect SkRectCompareType;
#define SkScalarToCompareType(x) SkScalarAs2sCompliment(x)
#else
typedef SkScalar SkScalarCompareType;
typedef SkRect SkRectCompareType;
#define SkScalarToCompareType(x) (x)
#endif
#endif

Просмотреть файл

@ -345,8 +345,7 @@ public:
static SkShader* CreateBitmapShader(const SkBitmap& src,
TileMode tmx, TileMode tmy);
SkDEVCODE(virtual void toString(SkString* str) const;)
SK_TO_STRING_VIRT()
SK_DEFINE_FLATTENABLE_TYPE(SkShader)
protected:
@ -371,10 +370,6 @@ private:
uint8_t fTotalInverseClass;
SkDEBUGCODE(SkBool8 fInSetContext;)
static SkShader* CreateBitmapShader(const SkBitmap& src,
TileMode, TileMode,
void* storage, size_t storageSize);
friend class SkAutoBitmapShaderInstall;
typedef SkFlattenable INHERITED;
};

Просмотреть файл

@ -189,6 +189,8 @@ public:
virtual void newline();
virtual void flush();
virtual size_t bytesWritten() const = 0;
// helpers
bool write8(U8CPU);
@ -205,7 +207,7 @@ public:
bool writeScalar(SkScalar);
bool writePackedUInt(size_t);
bool writeStream(SkStream* input, size_t length);
bool writeStream(SkStream* input, size_t length);
/**
* Append an SkData object to the stream, such that it can be read
@ -216,6 +218,12 @@ public:
* just write the raw content of the SkData object to the stream.
*/
bool writeData(const SkData*);
/**
* This returns the number of bytes in the stream required to store
* 'value'.
*/
static int SizeOfPackedUInt(size_t value);
};
////////////////////////////////////////////////////////////////////////////////////////
@ -365,6 +373,7 @@ public:
virtual bool write(const void* buffer, size_t size) SK_OVERRIDE;
virtual void flush() SK_OVERRIDE;
virtual size_t bytesWritten() const SK_OVERRIDE;
private:
SkFILE* fFILE;
@ -378,7 +387,7 @@ public:
SkMemoryWStream(void* buffer, size_t size);
virtual bool write(const void* buffer, size_t size) SK_OVERRIDE;
size_t bytesWritten() const { return fBytesWritten; }
virtual size_t bytesWritten() const SK_OVERRIDE { return fBytesWritten; }
private:
char* fBuffer;
@ -396,12 +405,12 @@ public:
virtual ~SkDynamicMemoryWStream();
virtual bool write(const void* buffer, size_t size) SK_OVERRIDE;
virtual size_t bytesWritten() const SK_OVERRIDE { return fBytesWritten; }
// random access write
// modifies stream and returns true if offset + size is less than or equal to getOffset()
bool write(const void* buffer, size_t offset, size_t size);
bool read(void* buffer, size_t offset, size_t size);
size_t getOffset() const { return fBytesWritten; }
size_t bytesWritten() const { return fBytesWritten; }
// copy what has been written to the stream into dst
void copyTo(void* dst) const;
@ -437,13 +446,16 @@ private:
class SK_API SkDebugWStream : public SkWStream {
public:
SkDebugWStream() : fBytesWritten(0) {}
SK_DECLARE_INST_COUNT(SkDebugWStream)
// overrides
virtual bool write(const void* buffer, size_t size) SK_OVERRIDE;
virtual void newline() SK_OVERRIDE;
virtual size_t bytesWritten() const SK_OVERRIDE { return fBytesWritten; }
private:
size_t fBytesWritten;
typedef SkWStream INHERITED;
};

Просмотреть файл

@ -52,10 +52,7 @@ public:
* pixels in SkPMColor format.
*/
static SkSurface* NewRasterPMColor(int width, int height) {
SkImageInfo info = {
width, height, kPMColor_SkColorType, kPremul_SkAlphaType
};
return NewRaster(info);
return NewRaster(SkImageInfo::MakeN32Premul(width, height));
}
/**
@ -151,6 +148,18 @@ public:
*/
void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*);
/**
* If the surface has direct access to its pixels (i.e. they are in local
* RAM) return the const-address of those pixels, and if not null, return
* the ImageInfo and rowBytes. The returned address is only valid while
* the surface object is in scope, and no API call is made on the surface
* or its canvas.
*
* On failure, returns NULL and the info and rowBytes parameters are
* ignored.
*/
const void* peekPixels(SkImageInfo* info, size_t* rowBytes);
protected:
SkSurface(int width, int height);
SkSurface(const SkImageInfo&);

Просмотреть файл

@ -158,7 +158,6 @@ public:
* It will never shrink the shrink the storage.
*/
void setCount(int count) {
// TODO(mtklein): eliminate this method, setCountExact -> setCount
SkASSERT(count >= 0);
if (count > fReserve) {
this->resizeStorageToAtLeast(count);
@ -166,20 +165,6 @@ public:
fCount = count;
}
/**
* Sets the number of elements in the array.
* If the array does not have space for count elements, it will increase
* the storage allocated to exactly the amount required, with no remaining
* reserved space.
* It will never shrink the shrink the storage.
*/
void setCountExact(int count) {
if (count > fReserve) {
this->resizeStorageToExact(count);
}
fCount = count;
}
void setReserve(int reserve) {
if (reserve > fReserve) {
this->resizeStorageToAtLeast(reserve);
@ -382,22 +367,6 @@ private:
this->setCount(fCount + delta);
}
/**
* This resizes the storage to *exactly* count elements, growing or
* shrinking the allocation as needed. It does not ASSERT anything about
* the previous allocation size, or about fCount.
*
* note: does NOT modify fCount
*/
void resizeStorageToExact(int count) {
SkASSERT(count >= 0);
fArray = (T*)sk_realloc_throw(fArray, count * sizeof(T));
#ifdef SK_DEBUG
fData = (ArrayT*)fArray;
#endif
fReserve = count;
}
/**
* Increase the storage allocation such that it can hold (fCount + extra)
* elements.
@ -408,9 +377,12 @@ private:
*/
void resizeStorageToAtLeast(int count) {
SkASSERT(count > fReserve);
int space = count + 4;
space += space>>2;
this->resizeStorageToExact(space);
fReserve = count + 4;
fReserve += fReserve / 4;
fArray = (T*)sk_realloc_throw(fArray, fReserve * sizeof(T));
#ifdef SK_DEBUG
fData = (ArrayT*)fArray;
#endif
}
};

Просмотреть файл

@ -74,6 +74,16 @@ public:
return fPtr;
}
/**
* Destroy the lazy object (if it was created via init() or set())
*/
void reset() {
if (this->isValid()) {
fPtr->~T();
fPtr = NULL;
}
}
/**
* Returns true if a valid object has been initialized in the SkTLazy,
* false otherwise.

Просмотреть файл

@ -11,6 +11,8 @@
#define SkTemplates_DEFINED
#include "SkTypes.h"
#include <limits>
#include <limits.h>
#include <new>
/** \file SkTemplates.h
@ -64,6 +66,15 @@ template <typename D, typename S> static D* SkTAddOffset(S* ptr, size_t byteOffs
);
}
/** SkTSetBit<N, T>::value is a T with the Nth bit set. */
template<unsigned N, typename T = uintmax_t> struct SkTSetBit {
static const T value = static_cast<T>(1) << N;
SK_COMPILE_ASSERT(sizeof(T)*CHAR_BIT > N, SkTSetBit_N_too_large);
SK_COMPILE_ASSERT(std::numeric_limits<T>::is_integer, SkTSetBit_T_must_be_integer);
SK_COMPILE_ASSERT(!std::numeric_limits<T>::is_signed, SkTSetBit_T_must_be_unsigned);
SK_COMPILE_ASSERT(std::numeric_limits<T>::radix == 2, SkTSetBit_T_radix_must_be_2);
};
/** \class SkAutoTCallVProc
Call a function when this goes out of scope. The template uses two

Просмотреть файл

@ -1,194 +0,0 @@
/*
* Copyright 2006 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkThread_platform_DEFINED
#define SkThread_platform_DEFINED
#if defined(SK_BUILD_FOR_ANDROID)
#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
#include <stdint.h>
/* Just use the GCC atomic intrinsics. They're supported by the NDK toolchain,
* have reasonable performance, and provide full memory barriers
*/
static inline __attribute__((always_inline)) int32_t sk_atomic_inc(int32_t *addr) {
return __sync_fetch_and_add(addr, 1);
}
static inline __attribute__((always_inline)) int32_t sk_atomic_add(int32_t *addr, int32_t inc) {
return __sync_fetch_and_add(addr, inc);
}
static inline __attribute__((always_inline)) int32_t sk_atomic_dec(int32_t *addr) {
return __sync_fetch_and_add(addr, -1);
}
static inline __attribute__((always_inline)) void sk_membar_aquire__after_atomic_dec() { }
static inline __attribute__((always_inline)) int32_t sk_atomic_conditional_inc(int32_t* addr) {
int32_t value = *addr;
while (true) {
if (value == 0) {
return 0;
}
int32_t before = __sync_val_compare_and_swap(addr, value, value + 1);
if (before == value) {
return value;
} else {
value = before;
}
}
}
static inline __attribute__((always_inline)) void sk_membar_aquire__after_atomic_conditional_inc() { }
#else // SK_BUILD_FOR_ANDROID_FRAMEWORK
/* The platform atomics operations are slightly more efficient than the
* GCC built-ins, so use them.
*/
#include <utils/Atomic.h>
#define sk_atomic_inc(addr) android_atomic_inc(addr)
#define sk_atomic_add(addr, inc) android_atomic_add(inc, addr)
#define sk_atomic_dec(addr) android_atomic_dec(addr)
static inline __attribute__((always_inline)) void sk_membar_aquire__after_atomic_dec() {
//HACK: Android is actually using full memory barriers.
// Should this change, uncomment below.
//int dummy;
//android_atomic_aquire_store(0, &dummy);
}
static inline __attribute__((always_inline)) int32_t sk_atomic_conditional_inc(int32_t* addr) {
while (true) {
int32_t value = *addr;
if (value == 0) {
return 0;
}
if (0 == android_atomic_release_cas(value, value + 1, addr)) {
return value;
}
}
}
static inline __attribute__((always_inline)) void sk_membar_aquire__after_atomic_conditional_inc() {
//HACK: Android is actually using full memory barriers.
// Should this change, uncomment below.
//int dummy;
//android_atomic_aquire_store(0, &dummy);
}
#endif // SK_BUILD_FOR_ANDROID_FRAMEWORK
#else // !SK_BUILD_FOR_ANDROID
/** Implemented by the porting layer, this function adds one to the int
specified by the address (in a thread-safe manner), and returns the
previous value.
No additional memory barrier is required.
This must act as a compiler barrier.
*/
SK_API int32_t sk_atomic_inc(int32_t* addr);
/** Implemented by the porting layer, this function adds inc to the int
specified by the address (in a thread-safe manner), and returns the
previous value.
No additional memory barrier is required.
This must act as a compiler barrier.
*/
SK_API int32_t sk_atomic_add(int32_t* addr, int32_t inc);
/** Implemented by the porting layer, this function subtracts one from the int
specified by the address (in a thread-safe manner), and returns the
previous value.
Expected to act as a release (SL/S) memory barrier and a compiler barrier.
*/
SK_API int32_t sk_atomic_dec(int32_t* addr);
/** If sk_atomic_dec does not act as an aquire (L/SL) barrier, this is expected
to act as an aquire (L/SL) memory barrier and as a compiler barrier.
*/
SK_API void sk_membar_aquire__after_atomic_dec();
/** Implemented by the porting layer, this function adds one to the int
specified by the address iff the int specified by the address is not zero
(in a thread-safe manner), and returns the previous value.
No additional memory barrier is required.
This must act as a compiler barrier.
*/
SK_API int32_t sk_atomic_conditional_inc(int32_t*);
/** If sk_atomic_conditional_inc does not act as an aquire (L/SL) barrier, this
is expected to act as an aquire (L/SL) memory barrier and as a compiler
barrier.
*/
SK_API void sk_membar_aquire__after_atomic_conditional_inc();
#endif // !SK_BUILD_FOR_ANDROID
#ifdef SK_USE_POSIX_THREADS
#include <pthread.h>
// A SkBaseMutex is a POD structure that can be directly initialized
// at declaration time with SK_DECLARE_STATIC/GLOBAL_MUTEX. This avoids the
// generation of a static initializer in the final machine code (and
// a corresponding static finalizer).
//
struct SkBaseMutex {
void acquire() { pthread_mutex_lock(&fMutex); }
void release() { pthread_mutex_unlock(&fMutex); }
pthread_mutex_t fMutex;
};
// Using POD-style initialization prevents the generation of a static initializer
// and keeps the acquire() implementation small and fast.
#define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name = { PTHREAD_MUTEX_INITIALIZER }
// Special case used when the static mutex must be available globally.
#define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name = { PTHREAD_MUTEX_INITIALIZER }
// A normal mutex that requires to be initialized through normal C++ construction,
// i.e. when it's a member of another class, or allocated on the heap.
class SK_API SkMutex : public SkBaseMutex, SkNoncopyable {
public:
SkMutex();
~SkMutex();
};
#else // !SK_USE_POSIX_THREADS
// In the generic case, SkBaseMutex and SkMutex are the same thing, and we
// can't easily get rid of static initializers.
//
class SK_API SkMutex : SkNoncopyable {
public:
SkMutex();
~SkMutex();
void acquire();
void release();
private:
bool fIsGlobal;
enum {
kStorageIntCount = 64
};
uint32_t fStorage[kStorageIntCount];
};
typedef SkMutex SkBaseMutex;
#define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name
#define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name
#endif // !SK_USE_POSIX_THREADS
#endif

Просмотреть файл

@ -115,20 +115,37 @@ inline void operator delete(void* p) {
#ifdef SK_DEVELOPER
#define SkDEVCODE(code) code
// the 'toString' helper functions convert Sk* objects to human-readable
// form in developer mode
#define SK_DEVELOPER_TO_STRING() virtual void toString(SkString* str) const SK_OVERRIDE;
#else
#define SkDEVCODE(code)
#define SK_DEVELOPER_TO_STRING()
#endif
#ifdef SK_IGNORE_TO_STRING
#define SK_TO_STRING_NONVIRT()
#define SK_TO_STRING_VIRT()
#define SK_TO_STRING_PUREVIRT()
#define SK_TO_STRING_OVERRIDE()
#else
// the 'toString' helper functions convert Sk* objects to human-readable
// form in developer mode
#define SK_TO_STRING_NONVIRT() void toString(SkString* str) const;
#define SK_TO_STRING_VIRT() virtual void toString(SkString* str) const;
#define SK_TO_STRING_PUREVIRT() virtual void toString(SkString* str) const = 0;
#define SK_TO_STRING_OVERRIDE() virtual void toString(SkString* str) const SK_OVERRIDE;
#endif
template <bool>
struct SkCompileAssert {
};
// Uses static_cast<bool>(expr) instead of bool(expr) due to
// https://connect.microsoft.com/VisualStudio/feedback/details/832915
// The extra parentheses in SkCompileAssert<(...)> are a work around for
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57771
// which was fixed in gcc 4.8.2.
#define SK_COMPILE_ASSERT(expr, msg) \
typedef SkCompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] SK_UNUSED
typedef SkCompileAssert<(static_cast<bool>(expr))> \
msg[static_cast<bool>(expr) ? 1 : -1] SK_UNUSED
/*
* Usage: SK_MACRO_CONCAT(a, b) to construct the symbol ab
@ -219,6 +236,7 @@ typedef uint8_t SkBool8;
SK_API uint32_t SkToU32(uintmax_t);
SK_API int SkToInt(intmax_t);
SK_API unsigned SkToUInt(uintmax_t);
SK_API size_t SkToSizeT(uintmax_t);
#else
#define SkToS8(x) ((int8_t)(x))
#define SkToU8(x) ((uint8_t)(x))
@ -228,6 +246,7 @@ typedef uint8_t SkBool8;
#define SkToU32(x) ((uint32_t)(x))
#define SkToInt(x) ((int)(x))
#define SkToUInt(x) ((unsigned)(x))
#define SkToSizeT(x) ((size_t)(x))
#endif
/** Returns 0 or 1 based on the condition

Просмотреть файл

@ -10,6 +10,7 @@
#ifndef SkWriter32_DEFINED
#define SkWriter32_DEFINED
#include "SkData.h"
#include "SkMatrix.h"
#include "SkPath.h"
#include "SkPoint.h"
@ -18,7 +19,7 @@
#include "SkRegion.h"
#include "SkScalar.h"
#include "SkStream.h"
#include "SkTDArray.h"
#include "SkTemplates.h"
#include "SkTypes.h"
class SkWriter32 : SkNoncopyable {
@ -30,12 +31,7 @@ public:
* first time an allocation doesn't fit. From then it will use dynamically allocated storage.
* This used to be optional behavior, but pipe now relies on it.
*/
SkWriter32(void* external = NULL, size_t externalBytes = 0)
: fData(0)
, fCapacity(0)
, fUsed(0)
, fExternal(0)
{
SkWriter32(void* external = NULL, size_t externalBytes = 0) {
this->reset(external, externalBytes);
}
@ -49,6 +45,7 @@ public:
SkASSERT(SkIsAlign4((uintptr_t)external));
SkASSERT(SkIsAlign4(externalBytes));
fSnapshot.reset(NULL);
fData = (uint8_t*)external;
fCapacity = externalBytes;
fUsed = 0;
@ -75,7 +72,7 @@ public:
/**
* Read a T record at offset, which must be a multiple of 4. Only legal if the record
* was writtern atomically using the write methods below.
* was written atomically using the write methods below.
*/
template<typename T>
const T& readTAt(size_t offset) const {
@ -86,12 +83,13 @@ public:
/**
* Overwrite a T record at offset, which must be a multiple of 4. Only legal if the record
* was writtern atomically using the write methods below.
* was written atomically using the write methods below.
*/
template<typename T>
void overwriteTAt(size_t offset, const T& value) {
SkASSERT(SkAlign4(offset) == offset);
SkASSERT(offset < fUsed);
SkASSERT(fSnapshot.get() == NULL);
*(T*)(fData + offset) = value;
}
@ -235,14 +233,27 @@ public:
return stream->read(this->reservePad(length), length);
}
/**
* Captures a snapshot of the data as it is right now, and return it.
* Multiple calls without intervening writes may return the same SkData,
* but this is not guaranteed.
* Future appends will not affect the returned buffer.
* It is illegal to call overwriteTAt after this without an intervening
* append. It may cause the snapshot buffer to be corrupted.
* Callers must unref the returned SkData.
* This is not thread safe, it should only be called on the writing thread,
* the result however can be shared across threads.
*/
SkData* snapshotAsData() const;
private:
void growToAtLeast(size_t size);
uint8_t* fData; // Points to either fInternal or fExternal.
size_t fCapacity; // Number of bytes we can write to fData.
size_t fUsed; // Number of bytes written.
void* fExternal; // Unmanaged memory block.
SkTDArray<uint8_t> fInternal; // Managed memory block.
uint8_t* fData; // Points to either fInternal or fExternal.
size_t fCapacity; // Number of bytes we can write to fData.
size_t fUsed; // Number of bytes written.
void* fExternal; // Unmanaged memory block.
SkAutoTMalloc<uint8_t> fInternal; // Managed memory block.
SkAutoTUnref<SkData> fSnapshot; // Holds the result of last asData.
};
/**

Просмотреть файл

@ -32,8 +32,6 @@ class SK_API SkXfermode : public SkFlattenable {
public:
SK_DECLARE_INST_COUNT(SkXfermode)
SkXfermode() {}
virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) const;
virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
@ -213,7 +211,7 @@ public:
Coeff* dst,
GrTexture* background = NULL);
SkDEVCODE(virtual void toString(SkString* str) const = 0;)
SK_TO_STRING_PUREVIRT()
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
SK_DEFINE_FLATTENABLE_TYPE(SkXfermode)
@ -230,6 +228,11 @@ protected:
*/
virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst) const;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkXfermode() {}
private:
enum {
kModeCount = kLastMode + 1
@ -250,7 +253,9 @@ private:
*/
class SkProcXfermode : public SkXfermode {
public:
SkProcXfermode(SkXfermodeProc proc) : fProc(proc) {}
static SkProcXfermode* Create(SkXfermodeProc proc) {
return SkNEW_ARGS(SkProcXfermode, (proc));
}
// overrides from SkXfermode
virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
@ -260,7 +265,7 @@ public:
virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) const SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkProcXfermode)
protected:
@ -276,6 +281,11 @@ protected:
return fProc;
}
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkProcXfermode(SkXfermodeProc proc) : fProc(proc) {}
private:
SkXfermodeProc fProc;

Просмотреть файл

@ -67,8 +67,6 @@ public:
virtual bool endSheet();
virtual bool endPortfolio();
virtual uint32_t getDeviceCapabilities() SK_OVERRIDE;
protected:
virtual void clear(SkColor color) SK_OVERRIDE;
@ -312,11 +310,7 @@ private:
const SkVector& ppuScale,
IXpsOMPath* shadedPath);
// override from SkBaseDevice
virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config,
int width, int height,
bool isOpaque,
Usage usage) SK_OVERRIDE;
virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE;
// Disable the default copy and assign implementation.
SkXPSDevice(const SkXPSDevice&);

Просмотреть файл

@ -52,7 +52,10 @@ public:
@param style how to transform path at each point (based on the current
position and tangent)
*/
SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style);
static SkPath1DPathEffect* Create(const SkPath& path, SkScalar advance, SkScalar phase,
Style style) {
return SkNEW_ARGS(SkPath1DPathEffect, (path, advance, phase, style));
}
virtual bool filterPath(SkPath*, const SkPath&,
SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
@ -67,6 +70,11 @@ protected:
virtual SkScalar begin(SkScalar contourLength) const SK_OVERRIDE;
virtual SkScalar next(SkPath*, SkScalar, SkPathMeasure&) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style);
private:
SkPath fPath; // copied from constructor
SkScalar fAdvance; // copied from constructor

Просмотреть файл

@ -14,7 +14,9 @@
class SK_API Sk2DPathEffect : public SkPathEffect {
public:
Sk2DPathEffect(const SkMatrix& mat);
static Sk2DPathEffect* Create(const SkMatrix& mat) {
return SkNEW_ARGS(Sk2DPathEffect, (mat));
}
virtual bool filterPath(SkPath*, const SkPath&,
SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
@ -44,6 +46,11 @@ protected:
Sk2DPathEffect(SkReadBuffer&);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
Sk2DPathEffect(const SkMatrix& mat);
private:
SkMatrix fMatrix, fInverse;
bool fMatrixIsInvertible;
@ -58,8 +65,9 @@ private:
class SK_API SkLine2DPathEffect : public Sk2DPathEffect {
public:
SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix)
: Sk2DPathEffect(matrix), fWidth(width) {}
static SkLine2DPathEffect* Create(SkScalar width, const SkMatrix& matrix) {
return SkNEW_ARGS(SkLine2DPathEffect, (width, matrix));
}
virtual bool filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
@ -73,6 +81,12 @@ protected:
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix)
: Sk2DPathEffect(matrix), fWidth(width) {}
private:
SkScalar fWidth;
@ -85,7 +99,9 @@ public:
* Stamp the specified path to fill the shape, using the matrix to define
* the latice.
*/
SkPath2DPathEffect(const SkMatrix&, const SkPath&);
static SkPath2DPathEffect* Create(const SkMatrix& matrix, const SkPath& path) {
return SkNEW_ARGS(SkPath2DPathEffect, (matrix, path));
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath2DPathEffect)
@ -95,6 +111,11 @@ protected:
virtual void next(const SkPoint&, int u, int v, SkPath*) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkPath2DPathEffect(const SkMatrix&, const SkPath&);
private:
SkPath fPath;

Просмотреть файл

@ -37,7 +37,9 @@ public:
Tolerance near 0: draw only on colors that are nearly identical to the op-color
Tolerance near 255: draw on any colors even remotely similar to the op-color
*/
SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode);
static SkAvoidXfermode* Create(SkColor opColor, U8CPU tolerance, Mode mode) {
return SkNEW_ARGS(SkAvoidXfermode, (opColor, tolerance, mode));
}
// overrides from SkXfermode
virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
@ -47,13 +49,18 @@ public:
virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) const SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAvoidXfermode)
protected:
SkAvoidXfermode(SkReadBuffer&);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode);
private:
SkColor fOpColor;
uint32_t fDistMul; // x.14

Просмотреть файл

@ -20,30 +20,30 @@
class SK_API SkBicubicImageFilter : public SkImageFilter {
public:
virtual ~SkBicubicImageFilter();
static SkBicubicImageFilter* CreateMitchell(const SkSize& scale, SkImageFilter* input = NULL);
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBicubicImageFilter)
protected:
/** Construct a (scaling-only) bicubic resampling image filter.
@param scale How much to scale the image.
@param coefficients The 16 coefficients of the bicubic matrix.
@param input The input image filter. If NULL, the src bitmap
passed to filterImage() is used instead.
*/
SkBicubicImageFilter(const SkSize& scale, const SkScalar coefficients[16],
SkImageFilter* input = NULL);
static SkBicubicImageFilter* CreateMitchell(const SkSize& scale, SkImageFilter* input = NULL);
virtual ~SkBicubicImageFilter();
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBicubicImageFilter)
protected:
SkBicubicImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; }
virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#endif

Просмотреть файл

@ -1,24 +0,0 @@
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkShader.h"
#include "SkBitmap.h"
#include "SkRegion.h"
#include "SkString.h"
class SK_API SkBitmapAlphaThresholdShader : public SkShader {
public:
/**
* Creates a shader that samples a bitmap and a region. If the sample is inside the region
* the alpha of the bitmap color is boosted up to a threshold value. If it is
* outside the region then the bitmap alpha is decreased to the threshold value.
* The 0,0 point of the region corresponds to the upper left corner of the bitmap
* Currently, this only has a GPU implementation, doesn't respect the paint's bitmap
* filter setting, and always uses clamp mode.
*/
static SkShader* Create(const SkBitmap& bitmap, const SkRegion& region, U8CPU threshold);
};

Просмотреть файл

@ -13,8 +13,13 @@
class SK_API SkBitmapSource : public SkImageFilter {
public:
explicit SkBitmapSource(const SkBitmap& bitmap);
SkBitmapSource(const SkBitmap& bitmap, const SkRect& srcRect, const SkRect& dstRect);
static SkBitmapSource* Create(const SkBitmap& bitmap) {
return SkNEW_ARGS(SkBitmapSource, (bitmap));
}
static SkBitmapSource* Create(const SkBitmap& bitmap, const SkRect& srcRect,
const SkRect& dstRect) {
return SkNEW_ARGS(SkBitmapSource, (bitmap, srcRect, dstRect));
}
virtual void computeFastBounds(const SkRect& src, SkRect* dst) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapSource)
@ -22,10 +27,16 @@ public:
protected:
explicit SkBitmapSource(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRect* dst) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
explicit SkBitmapSource(const SkBitmap& bitmap);
SkBitmapSource(const SkBitmap& bitmap, const SkRect& srcRect, const SkRect& dstRect);
private:
SkBitmap fBitmap;
SkRect fSrcRect, fDstRect;

Просмотреть файл

@ -43,11 +43,11 @@ public:
uint32_t flags = kNone_BlurFlag);
virtual ~SkBlurDrawLooper();
// overrides from SkDrawLooper
virtual void init(SkCanvas*);
virtual bool next(SkCanvas*, SkPaint* paint);
virtual SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
virtual size_t contextSize() const SK_OVERRIDE { return sizeof(BlurDrawLooperContext); }
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurDrawLooper)
protected:
@ -66,7 +66,17 @@ private:
kAfterEdge,
kDone
};
State fState;
class BlurDrawLooperContext : public SkDrawLooper::Context {
public:
explicit BlurDrawLooperContext(const SkBlurDrawLooper* looper);
virtual bool next(SkCanvas* canvas, SkPaint* paint) SK_OVERRIDE;
private:
const SkBlurDrawLooper* fLooper;
State fState;
};
void init(SkScalar sigma, SkScalar dx, SkScalar dy, SkColor color, uint32_t flags);

Просмотреть файл

@ -13,10 +13,13 @@
class SK_API SkBlurImageFilter : public SkImageFilter {
public:
SkBlurImageFilter(SkScalar sigmaX,
SkScalar sigmaY,
SkImageFilter* input = NULL,
const CropRect* cropRect = NULL);
static SkBlurImageFilter* Create(SkScalar sigmaX,
SkScalar sigmaY,
SkImageFilter* input = NULL,
const CropRect* cropRect = NULL) {
return SkNEW_ARGS(SkBlurImageFilter, (sigmaX, sigmaY, input, cropRect));
}
virtual void computeFastBounds(const SkRect&, SkRect*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurImageFilter)
@ -25,15 +28,23 @@ protected:
explicit SkBlurImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect& src, const SkMatrix&,
SkIRect* dst) const SK_OVERRIDE;
bool canFilterImageGPU() const SK_OVERRIDE { return true; }
virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkBlurImageFilter(SkScalar sigmaX,
SkScalar sigmaY,
SkImageFilter* input = NULL,
const CropRect* cropRect = NULL);
private:
SkSize fSigma;
typedef SkImageFilter INHERITED;

Просмотреть файл

@ -25,7 +25,7 @@ protected:
SkColorFilterImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
virtual bool asColorFilter(SkColorFilter**) const SK_OVERRIDE;

Просмотреть файл

@ -13,8 +13,12 @@
class SK_API SkColorMatrixFilter : public SkColorFilter {
public:
explicit SkColorMatrixFilter(const SkColorMatrix&);
SkColorMatrixFilter(const SkScalar array[20]);
static SkColorMatrixFilter* Create(const SkColorMatrix& cm) {
return SkNEW_ARGS(SkColorMatrixFilter, (cm));
}
static SkColorMatrixFilter* Create(const SkScalar array[20]) {
return SkNEW_ARGS(SkColorMatrixFilter, (array));
}
// overrides from SkColorFilter
virtual void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const SK_OVERRIDE;
@ -30,7 +34,7 @@ public:
int fShift;
};
SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorMatrixFilter)
@ -38,6 +42,12 @@ protected:
SkColorMatrixFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
explicit SkColorMatrixFilter(const SkColorMatrix&);
SkColorMatrixFilter(const SkScalar array[20]);
private:
SkColorMatrix fMatrix;

Просмотреть файл

@ -12,18 +12,26 @@
class SK_API SkComposeImageFilter : public SkImageFilter {
public:
SkComposeImageFilter(SkImageFilter* outer, SkImageFilter* inner) : INHERITED(outer, inner) {}
virtual ~SkComposeImageFilter();
static SkComposeImageFilter* Create(SkImageFilter* outer, SkImageFilter* inner) {
return SkNEW_ARGS(SkComposeImageFilter, (outer, inner));
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeImageFilter)
protected:
explicit SkComposeImageFilter(SkReadBuffer& buffer);
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkComposeImageFilter(SkImageFilter* outer, SkImageFilter* inner) : INHERITED(outer, inner) {}
private:
typedef SkImageFilter INHERITED;
};

Просмотреть файл

@ -20,7 +20,9 @@ public:
/** radius must be > 0 to have an effect. It specifies the distance from each corner
that should be "rounded".
*/
SkCornerPathEffect(SkScalar radius);
static SkCornerPathEffect* Create(SkScalar radius) {
return SkNEW_ARGS(SkCornerPathEffect, (radius));
}
virtual ~SkCornerPathEffect();
virtual bool filterPath(SkPath* dst, const SkPath& src,
@ -32,6 +34,11 @@ protected:
SkCornerPathEffect(SkReadBuffer&);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkCornerPathEffect(SkScalar radius);
private:
SkScalar fRadius;

Просмотреть файл

@ -36,8 +36,10 @@ public:
Note: only affects stroked paths.
*/
SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase,
bool scaleToFit = false);
static SkDashPathEffect* Create(const SkScalar intervals[], int count,
SkScalar phase, bool scaleToFit = false) {
return SkNEW_ARGS(SkDashPathEffect, (intervals, count, phase, scaleToFit));
}
virtual ~SkDashPathEffect();
virtual bool filterPath(SkPath* dst, const SkPath& src,
@ -55,6 +57,12 @@ protected:
SkDashPathEffect(SkReadBuffer&);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase,
bool scaleToFit = false);
private:
SkScalar* fIntervals;
int32_t fCount;

Просмотреть файл

@ -20,7 +20,9 @@ public:
away from the original path by a maximum of deviation.
Note: works on filled or framed paths
*/
SkDiscretePathEffect(SkScalar segLength, SkScalar deviation);
static SkDiscretePathEffect* Create(SkScalar segLength, SkScalar deviation) {
return SkNEW_ARGS(SkDiscretePathEffect, (segLength, deviation));
}
virtual bool filterPath(SkPath* dst, const SkPath& src,
SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
@ -31,6 +33,11 @@ protected:
SkDiscretePathEffect(SkReadBuffer&);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkDiscretePathEffect(SkScalar segLength, SkScalar deviation);
private:
SkScalar fSegLength, fPerterb;

Просмотреть файл

@ -18,23 +18,25 @@ public:
kR_ChannelSelectorType,
kG_ChannelSelectorType,
kB_ChannelSelectorType,
kA_ChannelSelectorType,
kKeyBits = 3 // Max value is 4, so 3 bits are required at most
kA_ChannelSelectorType
};
SkDisplacementMapEffect(ChannelSelectorType xChannelSelector,
ChannelSelectorType yChannelSelector,
SkScalar scale, SkImageFilter* displacement,
SkImageFilter* color = NULL,
const CropRect* cropRect = NULL);
~SkDisplacementMapEffect();
static SkDisplacementMapEffect* Create(ChannelSelectorType xChannelSelector,
ChannelSelectorType yChannelSelector,
SkScalar scale, SkImageFilter* displacement,
SkImageFilter* color = NULL,
const CropRect* cropRect = NULL) {
return SkNEW_ARGS(SkDisplacementMapEffect, (xChannelSelector, yChannelSelector, scale,
displacement, color, cropRect));
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDisplacementMapEffect)
virtual bool onFilterImage(Proxy* proxy,
const SkBitmap& src,
const SkMatrix& ctm,
const Context& ctx,
SkBitmap* dst,
SkIPoint* offset) const SK_OVERRIDE;
virtual void computeFastBounds(const SkRect& src, SkRect* dst) const SK_OVERRIDE;
@ -44,7 +46,7 @@ public:
#if SK_SUPPORT_GPU
virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; }
virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#endif
@ -52,6 +54,15 @@ protected:
explicit SkDisplacementMapEffect(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkDisplacementMapEffect(ChannelSelectorType xChannelSelector,
ChannelSelectorType yChannelSelector,
SkScalar scale, SkImageFilter* displacement,
SkImageFilter* color = NULL,
const CropRect* cropRect = NULL);
private:
ChannelSelectorType fXChannelSelector;
ChannelSelectorType fYChannelSelector;

Просмотреть файл

@ -11,19 +11,34 @@
class SK_API SkDropShadowImageFilter : public SkImageFilter {
public:
SkDropShadowImageFilter(SkScalar dx, SkScalar dy, SkScalar sigma, SkColor, SkImageFilter* input = NULL);
SkDropShadowImageFilter(SkScalar dx, SkScalar dy, SkScalar sigmaX, SkScalar sigmaY, SkColor, SkImageFilter* input = NULL, const CropRect* cropRect = NULL);
static SkDropShadowImageFilter* Create(SkScalar dx, SkScalar dy, SkScalar sigma,
SkColor color, SkImageFilter* input = NULL) {
return SkNEW_ARGS(SkDropShadowImageFilter, (dx, dy, sigma, color, input));
}
static SkDropShadowImageFilter* Create(SkScalar dx, SkScalar dy,
SkScalar sigmaX, SkScalar sigmaY, SkColor color,
SkImageFilter* input = NULL,
const CropRect* cropRect = NULL) {
return SkNEW_ARGS(SkDropShadowImageFilter, (dx, dy, sigmaX, sigmaY,
color, input, cropRect));
}
virtual void computeFastBounds(const SkRect&, SkRect*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDropShadowImageFilter)
protected:
explicit SkDropShadowImageFilter(SkReadBuffer&);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& source, const SkMatrix&, SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& source, const Context&, SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect& src, const SkMatrix&,
SkIRect* dst) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkDropShadowImageFilter(SkScalar dx, SkScalar dy, SkScalar sigma, SkColor,
SkImageFilter* input = NULL);
SkDropShadowImageFilter(SkScalar dx, SkScalar dy, SkScalar sigmaX, SkScalar sigmaY, SkColor,
SkImageFilter* input = NULL, const CropRect* cropRect = NULL);
private:
SkScalar fDx, fDy, fSigmaX, fSigmaY;

Просмотреть файл

@ -23,10 +23,9 @@ public:
uint8_t fSpecular; // exponent, 4.4 right now
};
SkEmbossMaskFilter(SkScalar blurSigma, const Light& light);
SK_ATTR_DEPRECATED("use sigma version")
SkEmbossMaskFilter(const Light& light, SkScalar blurRadius);
static SkEmbossMaskFilter* Create(SkScalar blurSigma, const Light& light) {
return SkNEW_ARGS(SkEmbossMaskFilter, (blurSigma, light));
}
// overrides from SkMaskFilter
// This method is not exported to java.
@ -35,13 +34,18 @@ public:
virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&,
SkIPoint* margin) const SK_OVERRIDE;
SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkEmbossMaskFilter)
protected:
SkEmbossMaskFilter(SkReadBuffer&);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkEmbossMaskFilter(SkScalar blurSigma, const Light& light);
private:
Light fLight;
SkScalar fBlurSigma;

Просмотреть файл

@ -12,18 +12,17 @@
class SK_API SkKernel33ProcMaskFilter : public SkMaskFilter {
public:
SkKernel33ProcMaskFilter(unsigned percent256 = 256)
: fPercent256(percent256) {}
virtual uint8_t computeValue(uint8_t* const* srcRows) const = 0;
virtual SkMask::Format getFormat() const SK_OVERRIDE;
virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&,
SkIPoint*) const SK_OVERRIDE;
SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
SK_TO_STRING_OVERRIDE()
protected:
SkKernel33ProcMaskFilter(unsigned percent256 = 256)
: fPercent256(percent256) {}
SkKernel33ProcMaskFilter(SkReadBuffer& rb);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
@ -37,18 +36,26 @@ private:
class SK_API SkKernel33MaskFilter : public SkKernel33ProcMaskFilter {
public:
SkKernel33MaskFilter(const int coeff[3][3], int shift, int percent256 = 256)
: SkKernel33ProcMaskFilter(percent256) {
memcpy(fKernel, coeff, 9 * sizeof(int));
fShift = shift;
static SkKernel33MaskFilter* Create(const int coeff[3][3], int shift, int percent256 = 256) {
return SkNEW_ARGS(SkKernel33MaskFilter, (coeff, shift, percent256));
}
// override from SkKernel33ProcMaskFilter
virtual uint8_t computeValue(uint8_t* const* srcRows) const SK_OVERRIDE;
SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkKernel33MaskFilter)
protected:
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkKernel33MaskFilter(const int coeff[3][3], int shift, int percent256 = 256)
: SkKernel33ProcMaskFilter(percent256) {
memcpy(fKernel, coeff, 9 * sizeof(int));
fShift = shift;
}
private:
int fKernel[3][3];
int fShift;

Просмотреть файл

@ -24,8 +24,8 @@ public:
* Bits specifies which aspects of the layer's paint should replace the
* corresponding aspects on the draw's paint.
* kEntirePaint_Bits means use the layer's paint completely.
* 0 means ignore the layer's paint... except that LayerInfo's fFlagsMask
* and fColorMode are always applied.
* 0 means ignore the layer's paint... except for fColorMode, which is
* always applied.
*/
enum Bits {
kStyle_Bit = 1 << 0, //!< use this layer's Style/stroke settings
@ -40,8 +40,7 @@ public:
* Use the layer's paint entirely, with these exceptions:
* - We never override the draw's paint's text_encoding, since that is
* used to interpret the text/len parameters in draw[Pos]Text.
* - Flags and Color are always computed using the LayerInfo's
* fFlagsMask and fColorMode.
* - Color is always computed using the LayerInfo's fColorMode.
*/
kEntirePaint_Bits = -1
@ -51,12 +50,6 @@ public:
/**
* Info for how to apply the layer's paint and offset.
*
* fFlagsMask selects which flags in the layer's paint should be applied.
* result = (draw-flags & ~fFlagsMask) | (layer-flags & fFlagsMask)
* In the extreme:
* If fFlagsMask is 0, we ignore all of the layer's flags
* If fFlagsMask is -1, we use all of the layer's flags
*
* fColorMode controls how we compute the final color for the layer:
* The layer's paint's color is treated as the SRC
* The draw's paint's color is treated as the DST
@ -66,7 +59,6 @@ public:
* kDst_Mode: to just keep the draw's color, ignoring the layer's
*/
struct SK_API LayerInfo {
uint32_t fFlagsMask; // SkPaint::Flags
BitFlags fPaintBits;
SkXfermode::Mode fColorMode;
SkVector fOffset;
@ -102,15 +94,17 @@ public:
/// Similar to addLayer, but adds a layer to the top.
SkPaint* addLayerOnTop(const LayerInfo&);
// overrides from SkDrawLooper
virtual void init(SkCanvas*);
virtual bool next(SkCanvas*, SkPaint* paint);
virtual SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLayerDrawLooper)
virtual size_t contextSize() const SK_OVERRIDE { return sizeof(LayerDrawLooperContext); }
SK_TO_STRING_OVERRIDE()
/// Implements Flattenable.
virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; }
static SkFlattenable* CreateProc(SkReadBuffer& buffer);
protected:
SkLayerDrawLooper(SkReadBuffer&);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
private:
@ -124,9 +118,18 @@ private:
int fCount;
// state-machine during the init/next cycle
Rec* fCurrRec;
class LayerDrawLooperContext : public SkDrawLooper::Context {
public:
explicit LayerDrawLooperContext(const SkLayerDrawLooper* looper);
static void ApplyInfo(SkPaint* dst, const SkPaint& src, const LayerInfo&);
protected:
virtual bool next(SkCanvas*, SkPaint* paint) SK_OVERRIDE;
private:
Rec* fCurrRec;
static void ApplyInfo(SkPaint* dst, const SkPaint& src, const LayerInfo&);
};
class MyRegistrar : public SkFlattenable::Registrar {
public:
@ -134,6 +137,44 @@ private:
};
typedef SkDrawLooper INHERITED;
public:
class SK_API Builder {
public:
Builder();
~Builder();
/**
* Call for each layer you want to add (from top to bottom).
* This returns a paint you can modify, but that ptr is only valid until
* the next call made to addLayer().
*/
SkPaint* addLayer(const LayerInfo&);
/**
* This layer will draw with the original paint, at the specified offset
*/
void addLayer(SkScalar dx, SkScalar dy);
/**
* This layer will with the original paint and no offset.
*/
void addLayer() { this->addLayer(0, 0); }
/// Similar to addLayer, but adds a layer to the top.
SkPaint* addLayerOnTop(const LayerInfo&);
/**
* Pass list of layers on to newly built looper and return it. This will
* also reset the builder, so it can be used to build another looper.
*/
SkLayerDrawLooper* detachLooper();
private:
Rec* fRecs;
Rec* fTopRec;
int fCount;
};
};
#endif

Просмотреть файл

@ -18,9 +18,36 @@ class SkPaint;
class SK_API SkLayerRasterizer : public SkRasterizer {
public:
SkLayerRasterizer();
virtual ~SkLayerRasterizer();
class SK_API Builder {
public:
Builder();
~Builder();
void addLayer(const SkPaint& paint) {
this->addLayer(paint, 0, 0);
}
/**
* Add a new layer (above any previous layers) to the rasterizer.
* The layer will extract those fields that affect the mask from
* the specified paint, but will not retain a reference to the paint
* object itself, so it may be reused without danger of side-effects.
*/
void addLayer(const SkPaint& paint, SkScalar dx, SkScalar dy);
/**
* Pass queue of layers on to newly created layer rasterizer and return it. The builder
* cannot be used any more after calling this function.
*/
SkLayerRasterizer* detachRasterizer();
private:
SkDeque* fLayers;
};
#ifdef SK_SUPPORT_LEGACY_LAYERRASTERIZER_API
void addLayer(const SkPaint& paint) {
this->addLayer(paint, 0, 0);
}
@ -31,10 +58,12 @@ public:
object itself, so it may be reused without danger of side-effects.
*/
void addLayer(const SkPaint& paint, SkScalar dx, SkScalar dy);
#endif
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLayerRasterizer)
protected:
SkLayerRasterizer(SkDeque* layers);
SkLayerRasterizer(SkReadBuffer&);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
@ -43,8 +72,19 @@ protected:
const SkIRect* clipBounds,
SkMask* mask, SkMask::CreateMode mode) const;
#ifdef SK_SUPPORT_LEGACY_LAYERRASTERIZER_API
public:
#endif
SkLayerRasterizer();
private:
SkDeque fLayers;
#ifdef SK_SUPPORT_LEGACY_LAYERRASTERIZER_API
SkDeque* fLayers;
#else
const SkDeque* const fLayers;
#endif
static SkDeque* ReadLayers(SkReadBuffer& buffer);
typedef SkRasterizer INHERITED;
};

Просмотреть файл

@ -28,7 +28,7 @@ public:
virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) const SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLerpXfermode)
protected:

Просмотреть файл

@ -31,7 +31,7 @@ public:
virtual GrEffectRef* asNewEffect(GrContext*) const SK_OVERRIDE;
#endif
SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLumaColorFilter)
protected:

Просмотреть файл

@ -14,7 +14,9 @@
class SK_API SkMagnifierImageFilter : public SkImageFilter {
public:
SkMagnifierImageFilter(SkRect srcRect, SkScalar inset);
static SkMagnifierImageFilter* Create(const SkRect& srcRect, SkScalar inset) {
return SkNEW_ARGS(SkMagnifierImageFilter, (srcRect, inset));
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMagnifierImageFilter)
@ -22,12 +24,17 @@ protected:
explicit SkMagnifierImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture, const SkMatrix& matrix, const SkIRect& bounds) const SK_OVERRIDE;
#endif
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkMagnifierImageFilter(const SkRect& srcRect, SkScalar inset);
private:
SkRect fSrcRect;
SkScalar fInset;

Просмотреть файл

@ -28,61 +28,78 @@ public:
kClampToBlack_TileMode, /*!< Fill with transparent black. */
};
/** Construct a matrix convolution image filter.
@param kernelSize The kernel size in pixels, in each dimension (N by M).
@param kernel The image processing kernel. Must contain N * M
elements, in row order.
@param gain A scale factor applied to each pixel after
convolution. This can be used to normalize the
kernel, if it does not sum to 1.
@param bias A bias factor added to each pixel after convolution.
@param target An offset applied to each pixel coordinate before
convolution. This can be used to center the kernel
over the image (e.g., a 3x3 kernel should have a
target of {1, 1}).
@param tileMode How accesses outside the image are treated. (@see
TileMode).
@param convolveAlpha If true, all channels are convolved. If false,
only the RGB channels are convolved, and
alpha is copied from the source image.
@param input The input image filter. If NULL, the src bitmap
passed to filterImage() is used instead.
@param cropRect The rectangle to which the output processing will be limited.
*/
SkMatrixConvolutionImageFilter(const SkISize& kernelSize,
const SkScalar* kernel,
SkScalar gain,
SkScalar bias,
const SkIPoint& target,
TileMode tileMode,
bool convolveAlpha,
SkImageFilter* input = NULL,
const CropRect* cropRect = NULL);
virtual ~SkMatrixConvolutionImageFilter();
/** Construct a matrix convolution image filter.
@param kernelSize The kernel size in pixels, in each dimension (N by M).
@param kernel The image processing kernel. Must contain N * M
elements, in row order.
@param gain A scale factor applied to each pixel after
convolution. This can be used to normalize the
kernel, if it does not sum to 1.
@param bias A bias factor added to each pixel after convolution.
@param kernelOffset An offset applied to each pixel coordinate before
convolution. This can be used to center the kernel
over the image (e.g., a 3x3 kernel should have an
offset of {1, 1}).
@param tileMode How accesses outside the image are treated. (@see
TileMode).
@param convolveAlpha If true, all channels are convolved. If false,
only the RGB channels are convolved, and
alpha is copied from the source image.
@param input The input image filter. If NULL, the src bitmap
passed to filterImage() is used instead.
@param cropRect The rectangle to which the output processing will be limited.
*/
static SkMatrixConvolutionImageFilter* Create(const SkISize& kernelSize,
const SkScalar* kernel,
SkScalar gain,
SkScalar bias,
const SkIPoint& kernelOffset,
TileMode tileMode,
bool convolveAlpha,
SkImageFilter* input = NULL,
const CropRect* cropRect = NULL) {
return SkNEW_ARGS(SkMatrixConvolutionImageFilter, (kernelSize, kernel, gain, bias,
kernelOffset, tileMode, convolveAlpha,
input, cropRect));
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMatrixConvolutionImageFilter)
protected:
SkMatrixConvolutionImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool asNewEffect(GrEffectRef** effect,
GrTexture*,
const SkMatrix& matrix,
const SkMatrix& ctm,
const SkIRect& bounds) const SK_OVERRIDE;
#endif
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkMatrixConvolutionImageFilter(const SkISize& kernelSize,
const SkScalar* kernel,
SkScalar gain,
SkScalar bias,
const SkIPoint& kernelOffset,
TileMode tileMode,
bool convolveAlpha,
SkImageFilter* input = NULL,
const CropRect* cropRect = NULL);
private:
SkISize fKernelSize;
SkScalar* fKernel;
SkScalar fGain;
SkScalar fBias;
SkIPoint fTarget;
SkIPoint fKernelOffset;
TileMode fTileMode;
bool fConvolveAlpha;
typedef SkImageFilter INHERITED;

Просмотреть файл

@ -14,22 +14,37 @@
class SK_API SkMergeImageFilter : public SkImageFilter {
public:
SkMergeImageFilter(SkImageFilter* first, SkImageFilter* second,
SkXfermode::Mode = SkXfermode::kSrcOver_Mode,
const CropRect* cropRect = NULL);
SkMergeImageFilter(SkImageFilter* filters[], int count,
const SkXfermode::Mode modes[] = NULL,
const CropRect* cropRect = NULL);
virtual ~SkMergeImageFilter();
static SkMergeImageFilter* Create(SkImageFilter* first, SkImageFilter* second,
SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
const CropRect* cropRect = NULL) {
return SkNEW_ARGS(SkMergeImageFilter, (first, second, mode, cropRect));
}
static SkMergeImageFilter* Create(SkImageFilter* filters[], int count,
const SkXfermode::Mode modes[] = NULL,
const CropRect* cropRect = NULL) {
return SkNEW_ARGS(SkMergeImageFilter, (filters, count, modes, cropRect));
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMergeImageFilter)
protected:
SkMergeImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkMergeImageFilter(SkImageFilter* first, SkImageFilter* second,
SkXfermode::Mode = SkXfermode::kSrcOver_Mode,
const CropRect* cropRect = NULL);
SkMergeImageFilter(SkImageFilter* filters[], int count,
const SkXfermode::Mode modes[] = NULL,
const CropRect* cropRect = NULL);
private:
uint8_t* fModes; // SkXfermode::Mode

Просмотреть файл

@ -15,7 +15,6 @@
class SK_API SkMorphologyImageFilter : public SkImageFilter {
public:
SkMorphologyImageFilter(int radiusX, int radiusY, SkImageFilter* input, const CropRect* cropRect);
virtual void computeFastBounds(const SkRect& src, SkRect* dst) const SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRect* dst) const SK_OVERRIDE;
@ -30,15 +29,17 @@ public:
int width, int height, int srcStride, int dstStride);
protected:
SkMorphologyImageFilter(int radiusX, int radiusY, SkImageFilter* input,
const CropRect* cropRect);
bool filterImageGeneric(Proc procX, Proc procY,
Proxy*, const SkBitmap& src, const SkMatrix&,
Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const;
SkMorphologyImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; }
bool filterImageGPUGeneric(bool dilate, Proxy* proxy, const SkBitmap& src,
const SkMatrix& ctm, SkBitmap* result,
const Context& ctm, SkBitmap* result,
SkIPoint* offset) const;
#endif
@ -51,15 +52,16 @@ private:
class SK_API SkDilateImageFilter : public SkMorphologyImageFilter {
public:
SkDilateImageFilter(int radiusX, int radiusY,
SkImageFilter* input = NULL,
const CropRect* cropRect = NULL)
: INHERITED(radiusX, radiusY, input, cropRect) {}
static SkDilateImageFilter* Create(int radiusX, int radiusY,
SkImageFilter* input = NULL,
const CropRect* cropRect = NULL) {
return SkNEW_ARGS(SkDilateImageFilter, (radiusX, radiusY, input, cropRect));
}
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#endif
@ -68,21 +70,30 @@ public:
protected:
SkDilateImageFilter(SkReadBuffer& buffer) : INHERITED(buffer) {}
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkDilateImageFilter(int radiusX, int radiusY,
SkImageFilter* input = NULL,
const CropRect* cropRect = NULL)
: INHERITED(radiusX, radiusY, input, cropRect) {}
private:
typedef SkMorphologyImageFilter INHERITED;
};
class SK_API SkErodeImageFilter : public SkMorphologyImageFilter {
public:
SkErodeImageFilter(int radiusX, int radiusY,
SkImageFilter* input = NULL,
const CropRect* cropRect = NULL)
: INHERITED(radiusX, radiusY, input, cropRect) {}
static SkErodeImageFilter* Create(int radiusX, int radiusY,
SkImageFilter* input = NULL,
const CropRect* cropRect = NULL) {
return SkNEW_ARGS(SkErodeImageFilter, (radiusX, radiusY, input, cropRect));
}
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#endif
@ -91,6 +102,14 @@ public:
protected:
SkErodeImageFilter(SkReadBuffer& buffer) : INHERITED(buffer) {}
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkErodeImageFilter(int radiusX, int radiusY,
SkImageFilter* input = NULL,
const CropRect* cropRect = NULL)
: INHERITED(radiusX, radiusY, input, cropRect) {}
private:
typedef SkMorphologyImageFilter INHERITED;
};

Просмотреть файл

@ -15,8 +15,10 @@ class SK_API SkOffsetImageFilter : public SkImageFilter {
typedef SkImageFilter INHERITED;
public:
SkOffsetImageFilter(SkScalar dx, SkScalar dy, SkImageFilter* input = NULL,
const CropRect* cropRect = NULL);
static SkOffsetImageFilter* Create(SkScalar dx, SkScalar dy, SkImageFilter* input = NULL,
const CropRect* cropRect = NULL) {
return SkNEW_ARGS(SkOffsetImageFilter, (dx, dy, input, cropRect));
}
virtual void computeFastBounds(const SkRect& src, SkRect* dst) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkOffsetImageFilter)
@ -24,10 +26,16 @@ protected:
SkOffsetImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkOffsetImageFilter(SkScalar dx, SkScalar dy, SkImageFilter* input = NULL,
const CropRect* cropRect = NULL);
private:
SkVector fOffset;
};

Просмотреть файл

@ -69,7 +69,7 @@ public:
virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader)
protected:
@ -79,28 +79,28 @@ protected:
private:
SkPerlinNoiseShader(SkPerlinNoiseShader::Type type, SkScalar baseFrequencyX,
SkScalar baseFrequencyY, int numOctaves, SkScalar seed,
const SkISize* tileSize = NULL);
const SkISize* tileSize);
virtual ~SkPerlinNoiseShader();
void setTileSize(const SkISize&);
void initPaint(PaintingData& paintingData);
SkScalar noise2D(int channel, const PaintingData& paintingData,
const StitchData& stitchData, const SkPoint& noiseVector);
const StitchData& stitchData, const SkPoint& noiseVector) const;
SkScalar calculateTurbulenceValueForPoint(int channel, const PaintingData& paintingData,
StitchData& stitchData, const SkPoint& point);
StitchData& stitchData, const SkPoint& point) const;
SkPMColor shade(const SkPoint& point, StitchData& stitchData);
SkPMColor shade(const SkPoint& point, StitchData& stitchData) const;
SkPerlinNoiseShader::Type fType;
SkScalar fBaseFrequencyX;
SkScalar fBaseFrequencyY;
int fNumOctaves;
SkScalar fSeed;
SkISize fTileSize;
bool fStitchTiles;
// TODO (scroggo): Once all SkShaders are created from a factory, and we have removed the
// constructor that creates SkPerlinNoiseShader from an SkReadBuffer, several fields can
// be made constant.
/*const*/ SkPerlinNoiseShader::Type fType;
/*const*/ SkScalar fBaseFrequencyX;
/*const*/ SkScalar fBaseFrequencyY;
/*const*/ int fNumOctaves;
/*const*/ SkScalar fSeed;
/*const*/ SkISize fTileSize;
/*const*/ bool fStitchTiles;
// TODO (scroggo): Once setContext creates a new object, place this on that object.
SkMatrix fMatrix;
PaintingData* fPaintingData;

Просмотреть файл

@ -16,13 +16,17 @@ public:
/**
* Refs the passed-in picture.
*/
explicit SkPictureImageFilter(SkPicture* picture);
static SkPictureImageFilter* Create(SkPicture* picture) {
return SkNEW_ARGS(SkPictureImageFilter, (picture));
}
/**
* Refs the passed-in picture. rect can be used to crop or expand the destination rect when
* Refs the passed-in picture. cropRect can be used to crop or expand the destination rect when
* the picture is drawn. (No scaling is implied by the dest rect; only the CTM is applied.)
*/
SkPictureImageFilter(SkPicture* picture, const SkRect& rect);
static SkPictureImageFilter* Create(SkPicture* picture, const SkRect& cropRect) {
return SkNEW_ARGS(SkPictureImageFilter, (picture, cropRect));
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureImageFilter)
@ -36,12 +40,18 @@ protected:
*/
explicit SkPictureImageFilter(SkReadBuffer&);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
explicit SkPictureImageFilter(SkPicture* picture);
SkPictureImageFilter(SkPicture* picture, const SkRect& cropRect);
private:
SkPicture* fPicture;
SkRect fRect;
SkRect fCropRect;
typedef SkImageFilter INHERITED;
};

Просмотреть файл

@ -17,9 +17,11 @@
*/
class SK_API SkPixelXorXfermode : public SkXfermode {
public:
SkPixelXorXfermode(SkColor opColor) : fOpColor(opColor) {}
static SkPixelXorXfermode* Create(SkColor opColor) {
return SkNEW_ARGS(SkPixelXorXfermode, (opColor));
}
SK_DEVELOPER_TO_STRING()
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPixelXorXfermode)
protected:
@ -29,6 +31,11 @@ protected:
// override from SkXfermode
virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst) const;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkPixelXorXfermode(SkColor opColor) : fOpColor(opColor) {}
private:
SkColor fOpColor;

Просмотреть файл

@ -37,7 +37,7 @@ protected:
SkRectShaderImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
private:

Просмотреть файл

@ -21,6 +21,8 @@
class SK_API SkResizeImageFilter : public SkImageFilter {
public:
virtual ~SkResizeImageFilter();
/** Construct a (scaling-only) resampling image filter.
* @param sx The x scale parameter to apply when resizing.
* @param sy The y scale parameter to apply when resizing.
@ -28,10 +30,12 @@ public:
* @param input The input image filter. If NULL, the src bitmap
* passed to filterImage() is used instead.
*/
static SkResizeImageFilter* Create(SkScalar sx, SkScalar sy, SkPaint::FilterLevel filterLevel,
SkImageFilter* input = NULL) {
return SkNEW_ARGS(SkResizeImageFilter, (sx, sy, filterLevel, input));
}
SkResizeImageFilter(SkScalar sx, SkScalar sy, SkPaint::FilterLevel filterLevel,
SkImageFilter* input = NULL);
virtual ~SkResizeImageFilter();
virtual void computeFastBounds(const SkRect&, SkRect*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkResizeImageFilter)
@ -39,8 +43,16 @@ protected:
SkResizeImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect& src, const SkMatrix&,
SkIRect* dst) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkResizeImageFilter(SkScalar sx, SkScalar sy, SkPaint::FilterLevel filterLevel,
SkImageFilter* input = NULL);
private:
SkScalar fSx, fSy;

Просмотреть файл

@ -15,7 +15,8 @@
*/
class SK_API SkStippleMaskFilter : public SkMaskFilter {
public:
SkStippleMaskFilter() : INHERITED() {
static SkStippleMaskFilter* Create() {
return SkNEW(SkStippleMaskFilter);
}
virtual bool filterMask(SkMask* dst, const SkMask& src,
@ -27,7 +28,7 @@ public:
return SkMask::kA8_Format;
}
SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkStippleMaskFilter);
protected:
@ -35,6 +36,12 @@ protected:
: SkMaskFilter(buffer) {
}
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkStippleMaskFilter() : INHERITED() {
}
private:
typedef SkMaskFilter INHERITED;
};

Просмотреть файл

@ -18,8 +18,6 @@
*/
class SK_API SkTableMaskFilter : public SkMaskFilter {
public:
SkTableMaskFilter();
SkTableMaskFilter(const uint8_t table[256]);
virtual ~SkTableMaskFilter();
/** Utility that sets the gamma table
@ -31,6 +29,10 @@ public:
*/
static void MakeClipTable(uint8_t table[256], uint8_t min, uint8_t max);
static SkTableMaskFilter* Create(const uint8_t table[256]) {
return SkNEW_ARGS(SkTableMaskFilter, (table));
}
static SkTableMaskFilter* CreateGamma(SkScalar gamma) {
uint8_t table[256];
MakeGammaTable(table, gamma);
@ -47,13 +49,19 @@ public:
virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&,
SkIPoint*) const SK_OVERRIDE;
SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTableMaskFilter)
protected:
SkTableMaskFilter(SkReadBuffer& rb);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkTableMaskFilter();
SkTableMaskFilter(const uint8_t table[256]);
private:
uint8_t fTable[256];

Просмотреть файл

@ -7,15 +7,18 @@
// Fun mode that scales down (only) and then scales back up to look pixelated
class SK_API SkDownSampleImageFilter : public SkImageFilter {
public:
SkDownSampleImageFilter(SkScalar scale) : INHERITED(0), fScale(scale) {}
static SkDownSampleImageFilter* Create(SkScalar scale) {
return SkNEW_ARGS(SkDownSampleImageFilter, (scale));
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDownSampleImageFilter)
protected:
SkDownSampleImageFilter(SkScalar scale) : INHERITED(0), fScale(scale) {}
SkDownSampleImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
private:

Просмотреть файл

@ -14,15 +14,17 @@ class SK_API SkTileImageFilter : public SkImageFilter {
typedef SkImageFilter INHERITED;
public:
/** Tile image filter constructor
/** Create a tile image filter
@param srcRect Defines the pixels to tile
@param dstRect Defines the pixels where tiles are drawn
@param input Input from which the subregion defined by srcRect will be tiled
*/
SkTileImageFilter(const SkRect& srcRect, const SkRect& dstRect, SkImageFilter* input)
: INHERITED(input), fSrcRect(srcRect), fDstRect(dstRect) {}
static SkTileImageFilter* Create(const SkRect& srcRect, const SkRect& dstRect,
SkImageFilter* input) {
return SkNEW_ARGS(SkTileImageFilter, (srcRect, dstRect, input));
}
virtual bool onFilterImage(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
virtual bool onFilterImage(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* dst, SkIPoint* offset) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTileImageFilter)
@ -32,6 +34,12 @@ protected:
virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkTileImageFilter(const SkRect& srcRect, const SkRect& dstRect, SkImageFilter* input)
: INHERITED(input), fSrcRect(srcRect), fDstRect(dstRect) {}
private:
SkRect fSrcRect;
SkRect fDstRect;

Просмотреть файл

@ -21,7 +21,7 @@ public:
virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE;
virtual void shadeSpan16(int x, int y, uint16_t span[], int count) SK_OVERRIDE;
SK_DEVELOPER_TO_STRING()
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTransparentShader)
private:

Просмотреть файл

@ -21,21 +21,24 @@ class SK_API SkXfermodeImageFilter : public SkImageFilter {
*/
public:
SkXfermodeImageFilter(SkXfermode* mode, SkImageFilter* background,
SkImageFilter* foreground = NULL, const CropRect* cropRect = NULL);
virtual ~SkXfermodeImageFilter();
static SkXfermodeImageFilter* Create(SkXfermode* mode, SkImageFilter* background,
SkImageFilter* foreground = NULL,
const CropRect* cropRect = NULL) {
return SkNEW_ARGS(SkXfermodeImageFilter, (mode, background, foreground, cropRect));
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkXfermodeImageFilter)
virtual bool onFilterImage(Proxy* proxy,
const SkBitmap& src,
const SkMatrix& ctm,
const Context& ctx,
SkBitmap* dst,
SkIPoint* offset) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool canFilterImageGPU() const SK_OVERRIDE { return !cropRectIsSet(); }
virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#endif
@ -43,6 +46,12 @@ protected:
explicit SkXfermodeImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
public:
#endif
SkXfermodeImageFilter(SkXfermode* mode, SkImageFilter* background,
SkImageFilter* foreground = NULL, const CropRect* cropRect = NULL);
private:
SkXfermode* fMode;
typedef SkImageFilter INHERITED;

Просмотреть файл

@ -1,46 +0,0 @@
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrBitmapTextContext_DEFINED
#define GrBitmapTextContext_DEFINED
#include "GrTextContext.h"
class GrTextStrike;
/*
* This class implements GrTextContext using standard bitmap fonts
*/
class GrBitmapTextContext : public GrTextContext {
public:
GrBitmapTextContext(GrContext*, const GrPaint&, SkColor);
virtual ~GrBitmapTextContext();
virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top,
GrFontScaler*) SK_OVERRIDE;
private:
GrContext::AutoMatrix fAutoMatrix;
GrTextStrike* fStrike;
void flushGlyphs(); // automatically called by destructor
enum {
kMinRequestedGlyphs = 1,
kDefaultRequestedGlyphs = 64,
kMinRequestedVerts = kMinRequestedGlyphs * 4,
kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4,
};
SkColor fSkPaintColor;
SkPoint* fVertices;
int32_t fMaxVertices;
GrTexture* fCurrTexture;
int fCurrVertex;
};
#endif

Просмотреть файл

@ -306,6 +306,19 @@ public:
*/
int getMaxSampleCount() const;
/**
* Returns the recommended sample count for a render target when using this
* context.
*
* @param config the configuration of the render target.
* @param dpi the display density in dots per inch.
*
* @return sample count that should be perform well and have good enough
* rendering quality for the display. Alternatively returns 0 if
* MSAA is not supported or recommended to be used by default.
*/
int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const;
///////////////////////////////////////////////////////////////////////////
// Backend Surfaces

Просмотреть файл

@ -1,46 +0,0 @@
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrDistanceFieldTextContext_DEFINED
#define GrDistanceFieldTextContext_DEFINED
#include "GrTextContext.h"
class GrTextStrike;
/*
* This class implements GrTextContext using distance field fonts
*/
class GrDistanceFieldTextContext : public GrTextContext {
public:
GrDistanceFieldTextContext(GrContext*, const GrPaint&, SkColor, SkScalar textRatio);
virtual ~GrDistanceFieldTextContext();
virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top,
GrFontScaler*) SK_OVERRIDE;
private:
GrTextStrike* fStrike;
SkScalar fTextRatio;
void flushGlyphs(); // automatically called by destructor
enum {
kMinRequestedGlyphs = 1,
kDefaultRequestedGlyphs = 64,
kMinRequestedVerts = kMinRequestedGlyphs * 4,
kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4,
};
SkColor fSkPaintColor;
SkPoint* fVertices;
int32_t fMaxVertices;
GrTexture* fCurrTexture;
int fCurrVertex;
};
#endif

Просмотреть файл

@ -64,7 +64,7 @@ public:
/** Returns a new instance of the appropriate *GL* implementation class
for the given GrEffect; caller is responsible for deleting
the object. */
virtual GLEffect* createGLInstance(const GrDrawEffect& drawEffect) const SK_OVERRIDE {
virtual GrGLEffect* createGLInstance(const GrDrawEffect& drawEffect) const SK_OVERRIDE {
return SkNEW_ARGS(GLEffect, (*this, drawEffect));
}

Просмотреть файл

@ -1,40 +0,0 @@
/*
* Copyright 2010 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrTextContext_DEFINED
#define GrTextContext_DEFINED
#include "GrContext.h"
#include "GrGlyph.h"
#include "GrPaint.h"
class GrContext;
class GrDrawTarget;
class GrFontScaler;
/*
* This class wraps the state for a single text render
*/
class GrTextContext {
public:
virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top,
GrFontScaler*) = 0;
protected:
GrTextContext(GrContext*, const GrPaint&);
virtual ~GrTextContext() {}
GrPaint fPaint;
GrContext* fContext;
GrDrawTarget* fDrawTarget;
SkIRect fClipRect;
private:
};
#endif

Просмотреть файл

@ -60,6 +60,8 @@ static inline GrSLType GrSLFloatVectorType(int count) {
GR_STATIC_ASSERT(kVec4f_GrSLType == 4);
}
//////////////////////////////////////////////////////////////////////////////
/**
* Types used to describe format of vertices in arrays.
*/
@ -166,4 +168,53 @@ struct GrVertexAttrib {
template <int N> class GrVertexAttribArray : public SkSTArray<N, GrVertexAttrib, true> {};
//////////////////////////////////////////////////////////////////////////////
/**
* We have coverage effects that clip rendering to the edge of some geometric primitive.
* This enum specifies how that clipping is performed. Not all factories that take a
* GrEffectEdgeType will succeed with all values and it is up to the caller to check for
* a NULL return.
*/
enum GrEffectEdgeType {
kFillBW_GrEffectEdgeType,
kFillAA_GrEffectEdgeType,
kInverseFillBW_GrEffectEdgeType,
kInverseFillAA_GrEffectEdgeType,
kHairlineAA_GrEffectEdgeType,
kLast_GrEffectEdgeType = kHairlineAA_GrEffectEdgeType
};
static const int kGrEffectEdgeTypeCnt = kLast_GrEffectEdgeType + 1;
static inline bool GrEffectEdgeTypeIsFill(const GrEffectEdgeType edgeType) {
return (kFillAA_GrEffectEdgeType == edgeType || kFillBW_GrEffectEdgeType == edgeType);
}
static inline bool GrEffectEdgeTypeIsInverseFill(const GrEffectEdgeType edgeType) {
return (kInverseFillAA_GrEffectEdgeType == edgeType ||
kInverseFillBW_GrEffectEdgeType == edgeType);
}
static inline bool GrEffectEdgeTypeIsAA(const GrEffectEdgeType edgeType) {
return (kFillBW_GrEffectEdgeType != edgeType && kInverseFillBW_GrEffectEdgeType != edgeType);
}
static inline GrEffectEdgeType GrInvertEffectEdgeType(const GrEffectEdgeType edgeType) {
switch (edgeType) {
case kFillBW_GrEffectEdgeType:
return kInverseFillBW_GrEffectEdgeType;
case kFillAA_GrEffectEdgeType:
return kInverseFillAA_GrEffectEdgeType;
case kInverseFillBW_GrEffectEdgeType:
return kFillBW_GrEffectEdgeType;
case kInverseFillAA_GrEffectEdgeType:
return kFillAA_GrEffectEdgeType;
case kHairlineAA_GrEffectEdgeType:
GrCrash("Hairline fill isn't invertible.");
}
return kFillAA_GrEffectEdgeType; // suppress warning.
}
#endif

Просмотреть файл

@ -14,6 +14,7 @@
#include "SkGr.h"
#include "SkBitmap.h"
#include "SkBitmapDevice.h"
#include "SkPicture.h"
#include "SkRegion.h"
#include "GrContext.h"
@ -35,6 +36,15 @@ public:
*/
static SkGpuDevice* Create(GrSurface* surface);
/**
* New device that will create an offscreen renderTarget based on the
* ImageInfo and sampleCount. The device's storage will not
* count against the GrContext's texture cache budget. The device's pixels
* will be uninitialized. On failure, returns NULL.
*/
static SkGpuDevice* Create(GrContext*, const SkImageInfo&, int sampleCount);
#ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG
/**
* New device that will create an offscreen renderTarget based on the
* config, width, height, and sampleCount. The device's storage will not
@ -42,6 +52,7 @@ public:
* will be uninitialized. TODO: This can fail, replace with a factory function.
*/
SkGpuDevice(GrContext*, SkBitmap::Config, int width, int height, int sampleCount = 0);
#endif
/**
* DEPRECATED -- need to make this private, call Create(surface)
@ -64,9 +75,6 @@ public:
virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE;
// overrides from SkBaseDevice
virtual uint32_t getDeviceCapabilities() SK_OVERRIDE {
return 0;
}
virtual int width() const SK_OVERRIDE {
return NULL == fRenderTarget ? 0 : fRenderTarget->width();
}
@ -80,9 +88,10 @@ public:
virtual SkBitmap::Config config() const SK_OVERRIDE;
virtual void clear(SkColor color) SK_OVERRIDE;
#ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
virtual void writePixels(const SkBitmap& bitmap, int x, int y,
SkCanvas::Config8888 config8888) SK_OVERRIDE;
#endif
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;
@ -132,16 +141,21 @@ public:
virtual void makeRenderTargetCurrent();
virtual bool canHandleImageFilter(const SkImageFilter*) SK_OVERRIDE;
virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkMatrix&,
virtual bool filterImage(const SkImageFilter*, const SkBitmap&,
const SkImageFilter::Context&,
SkBitmap*, SkIPoint*) SK_OVERRIDE;
class SkAutoCachedTexture; // used internally
protected:
// overrides from SkBaseDevice
virtual bool onReadPixels(const SkBitmap& bitmap,
int x, int y,
SkCanvas::Config8888 config8888) SK_OVERRIDE;
virtual bool onReadPixels(const SkBitmap&, int x, int y, SkCanvas::Config8888) SK_OVERRIDE;
virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) SK_OVERRIDE;
/** PRIVATE / EXPERIMENTAL -- do not call */
virtual void EXPERIMENTAL_optimize(SkPicture* picture) SK_OVERRIDE;
/** PRIVATE / EXPERIMENTAL -- do not call */
virtual bool EXPERIMENTAL_drawPicture(const SkPicture& picture) SK_OVERRIDE;
private:
GrContext* fContext;
@ -163,11 +177,7 @@ private:
// used by createCompatibleDevice
SkGpuDevice(GrContext*, GrTexture* texture, bool needClear);
// override from SkBaseDevice
virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config,
int width, int height,
bool isOpaque,
Usage usage) SK_OVERRIDE;
virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE;
virtual SkSurface* newSurface(const SkImageInfo&) SK_OVERRIDE;
@ -212,6 +222,8 @@ private:
int tileSize,
bool bicubic);
static SkPicture::AccelData::Key ComputeAccelDataKey();
typedef SkBitmapDevice INHERITED;
};

Просмотреть файл

@ -50,6 +50,7 @@ GR_STATIC_ASSERT((int)kIDA_GrBlendCoeff == (int)SkXfermode::kIDA_Coeff);
* kUnknown_PixelConfig if the conversion cannot be done.
*/
GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config);
GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType);
bool GrPixelConfig2ColorType(GrPixelConfig, SkColorType*);
static inline GrColor SkColor2GrColor(SkColor c) {

Просмотреть файл

@ -19,7 +19,7 @@ struct GrGLInterface;
* queried. It supports both glGetString- and glGetStringi-style extension string APIs and will
* use the latter if it is available.
*/
class GrGLExtensions {
class SK_API GrGLExtensions {
public:
GrGLExtensions() : fInitialized(false), fStrings(SkNEW(SkTArray<SkString>)) {}
@ -54,6 +54,11 @@ public:
*/
bool remove(const char[]);
/**
* Adds an extension to list
*/
void add(const char[]);
void reset() { fStrings->reset(); }
void print(const char* sep = "\n") const;

Просмотреть файл

@ -23,11 +23,6 @@ enum GrGLStandard {
kGLES_GrGLStandard,
};
// Temporary aliases until Chromium can be updated.
typedef GrGLStandard GrGLBinding;
static const GrGLStandard kES2_GrGLBinding = kGLES_GrGLStandard;
static const GrGLStandard kDesktop_GrGLBinding = kGL_GrGLStandard;
///////////////////////////////////////////////////////////////////////////////
/**
@ -106,14 +101,12 @@ extern "C" {
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLDeleteVertexArraysProc)(GrGLsizei n, const GrGLuint *arrays);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLDepthMaskProc)(GrGLboolean flag);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLDisableProc)(GrGLenum cap);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLDisableClientStateProc)(GrGLenum cap);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLDisableVertexAttribArrayProc)(GrGLuint index);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLDrawArraysProc)(GrGLenum mode, GrGLint first, GrGLsizei count);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLDrawBufferProc)(GrGLenum mode);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLDrawBuffersProc)(GrGLsizei n, const GrGLenum* bufs);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLDrawElementsProc)(GrGLenum mode, GrGLsizei count, GrGLenum type, const GrGLvoid* indices);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLEnableProc)(GrGLenum cap);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLEnableClientStateProc)(GrGLenum cap);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLEnableVertexAttribArrayProc)(GrGLuint index);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLEndQueryProc)(GrGLenum target);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLFinishProc)();
@ -147,10 +140,13 @@ extern "C" {
typedef const GrGLubyte* (GR_GL_FUNCTION_TYPE* GrGLGetStringiProc)(GrGLenum name, GrGLuint index);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLGetTexLevelParameterivProc)(GrGLenum target, GrGLint level, GrGLenum pname, GrGLint* params);
typedef GrGLint (GR_GL_FUNCTION_TYPE* GrGLGetUniformLocationProc)(GrGLuint program, const char* name);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLInsertEventMarkerProc)(GrGLsizei length, const char* marker);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLLineWidthProc)(GrGLfloat width);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLLinkProgramProc)(GrGLuint program);
typedef GrGLvoid* (GR_GL_FUNCTION_TYPE* GrGLMapBufferProc)(GrGLenum target, GrGLenum access);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLPixelStoreiProc)(GrGLenum pname, GrGLint param);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLPopGroupMarkerProc)();
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLPushGroupMarkerProc)(GrGLsizei length, const char* marker);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLQueryCounterProc)(GrGLuint id, GrGLenum target);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLReadBufferProc)(GrGLenum src);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLReadPixelsProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels);
@ -203,7 +199,6 @@ extern "C" {
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLUseProgramProc)(GrGLuint program);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLVertexAttrib4fvProc)(GrGLuint indx, const GrGLfloat* values);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLVertexAttribPointerProc)(GrGLuint indx, GrGLint size, GrGLenum type, GrGLboolean normalized, GrGLsizei stride, const GrGLvoid* ptr);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLVertexPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLViewportProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
// Experimental: Functions for GL_NV_path_rendering. These will be
@ -261,6 +256,7 @@ extern "C" {
typedef GrGLboolean (GR_GL_FUNCTION_TYPE* GrGLIsPointInStrokePathProc)(GrGLuint path, GrGLfloat x, GrGLfloat y);
typedef GrGLfloat (GR_GL_FUNCTION_TYPE* GrGLGetPathLengthProc)(GrGLuint path, GrGLsizei startSegment, GrGLsizei numSegments);
typedef GrGLboolean (GR_GL_FUNCTION_TYPE* GrGLPointAlongPathProc)(GrGLuint path, GrGLsizei startSegment, GrGLsizei numSegments, GrGLfloat distance, GrGLfloat *x, GrGLfloat *y, GrGLfloat *tangentX, GrGLfloat *tangentY);
} // extern "C"
#endif

Просмотреть файл

@ -76,6 +76,13 @@ typedef intptr_t GrGLInterfaceCallbackData;
GL_NV_path_rendering. */
const GrGLInterface* GrGLInterfaceRemoveNVPR(const GrGLInterface*);
/** Function that returns a new interface identical to "interface" but with support for
test version of GL_EXT_debug_marker. */
const GrGLInterface* GrGLInterfaceAddTestDebugMarker(const GrGLInterface*,
GrGLInsertEventMarkerProc insertEventMarkerFn,
GrGLPushGroupMarkerProc pushGroupMarkerFn,
GrGLPopGroupMarkerProc popGroupMarkerFn);
/**
* GrContext uses the following interface to make all calls into OpenGL. When a
* GrContext is created it is given a GrGLInterface. The interface's function
@ -131,18 +138,7 @@ public:
GrGLExtensions fExtensions;
// This wrapper and const hackery is necessary because the factories in Chromium do not yet
// initialize fExtensions.
bool hasExtension(const char ext[]) const {
if (!fExtensions.isInitialized()) {
GrGLExtensions* extensions = const_cast<GrGLExtensions*>(&fExtensions);
if (!extensions->init(fStandard, fFunctions.fGetString,
fFunctions.fGetStringi, fFunctions.fGetIntegerv)) {
return false;
}
}
return fExtensions.has(ext);
}
bool hasExtension(const char ext[]) const { return fExtensions.has(ext); }
/**
* The function pointers are in a struct so that we can have a compiler generated assignment
@ -169,7 +165,6 @@ public:
GLPtr<GrGLClearProc> fClear;
GLPtr<GrGLClearColorProc> fClearColor;
GLPtr<GrGLClearStencilProc> fClearStencil;
GLPtr<GrGLClientActiveTextureProc> fClientActiveTexture;
GLPtr<GrGLColorMaskProc> fColorMask;
GLPtr<GrGLCompileShaderProc> fCompileShader;
GLPtr<GrGLCompressedTexImage2DProc> fCompressedTexImage2D;
@ -187,14 +182,12 @@ public:
GLPtr<GrGLDeleteVertexArraysProc> fDeleteVertexArrays;
GLPtr<GrGLDepthMaskProc> fDepthMask;
GLPtr<GrGLDisableProc> fDisable;
GLPtr<GrGLDisableClientStateProc> fDisableClientState;
GLPtr<GrGLDisableVertexAttribArrayProc> fDisableVertexAttribArray;
GLPtr<GrGLDrawArraysProc> fDrawArrays;
GLPtr<GrGLDrawBufferProc> fDrawBuffer;
GLPtr<GrGLDrawBuffersProc> fDrawBuffers;
GLPtr<GrGLDrawElementsProc> fDrawElements;
GLPtr<GrGLEnableProc> fEnable;
GLPtr<GrGLEnableClientStateProc> fEnableClientState;
GLPtr<GrGLEnableVertexAttribArrayProc> fEnableVertexAttribArray;
GLPtr<GrGLEndQueryProc> fEndQuery;
GLPtr<GrGLFinishProc> fFinish;
@ -228,6 +221,7 @@ public:
GLPtr<GrGLGetStringiProc> fGetStringi;
GLPtr<GrGLGetTexLevelParameterivProc> fGetTexLevelParameteriv;
GLPtr<GrGLGetUniformLocationProc> fGetUniformLocation;
GLPtr<GrGLInsertEventMarkerProc> fInsertEventMarker;
GLPtr<GrGLLineWidthProc> fLineWidth;
GLPtr<GrGLLinkProgramProc> fLinkProgram;
GLPtr<GrGLLoadIdentityProc> fLoadIdentity;
@ -235,6 +229,8 @@ public:
GLPtr<GrGLMapBufferProc> fMapBuffer;
GLPtr<GrGLMatrixModeProc> fMatrixMode;
GLPtr<GrGLPixelStoreiProc> fPixelStorei;
GLPtr<GrGLPopGroupMarkerProc> fPopGroupMarker;
GLPtr<GrGLPushGroupMarkerProc> fPushGroupMarker;
GLPtr<GrGLQueryCounterProc> fQueryCounter;
GLPtr<GrGLReadBufferProc> fReadBuffer;
GLPtr<GrGLReadPixelsProc> fReadPixels;
@ -275,7 +271,6 @@ public:
GLPtr<GrGLStencilMaskSeparateProc> fStencilMaskSeparate;
GLPtr<GrGLStencilOpProc> fStencilOp;
GLPtr<GrGLStencilOpSeparateProc> fStencilOpSeparate;
GLPtr<GrGLTexGenfProc> fTexGenf;
GLPtr<GrGLTexGenfvProc> fTexGenfv;
GLPtr<GrGLTexGeniProc> fTexGeni;
GLPtr<GrGLTexImage2DProc> fTexImage2D;
@ -307,7 +302,6 @@ public:
GLPtr<GrGLUseProgramProc> fUseProgram;
GLPtr<GrGLVertexAttrib4fvProc> fVertexAttrib4fv;
GLPtr<GrGLVertexAttribPointerProc> fVertexAttribPointer;
GLPtr<GrGLVertexPointerProc> fVertexPointer;
GLPtr<GrGLViewportProc> fViewport;
// Experimental: Functions for GL_NV_path_rendering. These will be
@ -364,201 +358,11 @@ public:
GLPtr<GrGLPointAlongPathProc> fPointAlongPath;
} fFunctions;
// Temporary workaround aliases to keep Chromium GrGLInterface factories compiling until they
// assign the members of fFunctions.
GLPtrAlias<GrGLActiveTextureProc> fActiveTexture;
GLPtrAlias<GrGLAttachShaderProc> fAttachShader;
GLPtrAlias<GrGLBeginQueryProc> fBeginQuery;
GLPtrAlias<GrGLBindAttribLocationProc> fBindAttribLocation;
GLPtrAlias<GrGLBindBufferProc> fBindBuffer;
GLPtrAlias<GrGLBindFragDataLocationProc> fBindFragDataLocation;
GLPtrAlias<GrGLBindFragDataLocationIndexedProc> fBindFragDataLocationIndexed;
GLPtrAlias<GrGLBindFramebufferProc> fBindFramebuffer;
GLPtrAlias<GrGLBindRenderbufferProc> fBindRenderbuffer;
GLPtrAlias<GrGLBindTextureProc> fBindTexture;
GLPtrAlias<GrGLBindVertexArrayProc> fBindVertexArray;
GLPtrAlias<GrGLBlendColorProc> fBlendColor;
GLPtrAlias<GrGLBlendFuncProc> fBlendFunc;
GLPtrAlias<GrGLBlitFramebufferProc> fBlitFramebuffer;
GLPtrAlias<GrGLBufferDataProc> fBufferData;
GLPtrAlias<GrGLBufferSubDataProc> fBufferSubData;
GLPtrAlias<GrGLCheckFramebufferStatusProc> fCheckFramebufferStatus;
GLPtrAlias<GrGLClearProc> fClear;
GLPtrAlias<GrGLClearColorProc> fClearColor;
GLPtrAlias<GrGLClearStencilProc> fClearStencil;
GLPtrAlias<GrGLClientActiveTextureProc> fClientActiveTexture;
GLPtrAlias<GrGLColorMaskProc> fColorMask;
GLPtrAlias<GrGLCompileShaderProc> fCompileShader;
GLPtrAlias<GrGLCompressedTexImage2DProc> fCompressedTexImage2D;
GLPtrAlias<GrGLCopyTexSubImage2DProc> fCopyTexSubImage2D;
GLPtrAlias<GrGLCreateProgramProc> fCreateProgram;
GLPtrAlias<GrGLCreateShaderProc> fCreateShader;
GLPtrAlias<GrGLCullFaceProc> fCullFace;
GLPtrAlias<GrGLDeleteBuffersProc> fDeleteBuffers;
GLPtrAlias<GrGLDeleteFramebuffersProc> fDeleteFramebuffers;
GLPtrAlias<GrGLDeleteProgramProc> fDeleteProgram;
GLPtrAlias<GrGLDeleteQueriesProc> fDeleteQueries;
GLPtrAlias<GrGLDeleteRenderbuffersProc> fDeleteRenderbuffers;
GLPtrAlias<GrGLDeleteShaderProc> fDeleteShader;
GLPtrAlias<GrGLDeleteTexturesProc> fDeleteTextures;
GLPtrAlias<GrGLDeleteVertexArraysProc> fDeleteVertexArrays;
GLPtrAlias<GrGLDepthMaskProc> fDepthMask;
GLPtrAlias<GrGLDisableProc> fDisable;
GLPtrAlias<GrGLDisableClientStateProc> fDisableClientState;
GLPtrAlias<GrGLDisableVertexAttribArrayProc> fDisableVertexAttribArray;
GLPtrAlias<GrGLDrawArraysProc> fDrawArrays;
GLPtrAlias<GrGLDrawBufferProc> fDrawBuffer;
GLPtrAlias<GrGLDrawBuffersProc> fDrawBuffers;
GLPtrAlias<GrGLDrawElementsProc> fDrawElements;
GLPtrAlias<GrGLEnableProc> fEnable;
GLPtrAlias<GrGLEnableClientStateProc> fEnableClientState;
GLPtrAlias<GrGLEnableVertexAttribArrayProc> fEnableVertexAttribArray;
GLPtrAlias<GrGLEndQueryProc> fEndQuery;
GLPtrAlias<GrGLFinishProc> fFinish;
GLPtrAlias<GrGLFlushProc> fFlush;
GLPtrAlias<GrGLFramebufferRenderbufferProc> fFramebufferRenderbuffer;
GLPtrAlias<GrGLFramebufferTexture2DProc> fFramebufferTexture2D;
GLPtrAlias<GrGLFramebufferTexture2DMultisampleProc> fFramebufferTexture2DMultisample;
GLPtrAlias<GrGLFrontFaceProc> fFrontFace;
GLPtrAlias<GrGLGenBuffersProc> fGenBuffers;
GLPtrAlias<GrGLGenFramebuffersProc> fGenFramebuffers;
GLPtrAlias<GrGLGenerateMipmapProc> fGenerateMipmap;
GLPtrAlias<GrGLGenQueriesProc> fGenQueries;
GLPtrAlias<GrGLGenRenderbuffersProc> fGenRenderbuffers;
GLPtrAlias<GrGLGenTexturesProc> fGenTextures;
GLPtrAlias<GrGLGenVertexArraysProc> fGenVertexArrays;
GLPtrAlias<GrGLGetBufferParameterivProc> fGetBufferParameteriv;
GLPtrAlias<GrGLGetErrorProc> fGetError;
GLPtrAlias<GrGLGetFramebufferAttachmentParameterivProc> fGetFramebufferAttachmentParameteriv;
GLPtrAlias<GrGLGetIntegervProc> fGetIntegerv;
GLPtrAlias<GrGLGetQueryObjecti64vProc> fGetQueryObjecti64v;
GLPtrAlias<GrGLGetQueryObjectivProc> fGetQueryObjectiv;
GLPtrAlias<GrGLGetQueryObjectui64vProc> fGetQueryObjectui64v;
GLPtrAlias<GrGLGetQueryObjectuivProc> fGetQueryObjectuiv;
GLPtrAlias<GrGLGetQueryivProc> fGetQueryiv;
GLPtrAlias<GrGLGetProgramInfoLogProc> fGetProgramInfoLog;
GLPtrAlias<GrGLGetProgramivProc> fGetProgramiv;
GLPtrAlias<GrGLGetRenderbufferParameterivProc> fGetRenderbufferParameteriv;
GLPtrAlias<GrGLGetShaderInfoLogProc> fGetShaderInfoLog;
GLPtrAlias<GrGLGetShaderivProc> fGetShaderiv;
GLPtrAlias<GrGLGetStringProc> fGetString;
GLPtrAlias<GrGLGetStringiProc> fGetStringi;
GLPtrAlias<GrGLGetTexLevelParameterivProc> fGetTexLevelParameteriv;
GLPtrAlias<GrGLGetUniformLocationProc> fGetUniformLocation;
GLPtrAlias<GrGLLineWidthProc> fLineWidth;
GLPtrAlias<GrGLLinkProgramProc> fLinkProgram;
GLPtrAlias<GrGLLoadIdentityProc> fLoadIdentity;
GLPtrAlias<GrGLLoadMatrixfProc> fLoadMatrixf;
GLPtrAlias<GrGLMapBufferProc> fMapBuffer;
GLPtrAlias<GrGLMatrixModeProc> fMatrixMode;
GLPtrAlias<GrGLPixelStoreiProc> fPixelStorei;
GLPtrAlias<GrGLQueryCounterProc> fQueryCounter;
GLPtrAlias<GrGLReadBufferProc> fReadBuffer;
GLPtrAlias<GrGLReadPixelsProc> fReadPixels;
GLPtrAlias<GrGLRenderbufferStorageProc> fRenderbufferStorage;
GLPtrAlias<GrGLRenderbufferStorageMultisampleProc> fRenderbufferStorageMultisampleES2EXT;
GLPtrAlias<GrGLRenderbufferStorageMultisampleProc> fRenderbufferStorageMultisampleES2APPLE;
GLPtrAlias<GrGLRenderbufferStorageMultisampleProc> fRenderbufferStorageMultisample;
GLPtrAlias<GrGLBindUniformLocation> fBindUniformLocation;
GLPtrAlias<GrGLResolveMultisampleFramebufferProc> fResolveMultisampleFramebuffer;
GLPtrAlias<GrGLScissorProc> fScissor;
GLPtrAlias<GrGLShaderSourceProc> fShaderSource;
GLPtrAlias<GrGLStencilFuncProc> fStencilFunc;
GLPtrAlias<GrGLStencilFuncSeparateProc> fStencilFuncSeparate;
GLPtrAlias<GrGLStencilMaskProc> fStencilMask;
GLPtrAlias<GrGLStencilMaskSeparateProc> fStencilMaskSeparate;
GLPtrAlias<GrGLStencilOpProc> fStencilOp;
GLPtrAlias<GrGLStencilOpSeparateProc> fStencilOpSeparate;
GLPtrAlias<GrGLTexGenfProc> fTexGenf;
GLPtrAlias<GrGLTexGenfvProc> fTexGenfv;
GLPtrAlias<GrGLTexGeniProc> fTexGeni;
GLPtrAlias<GrGLTexImage2DProc> fTexImage2D;
GLPtrAlias<GrGLTexParameteriProc> fTexParameteri;
GLPtrAlias<GrGLTexParameterivProc> fTexParameteriv;
GLPtrAlias<GrGLTexSubImage2DProc> fTexSubImage2D;
GLPtrAlias<GrGLTexStorage2DProc> fTexStorage2D;
GLPtrAlias<GrGLDiscardFramebufferProc> fDiscardFramebuffer;
GLPtrAlias<GrGLUniform1fProc> fUniform1f;
GLPtrAlias<GrGLUniform1iProc> fUniform1i;
GLPtrAlias<GrGLUniform1fvProc> fUniform1fv;
GLPtrAlias<GrGLUniform1ivProc> fUniform1iv;
GLPtrAlias<GrGLUniform2fProc> fUniform2f;
GLPtrAlias<GrGLUniform2iProc> fUniform2i;
GLPtrAlias<GrGLUniform2fvProc> fUniform2fv;
GLPtrAlias<GrGLUniform2ivProc> fUniform2iv;
GLPtrAlias<GrGLUniform3fProc> fUniform3f;
GLPtrAlias<GrGLUniform3iProc> fUniform3i;
GLPtrAlias<GrGLUniform3fvProc> fUniform3fv;
GLPtrAlias<GrGLUniform3ivProc> fUniform3iv;
GLPtrAlias<GrGLUniform4fProc> fUniform4f;
GLPtrAlias<GrGLUniform4iProc> fUniform4i;
GLPtrAlias<GrGLUniform4fvProc> fUniform4fv;
GLPtrAlias<GrGLUniform4ivProc> fUniform4iv;
GLPtrAlias<GrGLUniformMatrix2fvProc> fUniformMatrix2fv;
GLPtrAlias<GrGLUniformMatrix3fvProc> fUniformMatrix3fv;
GLPtrAlias<GrGLUniformMatrix4fvProc> fUniformMatrix4fv;
GLPtrAlias<GrGLUnmapBufferProc> fUnmapBuffer;
GLPtrAlias<GrGLUseProgramProc> fUseProgram;
GLPtrAlias<GrGLVertexAttrib4fvProc> fVertexAttrib4fv;
GLPtrAlias<GrGLVertexAttribPointerProc> fVertexAttribPointer;
GLPtrAlias<GrGLVertexPointerProc> fVertexPointer;
GLPtrAlias<GrGLViewportProc> fViewport;
GLPtrAlias<GrGLPathCommandsProc> fPathCommands;
GLPtrAlias<GrGLPathCoordsProc> fPathCoords;
GLPtrAlias<GrGLPathSubCommandsProc> fPathSubCommands;
GLPtrAlias<GrGLPathSubCoordsProc> fPathSubCoords;
GLPtrAlias<GrGLPathStringProc> fPathString;
GLPtrAlias<GrGLPathGlyphsProc> fPathGlyphs;
GLPtrAlias<GrGLPathGlyphRangeProc> fPathGlyphRange;
GLPtrAlias<GrGLWeightPathsProc> fWeightPaths;
GLPtrAlias<GrGLCopyPathProc> fCopyPath;
GLPtrAlias<GrGLInterpolatePathsProc> fInterpolatePaths;
GLPtrAlias<GrGLTransformPathProc> fTransformPath;
GLPtrAlias<GrGLPathParameterivProc> fPathParameteriv;
GLPtrAlias<GrGLPathParameteriProc> fPathParameteri;
GLPtrAlias<GrGLPathParameterfvProc> fPathParameterfv;
GLPtrAlias<GrGLPathParameterfProc> fPathParameterf;
GLPtrAlias<GrGLPathDashArrayProc> fPathDashArray;
GLPtrAlias<GrGLGenPathsProc> fGenPaths;
GLPtrAlias<GrGLDeletePathsProc> fDeletePaths;
GLPtrAlias<GrGLIsPathProc> fIsPath;
GLPtrAlias<GrGLPathStencilFuncProc> fPathStencilFunc;
GLPtrAlias<GrGLPathStencilDepthOffsetProc> fPathStencilDepthOffset;
GLPtrAlias<GrGLStencilFillPathProc> fStencilFillPath;
GLPtrAlias<GrGLStencilStrokePathProc> fStencilStrokePath;
GLPtrAlias<GrGLStencilFillPathInstancedProc> fStencilFillPathInstanced;
GLPtrAlias<GrGLStencilStrokePathInstancedProc> fStencilStrokePathInstanced;
GLPtrAlias<GrGLPathCoverDepthFuncProc> fPathCoverDepthFunc;
GLPtrAlias<GrGLPathColorGenProc> fPathColorGen;
GLPtrAlias<GrGLPathTexGenProc> fPathTexGen;
GLPtrAlias<GrGLPathFogGenProc> fPathFogGen;
GLPtrAlias<GrGLCoverFillPathProc> fCoverFillPath;
GLPtrAlias<GrGLCoverStrokePathProc> fCoverStrokePath;
GLPtrAlias<GrGLCoverFillPathInstancedProc> fCoverFillPathInstanced;
GLPtrAlias<GrGLCoverStrokePathInstancedProc> fCoverStrokePathInstanced;
GLPtrAlias<GrGLGetPathParameterivProc> fGetPathParameteriv;
GLPtrAlias<GrGLGetPathParameterfvProc> fGetPathParameterfv;
GLPtrAlias<GrGLGetPathCommandsProc> fGetPathCommands;
GLPtrAlias<GrGLGetPathCoordsProc> fGetPathCoords;
GLPtrAlias<GrGLGetPathDashArrayProc> fGetPathDashArray;
GLPtrAlias<GrGLGetPathMetricsProc> fGetPathMetrics;
GLPtrAlias<GrGLGetPathMetricRangeProc> fGetPathMetricRange;
GLPtrAlias<GrGLGetPathSpacingProc> fGetPathSpacing;
GLPtrAlias<GrGLGetPathColorGenivProc> fGetPathColorGeniv;
GLPtrAlias<GrGLGetPathColorGenfvProc> fGetPathColorGenfv;
GLPtrAlias<GrGLGetPathTexGenivProc> fGetPathTexGeniv;
GLPtrAlias<GrGLGetPathTexGenfvProc> fGetPathTexGenfv;
GLPtrAlias<GrGLIsPointInFillPathProc> fIsPointInFillPath;
GLPtrAlias<GrGLIsPointInStrokePathProc> fIsPointInStrokePath;
GLPtrAlias<GrGLGetPathLengthProc> fGetPathLength;
GLPtrAlias<GrGLPointAlongPathProc> fPointAlongPath;
// Per-GL func callback
#if GR_GL_PER_GL_FUNC_CALLBACK
GrGLInterfaceCallbackProc fCallback;
GrGLInterfaceCallbackData fCallbackData;
#endif
};
#endif

Просмотреть файл

@ -70,8 +70,6 @@ public:
const SkMatrix& initialTransform);
SK_API virtual ~SkPDFDevice();
virtual uint32_t getDeviceCapabilities() SK_OVERRIDE;
virtual void clear(SkColor color) SK_OVERRIDE;
/** These are called inside the per-device-layer loop for each draw call.
@ -257,10 +255,7 @@ private:
const SkRegion& existingClipRegion);
// override from SkBaseDevice
virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config,
int width, int height,
bool isOpaque,
Usage usage) SK_OVERRIDE;
virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE;
void init();
void cleanUp(bool clearFontUsage);

Просмотреть файл

@ -11,7 +11,7 @@
#include "SkCanvas.h"
#include "SkPixelRef.h"
class DeferredDevice;
class SkDeferredDevice;
class SkImage;
class SkSurface;
@ -138,25 +138,7 @@ public:
void silentFlush();
// Overrides of the SkCanvas interface
virtual int save(SaveFlags flags) SK_OVERRIDE;
virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) SK_OVERRIDE;
virtual void restore() SK_OVERRIDE;
virtual bool isDrawingToLayer() const SK_OVERRIDE;
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
virtual bool clipRect(const SkRect& rect, SkRegion::Op op,
bool doAntiAlias) SK_OVERRIDE;
virtual bool clipRRect(const SkRRect& rect, SkRegion::Op op,
bool doAntiAlias) SK_OVERRIDE;
virtual bool clipPath(const SkPath& path, SkRegion::Op op,
bool doAntiAlias) SK_OVERRIDE;
virtual bool clipRegion(const SkRegion& deviceRgn,
SkRegion::Op op) SK_OVERRIDE;
virtual void clear(SkColor) SK_OVERRIDE;
virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
@ -200,6 +182,26 @@ public:
virtual SkBounder* setBounder(SkBounder* bounder) SK_OVERRIDE;
virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE;
protected:
virtual void willSave(SaveFlags) SK_OVERRIDE;
virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual void willRestore() SK_OVERRIDE;
virtual void didTranslate(SkScalar, SkScalar) SK_OVERRIDE;
virtual void didScale(SkScalar, SkScalar) SK_OVERRIDE;
virtual void didRotate(SkScalar) SK_OVERRIDE;
virtual void didSkew(SkScalar, SkScalar) SK_OVERRIDE;
virtual void didConcat(const SkMatrix&) SK_OVERRIDE;
virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
virtual void onDrawDRRect(const SkRRect&, const SkRRect&,
const SkPaint&) SK_OVERRIDE;
virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE;
public:
class NotificationClient {
public:
@ -235,10 +237,10 @@ public:
protected:
virtual SkCanvas* canvasForDrawIter();
DeferredDevice* getDeferredDevice() const;
SkDeferredDevice* getDeferredDevice() const;
private:
SkDeferredCanvas(DeferredDevice*);
SkDeferredCanvas(SkDeferredDevice*);
void recordedDrawCommand();
SkCanvas* drawingCanvas() const;

Просмотреть файл

@ -40,6 +40,7 @@ public:
kDrawOval_Verb,
kDrawRect_Verb,
kDrawRRect_Verb,
kDrawDRRect_Verb,
kDrawPath_Verb,
kDrawBitmap_Verb,
kDrawText_Verb,
@ -49,7 +50,9 @@ public:
kBeginCommentGroup_Verb,
kAddComment_Verb,
kEndCommentGroup_Verb
kEndCommentGroup_Verb,
kCull_Verb
};
/** Subclasses of this are installed on the DumpCanvas, and then called for
@ -71,24 +74,6 @@ public:
int getNestLevel() const { return fNestLevel; }
virtual int save(SaveFlags) SK_OVERRIDE;
virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags) SK_OVERRIDE;
virtual void restore() SK_OVERRIDE;
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
virtual bool clipRRect(const SkRRect&, SkRegion::Op, bool) SK_OVERRIDE;
virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
virtual bool clipRegion(const SkRegion& deviceRgn,
SkRegion::Op) SK_OVERRIDE;
virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
const SkPaint& paint) SK_OVERRIDE;
@ -126,6 +111,29 @@ public:
virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
virtual void endCommentGroup() SK_OVERRIDE;
protected:
virtual void willSave(SaveFlags) SK_OVERRIDE;
virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual void willRestore() SK_OVERRIDE;
virtual void didTranslate(SkScalar, SkScalar) SK_OVERRIDE;
virtual void didScale(SkScalar, SkScalar) SK_OVERRIDE;
virtual void didRotate(SkScalar) SK_OVERRIDE;
virtual void didSkew(SkScalar, SkScalar) SK_OVERRIDE;
virtual void didConcat(const SkMatrix&) SK_OVERRIDE;
virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
virtual void onPopCull() SK_OVERRIDE;
virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE;
static const char* EdgeStyleToAAString(ClipEdgeStyle edgeStyle);
private:
Dumper* fDumper;
int fNestLevel; // for nesting recursive elements like pictures

Просмотреть файл

@ -8,6 +8,7 @@
#ifndef SkLua_DEFINED
#define SkLua_DEFINED
#include "SkClipStack.h"
#include "SkColor.h"
#include "SkScalar.h"
#include "SkString.h"
@ -53,6 +54,11 @@ public:
void pushPaint(const SkPaint&, const char tableKey[] = NULL);
void pushPath(const SkPath&, const char tableKey[] = NULL);
void pushCanvas(SkCanvas*, const char tableKey[] = NULL);
void pushClipStack(const SkClipStack&, const char tableKey[] = NULL);
void pushClipStackElement(const SkClipStack::Element& element, const char tableKey[] = NULL);
// This SkCanvas lua methods is declared here to benefit from SkLua's friendship with SkCanvas.
static int lcanvas_getReducedClipStack(lua_State* L);
private:
lua_State* fL;

Просмотреть файл

@ -20,24 +20,6 @@ public:
SkLuaCanvas(int width, int height, lua_State*, const char function[]);
virtual ~SkLuaCanvas();
virtual int save(SaveFlags flags) SK_OVERRIDE;
virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) SK_OVERRIDE;
virtual void restore() SK_OVERRIDE;
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
virtual bool clipRRect(const SkRRect&, SkRegion::Op, bool) SK_OVERRIDE;
virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
virtual bool clipRegion(const SkRegion& deviceRgn,
SkRegion::Op) SK_OVERRIDE;
virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
const SkPaint& paint) SK_OVERRIDE;
@ -72,6 +54,25 @@ public:
const SkPaint& paint) SK_OVERRIDE;
virtual void drawData(const void* data, size_t length) SK_OVERRIDE;
protected:
virtual void willSave(SaveFlags) SK_OVERRIDE;
virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual void willRestore() SK_OVERRIDE;
virtual void didTranslate(SkScalar, SkScalar) SK_OVERRIDE;
virtual void didScale(SkScalar, SkScalar) SK_OVERRIDE;
virtual void didRotate(SkScalar) SK_OVERRIDE;
virtual void didSkew(SkScalar, SkScalar) SK_OVERRIDE;
virtual void didConcat(const SkMatrix&) SK_OVERRIDE;
virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE;
private:
lua_State* fL;
SkString fFunc;

Просмотреть файл

@ -23,21 +23,6 @@ public:
///////////////////////////////////////////////////////////////////////////
// These are forwarded to the N canvases we're referencing
virtual int save(SaveFlags) SK_OVERRIDE;
virtual int saveLayer(const SkRect* bounds, const SkPaint*,
SaveFlags) SK_OVERRIDE;
virtual void restore() SK_OVERRIDE;
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
virtual bool clipRRect(const SkRRect&, SkRegion::Op, bool) SK_OVERRIDE;
virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
virtual bool clipRegion(const SkRegion& deviceRgn,
SkRegion::Op) SK_OVERRIDE;
virtual void clear(SkColor) SK_OVERRIDE;
virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
@ -86,6 +71,24 @@ public:
protected:
SkTDArray<SkCanvas*> fList;
virtual void willSave(SaveFlags) SK_OVERRIDE;
virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual void willRestore() SK_OVERRIDE;
virtual void didTranslate(SkScalar, SkScalar) SK_OVERRIDE;
virtual void didScale(SkScalar, SkScalar) SK_OVERRIDE;
virtual void didRotate(SkScalar) SK_OVERRIDE;
virtual void didSkew(SkScalar, SkScalar) SK_OVERRIDE;
virtual void didConcat(const SkMatrix&) SK_OVERRIDE;
virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE;
class Iter;
private:

Просмотреть файл

@ -0,0 +1,47 @@
/*
* 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 SkNoSaveLayerCanvas_DEFINED
#define SkNoSaveLayerCanvas_DEFINED
#include "SkCanvas.h"
#include "SkRRect.h"
// The NoSaveLayerCanvas is used to play back SkPictures when the saveLayer
// functionality isn't required (e.g., during analysis of the draw calls).
// It also simplifies the clipping calls to only use rectangles.
class SK_API SkNoSaveLayerCanvas : public SkCanvas {
public:
SkNoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {}
protected:
virtual SaveLayerStrategy willSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) SK_OVERRIDE {
this->INHERITED::willSaveLayer(bounds, paint, flags);
return kNoLayer_SaveLayerStrategy;
}
// disable aa for speed
virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle) SK_OVERRIDE {
this->INHERITED::onClipRect(rect, op, kHard_ClipEdgeStyle);
}
// for speed, just respect the bounds, and disable AA. May give us a few
// false positives and negatives.
virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle) SK_OVERRIDE {
this->updateClipConservativelyUsingBounds(path.getBounds(), op,
path.isInverseFillType());
}
virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle) SK_OVERRIDE {
this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false);
}
private:
typedef SkCanvas INHERITED;
};
#endif // SkNoSaveLayerCanvas_DEFINED

Просмотреть файл

@ -26,24 +26,6 @@ public:
SkCanvas* getProxy() const { return fProxy; }
void setProxy(SkCanvas* proxy);
virtual int save(SaveFlags flags = kMatrixClip_SaveFlag) SK_OVERRIDE;
virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags = kARGB_ClipLayer_SaveFlag) SK_OVERRIDE;
virtual void restore() SK_OVERRIDE;
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
virtual bool clipRRect(const SkRRect&, SkRegion::Op, bool) SK_OVERRIDE;
virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
virtual bool clipRegion(const SkRegion& deviceRgn,
SkRegion::Op op = SkRegion::kIntersect_Op) SK_OVERRIDE;
virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
const SkPaint& paint) SK_OVERRIDE;
@ -85,6 +67,25 @@ public:
virtual SkBounder* setBounder(SkBounder* bounder) SK_OVERRIDE;
virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE;
protected:
virtual void willSave(SaveFlags) SK_OVERRIDE;
virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual void willRestore() SK_OVERRIDE;
virtual void didTranslate(SkScalar, SkScalar) SK_OVERRIDE;
virtual void didScale(SkScalar, SkScalar) SK_OVERRIDE;
virtual void didRotate(SkScalar) SK_OVERRIDE;
virtual void didSkew(SkScalar, SkScalar) SK_OVERRIDE;
virtual void didConcat(const SkMatrix&) SK_OVERRIDE;
virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE;
private:
SkCanvas* fProxy;

Просмотреть файл

@ -8,10 +8,18 @@
#ifndef SkRunnable_DEFINED
#define SkRunnable_DEFINED
class SkRunnable {
public:
virtual ~SkRunnable() {};
template <typename T>
struct SkTRunnable {
virtual ~SkTRunnable() {};
virtual void run(T&) = 0;
};
template <>
struct SkTRunnable<void> {
virtual ~SkTRunnable() {};
virtual void run() = 0;
};
typedef SkTRunnable<void> SkRunnable;
#endif

Просмотреть файл

@ -12,24 +12,42 @@
#include "SkRunnable.h"
#include "SkTDArray.h"
#include "SkTInternalLList.h"
#include "SkThreadUtils.h"
#include "SkTypes.h"
class SkThread;
#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_ANDROID)
# include <unistd.h>
#endif
class SkThreadPool {
// Returns the number of cores on this machine.
static inline int num_cores() {
#if defined(SK_BUILD_FOR_WIN32)
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
return sysinfo.dwNumberOfProcessors;
#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_ANDROID)
return sysconf(_SC_NPROCESSORS_ONLN);
#else
return 1;
#endif
}
template <typename T>
class SkTThreadPool {
public:
/**
* Create a threadpool with count threads, or one thread per core if kThreadPerCore.
*/
static const int kThreadPerCore = -1;
explicit SkThreadPool(int count);
~SkThreadPool();
explicit SkTThreadPool(int count);
~SkTThreadPool();
/**
* Queues up an SkRunnable to run when a thread is available, or immediately if
* count is 0. NULL is a safe no-op. Does not take ownership.
* Queues up an SkRunnable to run when a thread is available, or synchronously if count is 0.
* Does not take ownership. NULL is a safe no-op. If T is not void, the runnable will be passed
* a reference to a T on the thread's local stack.
*/
void add(SkRunnable*);
void add(SkTRunnable<T>*);
/**
* Block until all added SkRunnables have completed. Once called, calling add() is undefined.
@ -38,10 +56,7 @@ public:
private:
struct LinkedRunnable {
// Unowned pointer.
SkRunnable* fRunnable;
private:
SkTRunnable<T>* fRunnable; // Unowned.
SK_DECLARE_INTERNAL_LLIST_INTERFACE(LinkedRunnable);
};
@ -60,4 +75,128 @@ public:
static void Loop(void*); // Static because we pass in this.
};
template <typename T>
SkTThreadPool<T>::SkTThreadPool(int count) : fState(kRunning_State), fBusyThreads(0) {
if (count < 0) {
count = num_cores();
}
// Create count threads, all running SkTThreadPool::Loop.
for (int i = 0; i < count; i++) {
SkThread* thread = SkNEW_ARGS(SkThread, (&SkTThreadPool::Loop, this));
*fThreads.append() = thread;
thread->start();
}
}
template <typename T>
SkTThreadPool<T>::~SkTThreadPool() {
if (kRunning_State == fState) {
this->wait();
}
}
namespace SkThreadPoolPrivate {
template <typename T>
struct ThreadLocal {
void run(SkTRunnable<T>* r) { r->run(data); }
T data;
};
template <>
struct ThreadLocal<void> {
void run(SkTRunnable<void>* r) { r->run(); }
};
} // namespace SkThreadPoolPrivate
template <typename T>
void SkTThreadPool<T>::add(SkTRunnable<T>* r) {
if (r == NULL) {
return;
}
if (fThreads.isEmpty()) {
SkThreadPoolPrivate::ThreadLocal<T> threadLocal;
threadLocal.run(r);
return;
}
LinkedRunnable* linkedRunnable = SkNEW(LinkedRunnable);
linkedRunnable->fRunnable = r;
fReady.lock();
SkASSERT(fState != kHalting_State); // Shouldn't be able to add work when we're halting.
fQueue.addToHead(linkedRunnable);
fReady.signal();
fReady.unlock();
}
template <typename T>
void SkTThreadPool<T>::wait() {
fReady.lock();
fState = kWaiting_State;
fReady.broadcast();
fReady.unlock();
// Wait for all threads to stop.
for (int i = 0; i < fThreads.count(); i++) {
fThreads[i]->join();
SkDELETE(fThreads[i]);
}
SkASSERT(fQueue.isEmpty());
}
template <typename T>
/*static*/ void SkTThreadPool<T>::Loop(void* arg) {
// The SkTThreadPool passes itself as arg to each thread as they're created.
SkTThreadPool<T>* pool = static_cast<SkTThreadPool<T>*>(arg);
SkThreadPoolPrivate::ThreadLocal<T> threadLocal;
while (true) {
// We have to be holding the lock to read the queue and to call wait.
pool->fReady.lock();
while(pool->fQueue.isEmpty()) {
// Does the client want to stop and are all the threads ready to stop?
// If so, we move into the halting state, and whack all the threads so they notice.
if (kWaiting_State == pool->fState && pool->fBusyThreads == 0) {
pool->fState = kHalting_State;
pool->fReady.broadcast();
}
// Any time we find ourselves in the halting state, it's quitting time.
if (kHalting_State == pool->fState) {
pool->fReady.unlock();
return;
}
// wait yields the lock while waiting, but will have it again when awoken.
pool->fReady.wait();
}
// We've got the lock back here, no matter if we ran wait or not.
// The queue is not empty, so we have something to run. Claim it.
LinkedRunnable* r = pool->fQueue.tail();
pool->fQueue.remove(r);
// Having claimed our SkRunnable, we now give up the lock while we run it.
// Otherwise, we'd only ever do work on one thread at a time, which rather
// defeats the point of this code.
pool->fBusyThreads++;
pool->fReady.unlock();
// OK, now really do the work.
threadLocal.run(r->fRunnable);
SkDELETE(r);
// Let everyone know we're not busy.
pool->fReady.lock();
pool->fBusyThreads--;
pool->fReady.unlock();
}
SkASSERT(false); // Unreachable. The only exit happens when pool->fState is kHalting_State.
}
typedef SkTThreadPool<void> SkThreadPool;
#endif

Просмотреть файл

@ -32,8 +32,8 @@ public:
const SkBitmap& getBitmap() const { return fBitmap; }
void setConfig(SkBitmap::Config);
void resize(int width, int height, SkBitmap::Config config = SkBitmap::kNo_Config);
void setColorType(SkColorType);
void resize(int width, int height, SkColorType = kUnknown_SkColorType);
bool isDirty() const { return !fDirtyRgn.isEmpty(); }
bool update(SkIRect* updateArea);
@ -81,7 +81,7 @@ protected:
virtual bool onSetFocusView(SkView* focus);
private:
SkBitmap::Config fConfig;
SkColorType fColorType;
SkBitmap fBitmap;
SkRegion fDirtyRgn;

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше