// This is a GPU-specific GM.
return kGPUOnly_Flag;
}
-
+
virtual void onOnceBeforeDraw() SK_OVERRIDE {
SkPath tri;
tri.moveTo(5.f, 5.f);
tri.lineTo(100.f, 20.f);
tri.lineTo(15.f, 100.f);
-
+
fPaths.addToTail(tri);
fPaths.addToTail(SkPath())->reverseAddPath(tri);
-
+
tri.close();
fPaths.addToTail(tri);
-
+
SkPath ngon;
static const SkScalar kRadius = 50.f;
const SkPoint center = { kRadius, kRadius };
ngon.lineTo(point);
}
}
-
+
fPaths.addToTail(ngon);
SkMatrix scaleM;
scaleM.setScale(1.1f, 0.4f);
}
GrDrawState* drawState = tt.target()->drawState();
drawState->setVertexAttribs<kAttribs>(SK_ARRAY_COUNT(kAttribs));
-
+
SkMatrix m;
SkPath p;
m.setTranslate(x, y);
path->transform(m, &p);
-
+
GrConvexPolyEffect::EdgeType edgeType = (GrConvexPolyEffect::EdgeType) et;
SkAutoTUnref<GrEffectRef> effect(GrConvexPolyEffect::Create(edgeType, p));
if (!effect) {
drawState->setIdentityViewMatrix();
drawState->setRenderTarget(rt);
drawState->setColor(0xff000000);
-
+
SkPoint verts[4];
SkRect bounds = p.getBounds();
// Make sure any artifacts around the exterior of path are visible by using overly
tt.target()->setVertexSourceToArray(verts, 4);
tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer());
tt.target()->drawIndexed(kTriangleFan_GrPrimitiveType, 0, 0, 4, 6);
-
+
x += path->getBounds().width() + 10.f;
}
-
+
// Draw AA and non AA paths using normal API for reference.
canvas->save();
canvas->translate(x, y);
paint.setAntiAlias(true);
canvas->drawPath(*path, paint);
canvas->restore();
-
+
y += path->getBounds().height() + 20.f;
}
}
// The class in this header defines the interface between Skia's internal
// tracing macros and an external entity (e.g., Chrome) that will consume them.
-// Such an entity should subclass SkEventTracer and provide an instance of
+// Such an entity should subclass SkEventTracer and provide an instance of
// that event to SkEventTracer::SetInstance.
// If you're looking for the tracing macros to instrument Skia itself, those
public:
typedef uint32_t Handle;
-
+
static SkEventTracer* GetInstance();
- static void SetInstance(SkEventTracer* tracer) {
+ static void SetInstance(SkEventTracer* tracer) {
SkDELETE(SkEventTracer::gInstance);
SkEventTracer::gInstance = tracer;
}
virtual const unsigned char* getCategoryGroupEnabled(const char* name) = 0;
virtual const char* getCategoryGroupName(
const uint8_t* category_group_enabled) = 0;
-
- virtual SkEventTracer::Handle
+
+ virtual SkEventTracer::Handle
addTraceEvent(char phase,
const uint8_t* categoryEnabledFlag,
const char* name,
const uint8_t* argTypes,
const uint64_t* argValues,
uint8_t flags) = 0;
-
- virtual void
- updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
- const char* name,
+
+ virtual void
+ updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
+ const char* name,
SkEventTracer::Handle) = 0;
private:
static SkEventTracer *gInstance;
return profile[ox];
}
-void SkBlurMask::ComputeBlurredScanline(uint8_t *pixels, const uint8_t *profile,
+void SkBlurMask::ComputeBlurredScanline(uint8_t *pixels, const uint8_t *profile,
unsigned int width, SkScalar sigma) {
unsigned int profile_size = SkScalarCeilToInt(6*sigma);
float giX = 1.5f - (x+.5f)/(2*sigma);
pixels[x] = (uint8_t) (255 * (gaussianIntegral(giX) - gaussianIntegral(giX + span)));
}
- }
+ }
}
bool SkBlurMask::BlurRect(SkMask *dst, const SkRect &src,
SkAutoTMalloc<uint8_t> horizontalScanline(dstWidth);
SkAutoTMalloc<uint8_t> verticalScanline(dstHeight);
-
+
ComputeBlurredScanline(horizontalScanline, profile, dstWidth, sigma);
ComputeBlurredScanline(verticalScanline, profile, dstHeight, sigma);
SkIPoint* margin = NULL);
static SkScalar ConvertRadiusToSigma(SkScalar radius);
-
+
/* Helper functions for analytic rectangle blurs */
-
+
/** Look up the intensity of the (one dimnensional) blurred half-plane.
@param profile The precomputed 1D blur profile; memory allocated by and managed by
ComputeBlurProfile below.
- @param loc the location to look up; The lookup will clamp invalid inputs, but
+ @param loc the location to look up; The lookup will clamp invalid inputs, but
meaningful data are available between 0 and blurred_width
@param blurred_width The width of the final, blurred rectangle
@param sharp_width The width of the original, unblurred rectangle.
- */
+ */
static uint8_t ProfileLookup(const uint8_t* profile, int loc, int blurred_width, int sharp_width);
-
+
/** Allocate memory for and populate the profile of a 1D blurred halfplane. The caller
must free the memory. The amount of memory allocated will be exactly 6*sigma bytes.
@param sigma The standard deviation of the gaussian blur kernel
@param profile_out The location to store the allocated profile curve
*/
-
+
static void ComputeBlurProfile(SkScalar sigma, uint8_t** profile_out);
-
+
/** Compute an entire scanline of a blurred step function. This is a 1D helper that
will produce both the horizontal and vertical profiles of the blurry rectangle.
@param pixels Location to store the resulting pixel data; allocated and managed by caller
@param sigma Standard deviation of the gaussian blur kernel used to compute the profile;
this implicitly gives the size of the pixels array.
*/
-
+
static void ComputeBlurredScanline(uint8_t* pixels, const uint8_t* profile,
unsigned int width, SkScalar sigma);
-
-
-
+
+
+
};
#endif
/**
* Create a simple filter effect with custom bicubic coefficients.
*/
- static GrEffectRef* Create(GrContext *context, const SkRect& rect,
+ static GrEffectRef* Create(GrContext *context, const SkRect& rect,
float sigma) {
GrTexture *horizontalScanline, *verticalScanline;
- bool createdScanlines = CreateScanlineTextures(context, sigma,
+ bool createdScanlines = CreateScanlineTextures(context, sigma,
SkScalarCeilToInt(rect.width()),
SkScalarCeilToInt(rect.height()),
&horizontalScanline, &verticalScanline);
if (!createdScanlines) {
return NULL;
}
- AutoEffectUnref effect(SkNEW_ARGS(GrRectBlurEffect, (rect, sigma,
+ AutoEffectUnref effect(SkNEW_ARGS(GrRectBlurEffect, (rect, sigma,
horizontalScanline, verticalScanline)));
- return CreateEffectRef(effect);
+ return CreateEffectRef(effect);
}
-
+
unsigned int getWidth() const { return fWidth; }
unsigned int getHeight() const { return fHeight; }
float getSigma() const { return fSigma; }
const GrCoordTransform& getTransform() const { return fTransform; }
private:
- GrRectBlurEffect(const SkRect& rect, float sigma,
+ GrRectBlurEffect(const SkRect& rect, float sigma,
GrTexture *horizontal_scanline, GrTexture *vertical_scanline);
virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
-
+
static bool CreateScanlineTextures(GrContext *context, float sigma,
unsigned int width, unsigned int height,
GrTexture **horizontalScanline,
GrTexture **verticalScanline);
-
+
unsigned int fWidth, fHeight;
float fSigma;
GrTextureAccess fHorizontalScanlineAccess;
const char* inputColor,
const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
-
+
SkString texture_coords = builder->ensureFSCoords2D(coords, 0);
-
+
if (inputColor) {
builder->fsCodeAppendf("\tvec4 src=%s;\n", inputColor);
} else {
builder->fsCodeAppendf("\tvec4 src=vec4(1)\n;");
}
-
+
builder->fsCodeAppendf("\tvec4 horiz = ");
builder->fsAppendTextureLookup( samplers[0], texture_coords.c_str() );
builder->fsCodeAppendf(";\n");
builder->fsCodeAppendf("\tvec4 vert = ");
builder->fsAppendTextureLookup( samplers[1], texture_coords.c_str() );
builder->fsCodeAppendf(";\n");
-
+
builder->fsCodeAppendf("\tfloat final = (horiz*vert).r;\n");
builder->fsCodeAppendf("\t%s = final*src;\n", outputColor);
}
GrTexture **verticalScanline) {
GrTextureParams params;
GrTextureDesc texDesc;
-
+
unsigned int profile_size = SkScalarFloorToInt(6*sigma);
-
+
texDesc.fWidth = width;
texDesc.fHeight = 1;
texDesc.fConfig = kAlpha_8_GrPixelConfig;
-
+
static const GrCacheID::Domain gBlurProfileDomain = GrCacheID::GenerateDomain();
GrCacheID::Key key;
memset(&key, 0, sizeof(key));
key.fData32[1] = width;
key.fData32[2] = 1;
GrCacheID horizontalCacheID(gBlurProfileDomain, key);
-
+
uint8_t *profile = NULL;
SkAutoTDeleteArray<uint8_t> ada(NULL);
-
+
*horizontalScanline = context->findAndRefTexture(texDesc, horizontalCacheID, ¶ms);
-
+
if (NULL == *horizontalScanline) {
-
+
SkBlurMask::ComputeBlurProfile(sigma, &profile);
ada.reset(profile);
-
+
SkAutoTMalloc<uint8_t> horizontalPixels(width);
SkBlurMask::ComputeBlurredScanline(horizontalPixels, profile, width, sigma);
-
- *horizontalScanline = context->createTexture(¶ms, texDesc, horizontalCacheID,
+
+ *horizontalScanline = context->createTexture(¶ms, texDesc, horizontalCacheID,
horizontalPixels, 0);
-
+
if (NULL == *horizontalScanline) {
return false;
}
}
-
+
texDesc.fWidth = 1;
texDesc.fHeight = height;
key.fData32[1] = 1;
key.fData32[2] = height;
GrCacheID verticalCacheID(gBlurProfileDomain, key);
-
+
*verticalScanline = context->findAndRefTexture(texDesc, verticalCacheID, ¶ms);
if (NULL == *verticalScanline) {
if (NULL == profile) {
SkBlurMask::ComputeBlurProfile(sigma, &profile);
ada.reset(profile);
}
-
+
SkAutoTMalloc<uint8_t> verticalPixels(height);
SkBlurMask::ComputeBlurredScanline(verticalPixels, profile, height, sigma);
-
- *verticalScanline = context->createTexture(¶ms, texDesc, verticalCacheID,
+
+ *verticalScanline = context->createTexture(¶ms, texDesc, verticalCacheID,
verticalPixels, 0);
-
+
if (NULL == *verticalScanline) {
return false;
}
-
+
}
return true;
}
GrRectBlurEffect::GrRectBlurEffect(const SkRect& rect, float sigma,
GrTexture *horizontal_scanline, GrTexture *vertical_scanline)
- : INHERITED(),
+ : INHERITED(),
fWidth(horizontal_scanline->width()),
fHeight(vertical_scanline->width()),
fSigma(sigma),
SkMatrix mat;
mat.setRectToRect(rect, SkRect::MakeWH(1,1), SkMatrix::kFill_ScaleToFit);
fTransform.reset(kLocal_GrCoordSet, mat);
- this->addTextureAccess(&fHorizontalScanlineAccess);
- this->addTextureAccess(&fVerticalScanlineAccess);
+ this->addTextureAccess(&fHorizontalScanlineAccess);
+ this->addTextureAccess(&fVerticalScanlineAccess);
this->addCoordTransform(&fTransform);
}
if (fBlurStyle != SkBlurMaskFilter::kNormal_BlurStyle) {
return false;
}
-
+
SkRect rect;
if (!path.isRect(&rect)) {
return false;
}
-
+
if (!strokeRec.isFillStyle()) {
return false;
}
-
+
SkMatrix ctm = context->getMatrix();
SkScalar xformedSigma = this->computeXformedSigma(ctm);
rect.outset(3*xformedSigma, 3*xformedSigma);
-
+
SkAutoTUnref<GrEffectRef> effect(GrRectBlurEffect::Create(
context, rect, xformedSigma));
if (!effect) {
grp->addCoverageEffect(effect);
-
+
context->drawRect(*grp, rect);
return true;
}
GrTextContext::finish();
}
-void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
+void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
const char text[], size_t byteLength,
SkScalar x, SkScalar y) {
SkASSERT(byteLength == 0 || text != NULL);
///////////////////////////////////////////////////////////////////////////////
-void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint,
+void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint,
const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY,
int scalarsPerPosition) {
GrBitmapTextContext(GrContext*, const SkDeviceProperties&);
virtual ~GrBitmapTextContext();
- virtual void drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
+ virtual void drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
SkScalar x, SkScalar y) SK_OVERRIDE;
- virtual void drawPosText(const GrPaint&, const SkPaint&,
+ virtual void drawPosText(const GrPaint&, const SkPaint&,
const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY,
int scalarsPerPosition) SK_OVERRIDE;
virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
-
+
private:
GrTextStrike* fStrike;
fMaxVertices = 0;
fTextRatio = fSkPaint.getTextSize()/kBaseDFFontSize;
-
+
fSkPaint.setTextSize(SkIntToScalar(kBaseDFFontSize));
fSkPaint.setLCDRenderText(false);
fSkPaint.setAutohinted(false);
GrDistanceFieldTextContext(GrContext*, const SkDeviceProperties&);
virtual ~GrDistanceFieldTextContext();
- virtual void drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
+ virtual void drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
SkScalar x, SkScalar y) SK_OVERRIDE;
- virtual void drawPosText(const GrPaint&, const SkPaint&,
+ virtual void drawPosText(const GrPaint&, const SkPaint&,
const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY,
int scalarsPerPosition) SK_OVERRIDE;
-
+
virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
private:
class GrTextContext {
public:
virtual ~GrTextContext() {}
- virtual void drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
+ virtual void drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
SkScalar x, SkScalar y) = 0;
virtual void drawPosText(const GrPaint&, const SkPaint&,
const char text[], size_t byteLength,
int scalarsPerPosition) = 0;
virtual bool canDraw(const SkPaint& paint) = 0;
-
+
protected:
GrTextContext(GrContext*, const SkDeviceProperties&);
// transform the path into device space
pathPtr->transform(fContext->getMatrix(), devPathPtr);
-
+
SkRect maskRect;
if (paint.getMaskFilter()->canFilterMaskGPU(devPathPtr->getBounds(),
draw.fClip->getBounds(),
// nothing to draw
return;
}
-
+
if (paint.getMaskFilter()->directFilterMaskGPU(fContext, &grPaint,
SkStrokeRec(paint), *devPathPtr)) {
// the mask filter was able to draw itself directly, so there's nothing
SkDEBUGCODE(this->validate();)
- fMainTextContext->drawPosText(grPaint, paint, (const char *)text, byteLength, pos,
+ fMainTextContext->drawPosText(grPaint, paint, (const char *)text, byteLength, pos,
constY, scalarsPerPos);
} else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) {
GrPaint grPaint;
if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
return;
}
-
+
SkDEBUGCODE(this->validate();)
-
- fFallbackTextContext->drawPosText(grPaint, paint, (const char *)text, byteLength, pos,
+
+ fFallbackTextContext->drawPosText(grPaint, paint, (const char *)text, byteLength, pos,
constY, scalarsPerPos);
} else {
draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY,
return GrConvexPolyEffect::Create(edgeType, count, edges);
}
-
enum EdgeType {
kFillNoAA_EdgeType,
kFillAA_EdgeType,
-
+
kLastEdgeType = kFillAA_EdgeType,
};
#include "SkOnce.h"
class SkDefaultEventTracer: public SkEventTracer {
- virtual SkEventTracer::Handle
+ virtual SkEventTracer::Handle
addTraceEvent(char phase,
const uint8_t* categoryEnabledFlag,
const char* name,
const uint8_t* argTypes,
const uint64_t* argValues,
uint8_t flags) SK_OVERRIDE { return 0; }
-
- virtual void
- updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
- const char* name,
+
+ virtual void
+ updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
+ const char* name,
SkEventTracer::Handle) SK_OVERRIDE {};
virtual const uint8_t* getCategoryGroupEnabled(const char* name) SK_OVERRIDE {