Exemplo n.º 1
0
    virtual void onDraw(SkCanvas* canvas) {

        SkPoint pts[2] = {
            { 0, 0 },
            { SkIntToScalar(100), SkIntToScalar(100) }
        };
        SkShader::TileMode tm = SkShader::kClamp_TileMode;
        SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) };
        SkPaint paint;
        paint.setAntiAlias(true);

        canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
        for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
            canvas->save();
            for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
                SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, NULL);

                // apply an increasing y perspective as we move to the right
                SkMatrix perspective;
                perspective.setIdentity();
                perspective.setPerspY(SkScalarDiv(SkIntToScalar((unsigned) i+1),
                                      SkIntToScalar(500)));
                perspective.setSkewX(SkScalarDiv(SkIntToScalar((unsigned) i+1),
                                     SkIntToScalar(10)));
                shader->setLocalMatrix(perspective);

                paint.setShader(shader);
                canvas->drawRect(r, paint);
                shader->unref();
                canvas->translate(0, SkIntToScalar(120));
            }
            canvas->restore();
            canvas->translate(SkIntToScalar(120), 0);
        }
    }
Exemplo n.º 2
0
static IntersectionType intersection(const SkPoint& p1, const SkPoint& p2,
                                     const SkPoint& p3, const SkPoint& p4,
                                     SkPoint& res) {
    // Store the values for fast access and easy
    // equations-to-code conversion
    SkScalar x1 = p1.x(), x2 = p2.x(), x3 = p3.x(), x4 = p4.x();
    SkScalar y1 = p1.y(), y2 = p2.y(), y3 = p3.y(), y4 = p4.y();

    SkScalar d = SkScalarMul(x1 - x2, y3 - y4) - SkScalarMul(y1 - y2, x3 - x4);
    // If d is zero, there is no intersection
    if (SkScalarNearlyZero(d)) {
        return kNone_IntersectionType;
    }

    // Get the x and y
    SkScalar pre  = SkScalarMul(x1, y2) - SkScalarMul(y1, x2),
             post = SkScalarMul(x3, y4) - SkScalarMul(y3, x4);
    // Compute the point of intersection
    res.set(SkScalarDiv(SkScalarMul(pre, x3 - x4) - SkScalarMul(x1 - x2, post), d),
            SkScalarDiv(SkScalarMul(pre, y3 - y4) - SkScalarMul(y1 - y2, post), d));

    // Check if the x and y coordinates are within both lines
    return (res.x() < GrMin(x1, x2) || res.x() > GrMax(x1, x2) ||
            res.x() < GrMin(x3, x4) || res.x() > GrMax(x3, x4) ||
            res.y() < GrMin(y1, y2) || res.y() > GrMax(y1, y2) ||
            res.y() < GrMin(y3, y4) || res.y() > GrMax(y3, y4)) ?
            kOut_IntersectionType : kIn_IntersectionType;
}
Exemplo n.º 3
0
 void draw(SkCanvas* canvas,
           const SkRect& rect,
           const SkSize& deviceSize,
           SkPaint::FilterLevel filterLevel,
           SkImageFilter* input = NULL) {
     SkRect dstRect;
     canvas->getTotalMatrix().mapRect(&dstRect, rect);
     canvas->save();
     SkScalar deviceScaleX = SkScalarDiv(deviceSize.width(), dstRect.width());
     SkScalar deviceScaleY = SkScalarDiv(deviceSize.height(), dstRect.height());
     canvas->translate(rect.x(), rect.y());
     canvas->scale(deviceScaleX, deviceScaleY);
     canvas->translate(-rect.x(), -rect.y());
     SkMatrix matrix;
     matrix.setScale(SkScalarInvert(deviceScaleX),
                     SkScalarInvert(deviceScaleY));
     SkAutoTUnref<SkImageFilter> imageFilter(
         SkMatrixImageFilter::Create(matrix, filterLevel, input));
     SkPaint filteredPaint;
     filteredPaint.setImageFilter(imageFilter.get());
     canvas->saveLayer(&rect, &filteredPaint);
     SkPaint paint;
     paint.setColor(0xFF00FF00);
     SkRect ovalRect = rect;
     ovalRect.inset(SkIntToScalar(4), SkIntToScalar(4));
     canvas->drawOval(ovalRect, paint);
     canvas->restore(); // for saveLayer
     canvas->restore();
 }
Exemplo n.º 4
0
static SkScalar RGB_to_HSV(SkColor color, HSV_Choice choice) {
    SkScalar red = SkIntToScalar(SkColorGetR(color));
    SkScalar green = SkIntToScalar(SkColorGetG(color));
    SkScalar blue = SkIntToScalar(SkColorGetB(color));
    SkScalar min = SkMinScalar(SkMinScalar(red, green), blue);
    SkScalar value = SkMaxScalar(SkMaxScalar(red, green), blue);
    if (choice == kGetValue)
        return value/255;
    SkScalar delta = value - min;
    SkScalar saturation = value == 0 ? 0 : SkScalarDiv(delta, value);
    if (choice == kGetSaturation)
        return saturation;
    SkScalar hue;
    if (saturation == 0)
        hue = 0;
    else {
        SkScalar part60 = SkScalarDiv(60 * SK_Scalar1, delta);
        if (red == value) {
            hue = SkScalarMul(green - blue, part60);
            if (hue < 0)
                hue += 360 * SK_Scalar1;
        }
        else if (green == value)
            hue = 120 * SK_Scalar1 + SkScalarMul(blue - red, part60);
        else  // blue == value
            hue = 240 * SK_Scalar1 + SkScalarMul(red - green, part60);
    }
    SkASSERT(choice == kGetHue);
    return hue;
}
Exemplo n.º 5
0
void SkGridView::onSizeChange()
{
	fScrollBar->setHeight(this->height());
	fScrollBar->setLoc(this->locX() + this->width() - fScrollBar->width(), 0);

	if (fCellSize.equals(0, 0))
	{
		fVisibleCount.set(0, 0);
		return;
	}

	SkScalar rows = SkScalarDiv(this->height(), fCellSize.fY);
	SkScalar cols = SkScalarDiv(this->width(), fCellSize.fX);
	int		 y = SkScalarFloor(rows);
	int		 x = SkScalarFloor(cols);

	y = check_count(y, rows);
	x = check_count(x, cols);

	if (!fVisibleCount.equals(x, y))
	{
		fVisibleCount.set(x, y);
		this->ensureSelectionIsVisible();
	//	this->dirtyStrCache();
	}
}
bool SkXRayCrossesLine(const SkXRay& pt, const SkPoint pts[2]) {
    // Determine quick discards.
    // Consider query line going exactly through point 0 to not
    // intersect, for symmetry with SkXRayCrossesMonotonicCubic.
    if (pt.fY == pts[0].fY)
        return false;
    if (pt.fY < pts[0].fY && pt.fY < pts[1].fY)
        return false;
    if (pt.fY > pts[0].fY && pt.fY > pts[1].fY)
        return false;
    if (pt.fX > pts[0].fX && pt.fX > pts[1].fX)
        return false;
    // Determine degenerate cases
    if (SkScalarNearlyZero(pts[0].fY - pts[1].fY))
        return false;
    if (SkScalarNearlyZero(pts[0].fX - pts[1].fX))
        // We've already determined the query point lies within the
        // vertical range of the line segment.
        return pt.fX <= pts[0].fX;
    // Full line segment evaluation
    SkScalar delta_y = pts[1].fY - pts[0].fY;
    SkScalar delta_x = pts[1].fX - pts[0].fX;
    SkScalar slope = SkScalarDiv(delta_y, delta_x);
    SkScalar b = pts[0].fY - SkScalarMul(slope, pts[0].fX);
    // Solve for x coordinate at y = pt.fY
    SkScalar x = SkScalarDiv(pt.fY - b, slope);
    return pt.fX <= x;
}
Exemplo n.º 7
0
void SkRRect::setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad) {
    if (rect.isEmpty() || !rect.isFinite()) {
        this->setEmpty();
        return;
    }

    if (!SkScalarsAreFinite(xRad, yRad)) {
        xRad = yRad = 0;    // devolve into a simple rect
    }
    if (xRad <= 0 || yRad <= 0) {
        // all corners are square in this case
        this->setRect(rect);
        return;
    }

    if (rect.width() < xRad+xRad || rect.height() < yRad+yRad) {
        SkScalar scale = SkMinScalar(SkScalarDiv(rect.width(), xRad + xRad),
                                     SkScalarDiv(rect.height(), yRad + yRad));
        SkASSERT(scale < SK_Scalar1);
        xRad = SkScalarMul(xRad, scale);
        yRad = SkScalarMul(yRad, scale);
    }

    fRect = rect;
    for (int i = 0; i < 4; ++i) {
        fRadii[i].set(xRad, yRad);
    }
    fType = kSimple_Type;
    if (xRad >= SkScalarHalf(fRect.width()) && yRad >= SkScalarHalf(fRect.height())) {
        fType = kOval_Type;
        // TODO: assert that all the x&y radii are already W/2 & H/2
    }

    SkDEBUGCODE(this->validate();)
}
Exemplo n.º 8
0
void SkRRect::setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad,
                           SkScalar rightRad, SkScalar bottomRad) {
    if (rect.isEmpty() || !rect.isFinite()) {
        this->setEmpty();
        return;
    }

    const SkScalar array[4] = { leftRad, topRad, rightRad, bottomRad };
    if (!SkScalarsAreFinite(array, 4)) {
        this->setRect(rect);    // devolve into a simple rect
        return;
    }

    leftRad = SkMaxScalar(leftRad, 0);
    topRad = SkMaxScalar(topRad, 0);
    rightRad = SkMaxScalar(rightRad, 0);
    bottomRad = SkMaxScalar(bottomRad, 0);

    SkScalar scale = SK_Scalar1;
    if (leftRad + rightRad > rect.width()) {
        scale = SkScalarDiv(rect.width(), leftRad + rightRad);
    }
    if (topRad + bottomRad > rect.height()) {
        scale = SkMinScalar(scale, SkScalarDiv(rect.height(), topRad + bottomRad));
    }

    if (scale < SK_Scalar1) {
        leftRad = SkScalarMul(leftRad, scale);
        topRad = SkScalarMul(topRad, scale);
        rightRad = SkScalarMul(rightRad, scale);
        bottomRad = SkScalarMul(bottomRad, scale);
    }

    if (leftRad == rightRad && topRad == bottomRad) {
        if (leftRad >= SkScalarHalf(rect.width()) && topRad >= SkScalarHalf(rect.height())) {
            fType = kOval_Type;
        } else if (0 == leftRad || 0 == topRad) {
            // If the left and (by equality check above) right radii are zero then it is a rect.
            // Same goes for top/bottom.
            fType = kRect_Type;
            leftRad = 0;
            topRad = 0;
            rightRad = 0;
            bottomRad = 0;
        } else {
            fType = kSimple_Type;
        }
    } else {
        fType = kNinePatch_Type;
    }

    fRect = rect;
    fRadii[kUpperLeft_Corner].set(leftRad, topRad);
    fRadii[kUpperRight_Corner].set(rightRad, topRad);
    fRadii[kLowerRight_Corner].set(rightRad, bottomRad);
    fRadii[kLowerLeft_Corner].set(leftRad, bottomRad);

    SkDEBUGCODE(this->validate();)
}
Exemplo n.º 9
0
 virtual void onDraw(SkCanvas* canvas) {
     SkMatrix perspective;
     perspective.setIdentity();
     perspective.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000)));
     perspective.setSkewX(SkScalarDiv(SkIntToScalar(8), SkIntToScalar(25)));
     canvas->concat(perspective);
     INHERITED::onDraw(canvas);
 }
Exemplo n.º 10
0
 virtual Click* onFindClickHandler(SkScalar x, SkScalar y) {
     int ix = (int)(SkScalarDiv(x * N, W));
     int iy = (int)(SkScalarDiv(y * N, H));
     if (ix >= 0 && iy >= 0) {
         SkEvent evt("set-curr-index");
         evt.setFast32(iy * N + ix);
         this->sendEventToParents(evt);
     }
     return NULL;
 }
Exemplo n.º 11
0
void GrGLDisplacementMapEffect::setData(const GrGLProgramDataManager& pdman,
                                        const GrProcessor& proc) {
    const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMapEffect>();
    GrTexture* colorTex = displacementMap.texture(1);
    SkScalar scaleX = SkScalarDiv(displacementMap.scale().fX, SkIntToScalar(colorTex->width()));
    SkScalar scaleY = SkScalarDiv(displacementMap.scale().fY, SkIntToScalar(colorTex->height()));
    pdman.set2f(fScaleUni, SkScalarToFloat(scaleX),
                colorTex->origin() == kTopLeft_GrSurfaceOrigin ?
                SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY));
    fGLDomain.setData(pdman, displacementMap.domain(), colorTex->origin());
}
Exemplo n.º 12
0
static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& data,
                             SkShader::TileMode tm, const SkMatrix& localMatrix) {
    SkPoint center0, center1;
    SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
    SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
    center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
    center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
    return SkGradientShader::CreateTwoPointConical(center1, radius1,
                                                   center0, radius0,
                                                   data.fColors, data.fPos,
                                                   data.fCount, tm, 0, &localMatrix);
}
Exemplo n.º 13
0
static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
                             SkShader::TileMode tm, const SkMatrix& localMatrix) {
    SkPoint center0, center1;
    SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
    SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
    center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
                SkScalarAve(pts[0].fY, pts[1].fY));
    center0.set(center1.fX, center1.fY + radius1 - radius0);
    return SkGradientShader::CreateTwoPointConical(center0, radius0,
                                                   center1, radius1,
                                                   data.fColors, data.fPos,
                                                   data.fCount, tm, 0, &localMatrix);
}
Exemplo n.º 14
0
void SkSet::dump(SkAnimateMaker* maker) {
    INHERITED::dump(maker);
    if (dur != 1) {
#ifdef SK_CAN_USE_FLOAT
        SkDebugf("dur=\"%g\" ", SkScalarToFloat(SkScalarDiv(dur,1000)));
#else
        SkDebugf("dur=\"%x\" ", SkScalarDiv(dur,1000));
#endif
    }
    //don't want double />\n's
    SkDebugf("/>\n");

}
Exemplo n.º 15
0
    virtual void onDraw(SkCanvas* canvas) {
        canvas->clear(0x00000000);

        SkRect srcRect = SkRect::MakeWH(96, 96);

        SkSize deviceSize = SkSize::Make(16, 16);
        draw(canvas,
             srcRect,
             deviceSize,
             SkPaint::kNone_FilterLevel);

        canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
        draw(canvas,
             srcRect,
             deviceSize,
             SkPaint::kLow_FilterLevel);

        canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
        draw(canvas,
             srcRect,
             deviceSize,
             SkPaint::kMedium_FilterLevel);

        canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
        draw(canvas,
             srcRect,
             deviceSize,
             SkPaint::kHigh_FilterLevel);

        SkBitmap bitmap;
        bitmap.allocN32Pixels(16, 16);
        bitmap.eraseARGB(0x00, 0x00, 0x00, 0x00);
        {
            SkBitmapDevice bitmapDevice(bitmap);
            SkCanvas bitmapCanvas(&bitmapDevice);
            SkPaint paint;
            paint.setColor(0xFF00FF00);
            SkRect ovalRect = SkRect::MakeWH(16, 16);
            ovalRect.inset(SkScalarDiv(2.0f, 3.0f), SkScalarDiv(2.0f, 3.0f));
            bitmapCanvas.drawOval(ovalRect, paint);
        }
        SkRect inRect = SkRect::MakeXYWH(-4, -4, 20, 20);
        SkRect outRect = SkRect::MakeXYWH(-24, -24, 120, 120);
        SkAutoTUnref<SkBitmapSource> source(SkBitmapSource::Create(bitmap, inRect, outRect));
        canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
        draw(canvas,
             srcRect,
             deviceSize,
             SkPaint::kHigh_FilterLevel,
             source.get());
    }
Exemplo n.º 16
0
    virtual bool onClick(Click* click)  {
        SkScalar center = this->width()/2;
        fSaturation = SkScalarDiv(click->fCurr.fX - center, center/2);
        center = this->height()/2;
        fAngle = SkScalarDiv(click->fCurr.fY - center, center) * 180;

        fDX += click->fCurr.fX - click->fPrev.fX;
        fDY += click->fCurr.fY - click->fPrev.fY;

        fScale = SkScalarDiv(click->fCurr.fX, this->width());

        this->inval(NULL);
        return true;
        return this->INHERITED::onClick(click);
    }
Exemplo n.º 17
0
static ECode native_draw(
    /* [in] */ SkCanvas* canvas,
    /* [in] */ SkRect& bounds,
    /* [in] */ const SkBitmap* bitmap,
    /* [in] */ ArrayOf<Byte>* chunkObj,
    /* [in] */ const SkPaint* paint,
    /* [in] */ Int32 destDensity,
    /* [in] */ Int32 srcDensity)
{
    ECode ec = NOERROR;
    Int32 chunkSize = chunkObj->GetLength();
    void* storage = chunkObj->GetPayload();
    // need to deserialize the chunk
    android::Res_png_9patch* chunk = static_cast<android::Res_png_9patch*>(storage);
    assert(chunkSize == (Int32)chunk->serializedSize());
    // this relies on deserialization being done in place
    android::Res_png_9patch::deserialize(chunk);

    if (destDensity == srcDensity || destDensity == 0
            || srcDensity == 0) {
        // Logger::V(TAG, "Drawing unscaled 9-patch: (%g,%g)-(%g,%g)",
        //         SkScalarToFloat(bounds.fLeft), SkScalarToFloat(bounds.fTop),
        //         SkScalarToFloat(bounds.fRight), SkScalarToFloat(bounds.fBottom));
        ec = NinePatch_Draw(canvas, bounds, *bitmap, *chunk, paint, NULL);
    }
    else {
        canvas->save();

        SkScalar scale = SkFloatToScalar(destDensity / (float)srcDensity);
        canvas->translate(bounds.fLeft, bounds.fTop);
        canvas->scale(scale, scale);

        bounds.fRight = SkScalarDiv(bounds.fRight-bounds.fLeft, scale);
        bounds.fBottom = SkScalarDiv(bounds.fBottom-bounds.fTop, scale);
        bounds.fLeft = bounds.fTop = 0;

        Logger::V(TAG, "Drawing scaled 9-patch: (%g,%g)-(%g,%g) srcDensity=%d destDensity=%d",
                SkScalarToFloat(bounds.fLeft), SkScalarToFloat(bounds.fTop),
                SkScalarToFloat(bounds.fRight), SkScalarToFloat(bounds.fBottom),
                srcDensity, destDensity);

        ec = NinePatch_Draw(canvas, bounds, *bitmap, *chunk, paint, NULL);

        canvas->restore();
    }

    return ec;
}
Exemplo n.º 18
0
void SkAnimate::dump(SkAnimateMaker* maker) {
    INHERITED::dump(maker); //from animateBase
    //SkSet inherits from this class
    if (getType() != SkType_Set) {
        if (fMirror)
            SkDebugf("mirror=\"true\" ");
        if (fReset)
            SkDebugf("reset=\"true\" ");
        SkDebugf("dur=\"%g\" ", SkScalarToFloat(SkScalarDiv(dur,1000)));
        if (repeat != SK_Scalar1)
            SkDebugf("repeat=\"%g\" ", SkScalarToFloat(repeat));
        //if (fHasValues)
        //    SkDebugf("values=\"%s\" ", values);
        if (blend.count() != 1 || blend[0] != SK_Scalar1) {
            SkDebugf("blend=\"[");
            bool firstElem = true;
            for (int i = 0; i < blend.count(); i++) {
                if (!firstElem)
                    SkDebugf(",");
                firstElem = false;
                SkDebugf("%g", SkScalarToFloat(blend[i]));
            }
            SkDebugf("]\" ");
        }
        SkDebugf("/>\n");//i assume that if it IS, we will do it separately
    }
}
Exemplo n.º 19
0
    virtual void onDraw(SkCanvas* canvas) {
        SkScalar angle = kAngle*SK_ScalarPI + SkScalarHalf(SK_ScalarPI);
        SkScalar size = SkIntToScalar(SkMin32(kWidth, kHeight));
        SkPoint center = SkPoint::Make(SkScalarHalf(kWidth), SkScalarHalf(kHeight));
        SkScalar length = 5;
        SkScalar step = angle;

        SkPath path;
        path.moveTo(center);

        while (length < (SkScalarHalf(size) - 10.f))
        {
            SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX,
                                       length*SkScalarSin(step) + center.fY);
            path.lineTo(rp);
            length += SkScalarDiv(angle, SkScalarHalf(SK_ScalarPI));
            step += angle;
        }
        path.close();

        SkPaint paint;
        paint.setAntiAlias(true);
        paint.setStyle(SkPaint::kStroke_Style);
        paint.setColor(0xFF007700);

        canvas->drawPath(path, paint);
    }
void SkPathStroker::quad_to(const SkPoint pts[3],
                      const SkVector& normalAB, const SkVector& unitNormalAB,
                      SkVector* normalBC, SkVector* unitNormalBC,
                      int subDivide) {
    if (!set_normal_unitnormal(pts[1], pts[2], fRadius,
                               normalBC, unitNormalBC)) {
        // pts[1] nearly equals pts[2], so just draw a line to pts[2]
        this->line_to(pts[2], normalAB);
        *normalBC = normalAB;
        *unitNormalBC = unitNormalAB;
        return;
    }

    if (--subDivide >= 0 && normals_too_curvy(unitNormalAB, *unitNormalBC)) {
        SkPoint     tmp[5];
        SkVector    norm, unit;

        SkChopQuadAtHalf(pts, tmp);
        this->quad_to(&tmp[0], normalAB, unitNormalAB, &norm, &unit, subDivide);
        this->quad_to(&tmp[2], norm, unit, normalBC, unitNormalBC, subDivide);
    } else {
        SkVector    normalB;

        normalB = pts[2] - pts[0];
        normalB.rotateCCW();
        SkScalar dot = SkPoint::DotProduct(unitNormalAB, *unitNormalBC);
        SkAssertResult(normalB.setLength(SkScalarDiv(fRadius,
                                     SkScalarSqrt((SK_Scalar1 + dot)/2))));

        fOuter.quadTo(  pts[1].fX + normalB.fX, pts[1].fY + normalB.fY,
                        pts[2].fX + normalBC->fX, pts[2].fY + normalBC->fY);
        fInner.quadTo(  pts[1].fX - normalB.fX, pts[1].fY - normalB.fY,
                        pts[2].fX - normalBC->fX, pts[2].fY - normalBC->fY);
    }
}
Exemplo n.º 21
0
    void onDrawContent(SkCanvas* canvas) override {
        SkScalar angle = fAngle*SK_ScalarPI + SkScalarHalf(SK_ScalarPI);

        SkPoint center = SkPoint::Make(SkScalarHalf(this->width()), SkScalarHalf(this->height()));
        SkScalar length = 5;
        SkScalar step = angle;

        SkPath path;
        path.moveTo(center);

        while (length < (SkScalarHalf(SkMinScalar(this->width(), this->height())) - 10.f))
        {
            SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX,
                                       length*SkScalarSin(step) + center.fY);
            path.lineTo(rp);
            length += SkScalarDiv(angle, SkScalarHalf(SK_ScalarPI));
            step += angle;
        }
        path.close();

        SkPaint paint;
        paint.setAntiAlias(true);
        paint.setStyle(SkPaint::kStroke_Style);
        paint.setColor(0xFF007700);

        canvas->drawPath(path, paint);
    }
Exemplo n.º 22
0
void SkListView::ensureVisibleRowCount()
{
	SkScalar	height = this->height();
	int			n = 0;
	
	if (height > 0)
	{
		n = 1;
		height -= fHeights[kSelected_Height];
		if (height > 0)
		{
			SkScalar count = SkScalarDiv(height, fHeights[kNormal_Height]);
			n += SkScalarFloor(count);
			if (count - SkIntToScalar(n) > SK_Scalar1*3/4)
				n += 1;
				
		//	SkDebugf("count %g, n %d\n", count/65536., n);
		}
	}

	if (fVisibleRowCount != n)
	{
		if (fScrollBar)
			fScrollBar->setShown(n);

		fVisibleRowCount = n;
		this->ensureSelectionIsVisible();
		this->dirtyCache(kAnimCount_DirtyFlag | kAnimContent_DirtyFlag);
	}
}
Exemplo n.º 23
0
uint32_t GrPathUtils::quadraticPointCount(const GrPoint points[],
                                          GrScalar tol) {
    if (tol < gMinCurveTol) {
        tol == gMinCurveTol;
    }
    GrAssert(tol > 0);

    GrScalar d = points[1].distanceToLineSegmentBetween(points[0], points[2]);
    if (d <= tol) {
        return 1;
    } else {
        // Each time we subdivide, d should be cut in 4. So we need to
        // subdivide x = log4(d/tol) times. x subdivisions creates 2^(x)
        // points.
        // 2^(log4(x)) = sqrt(x);
        int temp = SkScalarCeil(SkScalarSqrt(SkScalarDiv(d, tol)));
        int pow2 = GrNextPow2(temp);
        // Because of NaNs & INFs we can wind up with a degenerate temp
        // such that pow2 comes out negative. Also, our point generator
        // will always output at least one pt.
        if (pow2 < 1) {
            pow2 = 1;
        }
        return GrMin(pow2, MAX_POINTS_PER_CURVE);
    }
}
Exemplo n.º 24
0
void SkPDFGraphicState::emitObject(SkWStream* stream,
                                   const SkPDFObjNumMap& objNumMap,
                                   const SkPDFSubstituteMap& substitutes) {
    SkAutoTUnref<SkPDFDict> dict(SkNEW_ARGS(SkPDFDict, ("ExtGState")));
    dict->insertName("Type", "ExtGState");

    SkScalar alpha = SkScalarDiv(fAlpha, 0xFF);
    dict->insertScalar("CA", alpha);
    dict->insertScalar("ca", alpha);

    SkPaint::Cap strokeCap = (SkPaint::Cap)fStrokeCap;
    SkPaint::Join strokeJoin = (SkPaint::Join)fStrokeJoin;
    SkXfermode::Mode xferMode = (SkXfermode::Mode)fMode;

    SK_COMPILE_ASSERT(SkPaint::kButt_Cap == 0, paint_cap_mismatch);
    SK_COMPILE_ASSERT(SkPaint::kRound_Cap == 1, paint_cap_mismatch);
    SK_COMPILE_ASSERT(SkPaint::kSquare_Cap == 2, paint_cap_mismatch);
    SK_COMPILE_ASSERT(SkPaint::kCapCount == 3, paint_cap_mismatch);
    SkASSERT(strokeCap >= 0 && strokeCap <= 2);
    dict->insertInt("LC", strokeCap);

    SK_COMPILE_ASSERT(SkPaint::kMiter_Join == 0, paint_join_mismatch);
    SK_COMPILE_ASSERT(SkPaint::kRound_Join == 1, paint_join_mismatch);
    SK_COMPILE_ASSERT(SkPaint::kBevel_Join == 2, paint_join_mismatch);
    SK_COMPILE_ASSERT(SkPaint::kJoinCount == 3, paint_join_mismatch);
    SkASSERT(strokeJoin >= 0 && strokeJoin <= 2);
    dict->insertInt("LJ", strokeJoin);

    dict->insertScalar("LW", fStrokeWidth);
    dict->insertScalar("ML", fStrokeMiter);
    dict->insertBool("SA", true);  // SA = Auto stroke adjustment.
    dict->insertName("BM", as_blend_mode(xferMode));
    dict->emitObject(stream, objNumMap, substitutes);
}
Exemplo n.º 25
0
uint32_t GrPathUtils::cubicPointCount(const GrPoint points[],
                                           GrScalar tol) {
    if (tol < gMinCurveTol) {
        tol == gMinCurveTol;
    }
    GrAssert(tol > 0);

    GrScalar d = GrMax(
        points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]),
        points[2].distanceToLineSegmentBetweenSqd(points[0], points[3]));
    d = SkScalarSqrt(d);
    if (d <= tol) {
        return 1;
    } else {
        int temp = SkScalarCeil(SkScalarSqrt(SkScalarDiv(d, tol)));
        int pow2 = GrNextPow2(temp);
        // Because of NaNs & INFs we can wind up with a degenerate temp
        // such that pow2 comes out negative. Also, our point generator
        // will always output at least one pt.
        if (pow2 < 1) {
            pow2 = 1;
        }
        return GrMin(pow2, MAX_POINTS_PER_CURVE);
    }
}
Exemplo n.º 26
0
static void normalize(SkScalar v[3]) {
    SkScalar mag = SkScalarSquare(v[0]) + SkScalarSquare(v[1]) + SkScalarSquare(v[2]);
    mag = SkScalarSqrt(mag);

    for (int i = 0; i < 3; i++) {
        v[i] = SkScalarDiv(v[i], mag);
    }
}
Exemplo n.º 27
0
SkScalar SkInterpolatorBase::ComputeRelativeT(SkMSec time, SkMSec prevTime,
                                  SkMSec nextTime, const SkScalar blend[4]) {
    SkASSERT(time > prevTime && time < nextTime);

    SkScalar t = SkScalarDiv((SkScalar)(time - prevTime),
                             (SkScalar)(nextTime - prevTime));
    return blend ?
            SkUnitCubicInterp(t, blend[0], blend[1], blend[2], blend[3]) : t;
}
Exemplo n.º 28
0
SkScalar SkPerlinNoiseShader::PerlinNoiseShaderContext::calculateTurbulenceValueForPoint(
        int channel, StitchData& stitchData, const SkPoint& point) const {
    const SkPerlinNoiseShader& perlinNoiseShader = static_cast<const SkPerlinNoiseShader&>(fShader);
    if (perlinNoiseShader.fStitchTiles) {
        // Set up TurbulenceInitial stitch values.
        stitchData = fPaintingData->fStitchDataInit;
    }
    SkScalar turbulenceFunctionResult = 0;
    SkPoint noiseVector(SkPoint::Make(SkScalarMul(point.x(), fPaintingData->fBaseFrequency.fX),
                                      SkScalarMul(point.y(), fPaintingData->fBaseFrequency.fY)));
    SkScalar ratio = SK_Scalar1;
    for (int octave = 0; octave < perlinNoiseShader.fNumOctaves; ++octave) {
        SkScalar noise = noise2D(channel, stitchData, noiseVector);
        turbulenceFunctionResult += SkScalarDiv(
            (perlinNoiseShader.fType == kFractalNoise_Type) ? noise : SkScalarAbs(noise), ratio);
        noiseVector.fX *= 2;
        noiseVector.fY *= 2;
        ratio *= 2;
        if (perlinNoiseShader.fStitchTiles) {
            // Update stitch values
            stitchData.fWidth  *= 2;
            stitchData.fWrapX   = stitchData.fWidth + kPerlinNoise;
            stitchData.fHeight *= 2;
            stitchData.fWrapY   = stitchData.fHeight + kPerlinNoise;
        }
    }

    // The value of turbulenceFunctionResult comes from ((turbulenceFunctionResult) + 1) / 2
    // by fractalNoise and (turbulenceFunctionResult) by turbulence.
    if (perlinNoiseShader.fType == kFractalNoise_Type) {
        turbulenceFunctionResult =
            SkScalarMul(turbulenceFunctionResult, SK_ScalarHalf) + SK_ScalarHalf;
    }

    if (channel == 3) { // Scale alpha by paint value
        turbulenceFunctionResult = SkScalarMul(turbulenceFunctionResult,
            SkScalarDiv(SkIntToScalar(getPaintAlpha()), SkIntToScalar(255)));
    }

    // Clamp result
    return SkScalarPin(turbulenceFunctionResult, 0, SK_Scalar1);
}
Exemplo n.º 29
0
bool SkSliderView::onClick(Click* click)
{
	if (fMax)
	{
		SkScalar percent = SkScalarDiv(click->fCurr.fX + SK_Scalar1, this->width() - SK_Scalar1*2);
		percent = SkMaxScalar(0, SkMinScalar(percent, SK_Scalar1));
		this->setValue(SkScalarRound(percent * fMax));
		return true;
	}
	return false;
}
Exemplo n.º 30
0
SkBBoxHierarchy* SkPicture::createBBoxHierarchy() const {
    // These values were empirically determined to produce reasonable
    // performance in most cases.
    static const int kRTreeMinChildren = 6;
    static const int kRTreeMaxChildren = 11;

    SkScalar aspectRatio = SkScalarDiv(SkIntToScalar(fWidth),
                                       SkIntToScalar(fHeight));
    return SkRTree::Create(kRTreeMinChildren, kRTreeMaxChildren,
                           aspectRatio);
}