当前位置: 首页>>代码示例>>C++>>正文


C++ SkShader::unref方法代码示例

本文整理汇总了C++中SkShader::unref方法的典型用法代码示例。如果您正苦于以下问题:C++ SkShader::unref方法的具体用法?C++ SkShader::unref怎么用?C++ SkShader::unref使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SkShader的用法示例。


在下文中一共展示了SkShader::unref方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SkIntToScalar

	ShaderView()
    {
        SkImageDecoder::DecodeFile("/cover.png", &fBitmap);

        SkPoint pts[2];
        SkColor colors[2];
        
        pts[0].set(0, 0);
        pts[1].set(SkIntToScalar(100), 0);
        colors[0] = SK_ColorRED;
        colors[1] = SK_ColorBLUE;
        SkShader* shaderA = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp_TileMode);
        
        pts[0].set(0, 0);
        pts[1].set(0, SkIntToScalar(100));
        colors[0] = SK_ColorBLACK;
        colors[1] = SkColorSetARGB(0x80, 0, 0, 0);
        SkShader* shaderB = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp_TileMode);
        
        SkXfermode* mode = SkPorterDuff::CreateXfermode(SkPorterDuff::kDstIn_Mode);

        fShader = new SkComposeShader(shaderA, shaderB, mode);
        shaderA->unref();
        shaderB->unref();
        mode->unref();
    }
开发者ID:Html5Lexloo,项目名称:o3d,代码行数:26,代码来源:SampleShaders.cpp

示例2: onDraw

    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++) {
                SkMatrix scale = SkMatrix::I();

                if (i == 5) { // if the clamp case
                    scale.setScale(0.5f, 0.5f);
                    scale.postTranslate(25.f, 25.f);
                }

                SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, scale);

                paint.setShader(shader);
                canvas->drawRect(r, paint);
                shader->unref();
                canvas->translate(0, SkIntToScalar(120));
            }
            canvas->restore();
            canvas->translate(SkIntToScalar(120), 0);
        }
    }
开发者ID:guolianzhu,项目名称:skia,代码行数:33,代码来源:gradients.cpp

示例3:

static cairo_status_t
_cairo_skia_context_set_source (void *abstract_cr,
				cairo_pattern_t *source)
{
    cairo_skia_context_t *cr = (cairo_skia_context_t *) abstract_cr;
    SkColor color;

    if (cr->source != NULL) {
	if (cr->source_image != NULL) {
	    _cairo_surface_release_source_image (cr->source, cr->source_image, cr->source_extra);
	    cr->source_image = NULL;
	}
	cairo_surface_destroy (cr->source);
	cr->source = NULL;
    }

    if (pattern_to_sk_color (source, color)) {
	cr->paint->setColor (color);
    } else {
	SkShader *shader = source_to_sk_shader (cr, source);
	if (shader == NULL) {
	    UNSUPPORTED;
	    return CAIRO_STATUS_SUCCESS;
	}

	cr->paint->setShader (shader);
	shader->unref ();

	cr->paint->setFilterBitmap (pattern_filter_to_sk (source));
    }

    /* XXX change notification */
    return CAIRO_STATUS_SUCCESS;
}
开发者ID:Ashod,项目名称:WinCairoRequirements,代码行数:34,代码来源:cairo-skia-context.cpp

示例4: gradient_slide

static void gradient_slide(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);
    paint.setDither(true);

    canvas->translate(SkIntToScalar(20), SkIntToScalar(10));
    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);
            paint.setShader(shader);
            canvas->drawRect(r, paint);
            shader->unref();
            canvas->translate(0, SkIntToScalar(120));
        }
        canvas->restore();
        canvas->translate(SkIntToScalar(120), 0);
    }
}
开发者ID:Adenilson,项目名称:skia,代码行数:25,代码来源:SampleSlides.cpp

示例5: onDraw

    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);
        }
    }
开发者ID:bunhere,项目名称:skia,代码行数:35,代码来源:gradients.cpp

示例6: SkIntToScalar

int
sk_test_linear_gradient(caskbench_context_t *ctx)
{
    int w = ctx->canvas_width;
    int h = ctx->canvas_height;
    int stops = 10;

    SkPoint pts[2];
    pts[0].iset(0, 0);
    pts[1].iset(100, 100);
    SkColor colors[10];
    SkScalar pos[10];

    for (int i = 0; i < stops; i++) {
        pos[i] = i / SkIntToScalar(stops - 1);
        colors[i] = skiaRandomColor();
    }

    SkShader *shader = SkGradientShader::CreateLinear(pts, colors, pos, stops,
                                          SkShader::kClamp_TileMode);
    ctx->skia_paint->setShader(shader);

    shapes_t shape;
    shape_copy(&ctx->shape_defaults, &shape);
    for (int i=0; i<ctx->size; i++) {
        double x1 = (double)rnd()/RAND_MAX * w;
        double x2 = (double)rnd()/RAND_MAX * w;
        double y1 = (double)rnd()/RAND_MAX * h;
        double y2 = (double)rnd()/RAND_MAX * h;

        double xx = MIN(x1, x2);
        double yy = MIN(x1, x2);
        double ww = abs(x2 - x1);
        double hh = abs(y2 - y1);

        ctx->skia_canvas->save();
        ctx->skia_canvas->translate(SkDoubleToScalar(xx), SkDoubleToScalar(yy));
        ctx->skia_canvas->scale(SkDoubleToScalar(ww/100), SkDoubleToScalar(hh/100));

        // transform(shape.width/100, 0, 0, shape.height/100, 0, 0)
        shape.x = 0;
        shape.y = 0;
        shape.width = 100;
        shape.height = 100;
        shape.fill_type = CB_FILL_LINEAR_GRADIENT;

        ctx->skia_paint->setStyle(SkPaint::kFill_Style);
        ctx->skia_paint->setShader(shader);

        skiaDrawRectangle(ctx, &shape);

        ctx->skia_canvas->restore();
    }
    if (shader)
        shader->unref();

    return 1;
}
开发者ID:codekiddy2,项目名称:caskbench,代码行数:58,代码来源:linear-gradient.cpp

示例7: paintButtonLike

static void paintButtonLike(RenderTheme* theme, RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
{
    SkCanvas* const canvas = i.context->platformContext()->canvas();
    SkPaint paint;
    SkRect skrect;
    const int right = rect.x() + rect.width();
    const int bottom = rect.y() + rect.height();
    SkColor baseColor = SkColorSetARGB(0xff, 0xdd, 0xdd, 0xdd);
    if (o->style()->hasBackground())
        baseColor = o->style()->backgroundColor().rgb();
    double h, s, l;
    Color(baseColor).getHSL(h, s, l);
    // Our standard gradient is from 0xdd to 0xf8. This is the amount of
    // increased luminance between those values.
    SkColor lightColor(brightenColor(h, s, l, 0.105));

    // If the button is too small, fallback to drawing a single, solid color
    if (rect.width() < 5 || rect.height() < 5) {
        paint.setColor(baseColor);
        skrect.set(rect.x(), rect.y(), right, bottom);
        canvas->drawRect(skrect, paint);
        return;
    }

    const int borderAlpha = theme->isHovered(o) ? 0x80 : 0x55;
    paint.setARGB(borderAlpha, 0, 0, 0);
    canvas->drawLine(rect.x() + 1, rect.y(), right - 1, rect.y(), paint);
    canvas->drawLine(right - 1, rect.y() + 1, right - 1, bottom - 1, paint);
    canvas->drawLine(rect.x() + 1, bottom - 1, right - 1, bottom - 1, paint);
    canvas->drawLine(rect.x(), rect.y() + 1, rect.x(), bottom - 1, paint);

    paint.setARGB(0xff, 0, 0, 0);
    SkPoint p[2];
    const int lightEnd = theme->isPressed(o) ? 1 : 0;
    const int darkEnd = !lightEnd;
    p[lightEnd].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.y()));
    p[darkEnd].set(SkIntToScalar(rect.x()), SkIntToScalar(bottom - 1));
    SkColor colors[2];
    colors[0] = lightColor;
    colors[1] = baseColor;

    SkShader* shader = SkGradientShader::CreateLinear(
        p, colors, NULL, 2, SkShader::kClamp_TileMode, NULL);
    paint.setStyle(SkPaint::kFill_Style);
    paint.setShader(shader);
    shader->unref();

    skrect.set(rect.x() + 1, rect.y() + 1, right - 1, bottom - 1);
    canvas->drawRect(skrect, paint);

    paint.setShader(NULL);
    paint.setColor(brightenColor(h, s, l, -0.0588));
    canvas->drawPoint(rect.x() + 1, rect.y() + 1, paint);
    canvas->drawPoint(right - 2, rect.y() + 1, paint);
    canvas->drawPoint(rect.x() + 1, bottom - 2, paint);
    canvas->drawPoint(right - 2, bottom - 2, paint);
}
开发者ID:halfkiss,项目名称:ComponentSuperAccessor,代码行数:57,代码来源:RenderThemeChromiumSkia.cpp

示例8: test_gradient

static void test_gradient(skiatest::Reporter* reporter)
{
    SkPoint pts[2];
    pts[0].iset(0, 0);
    pts[1].iset(1, 0);
    SkColor colors[2];
    SkScalar pos[2] = {SkIntToScalar(0), SkIntToScalar(1)};
    int count = 2;
    SkShader::TileMode mode = SkShader::kClamp_TileMode;

    // test 1: all opaque
    colors[0] = SkColorSetARGB(0xFF, 0, 0, 0);
    colors[1] = SkColorSetARGB(0xFF, 0, 0, 0);
    SkShader* grad = SkGradientShader::CreateLinear(pts, colors, pos, count,
                                                    mode);
    REPORTER_ASSERT(reporter, grad);
    REPORTER_ASSERT(reporter, grad->isOpaque());
    grad->unref();

    // test 2: all 0 alpha
    colors[0] = SkColorSetARGB(0, 0, 0, 0);
    colors[1] = SkColorSetARGB(0, 0, 0, 0);
    grad = SkGradientShader::CreateLinear(pts, colors, pos, count, mode);
    REPORTER_ASSERT(reporter, grad);
    REPORTER_ASSERT(reporter, !grad->isOpaque());
    grad->unref();

    // test 3: one opaque, one transparent
    colors[0] = SkColorSetARGB(0xFF, 0, 0, 0);
    colors[1] = SkColorSetARGB(0x40, 0, 0, 0);
    grad = SkGradientShader::CreateLinear(pts, colors, pos, count, mode);
    REPORTER_ASSERT(reporter, grad);
    REPORTER_ASSERT(reporter, !grad->isOpaque());
    grad->unref();

    // test 4: test 3, swapped
    colors[0] = SkColorSetARGB(0x40, 0, 0, 0);
    colors[1] = SkColorSetARGB(0xFF, 0, 0, 0);
    grad = SkGradientShader::CreateLinear(pts, colors, pos, count, mode);
    REPORTER_ASSERT(reporter, grad);
    REPORTER_ASSERT(reporter, !grad->isOpaque());
    grad->unref();
}
开发者ID:alexanderbill,项目名称:skia,代码行数:43,代码来源:ShaderOpacityTest.cpp

示例9: UNSUPPORTED

static cairo_int_status_t
_cairo_skia_surface_paint (void *asurface,
			   cairo_operator_t op,
			   const cairo_pattern_t *source,
			   cairo_clip_t *clip)
{
    cairo_skia_surface_t *surface = (cairo_skia_surface_t *) asurface;
    cairo_image_surface_t *image = NULL;
    cairo_status_t status;
    void *image_extra;
    SkColor color;

    status = _cairo_surface_clipper_set_clip (&surface->clipper, clip);
    if (unlikely (status))
	return (cairo_int_status_t) status;

    if (pattern_to_sk_color (source, color)) {
	surface->canvas->drawColor (color, operator_to_sk (op));
	return CAIRO_INT_STATUS_SUCCESS;
    }

    SkMatrix bitmapMatrix;
    SkBitmap *bitmap = pattern_to_sk_bitmap (surface, source, &bitmapMatrix,
					     &image, &image_extra);
    SkShader *shader = NULL;
    if (!bitmap)
	shader = pattern_to_sk_shader (surface, source, &image, &image_extra);

    if (!bitmap && !shader)
	return UNSUPPORTED("pattern to bitmap and shader conversion");

    SkPaint paint;
    paint.setFilterBitmap (pattern_filter_to_sk (source));
    paint.setXfermodeMode (operator_to_sk (op));

    if (shader) {
	paint.setShader (shader);
	surface->canvas->drawPaint (paint);
    } else {
	surface->canvas->drawBitmapMatrix (*bitmap, bitmapMatrix, &paint);
    }

    if (bitmap)
	delete bitmap;
    if (shader)
	shader->unref ();

    if (image != NULL) {
	_cairo_surface_release_source_image (&surface->base,
					     image, image_extra);
    }

    return CAIRO_INT_STATUS_SUCCESS;
}
开发者ID:AZed,项目名称:cairo,代码行数:54,代码来源:cairo-skia-surface.cpp

示例10: make_bitmap

 void make_bitmap() {
     fBitmap.allocN32Pixels(80, 80);
     SkCanvas canvas(fBitmap);
     canvas.clear(0x00000000);
     SkPaint paint;
     paint.setAntiAlias(true);
     SkShader* shader = MakeLinear();
     paint.setShader(shader);
     SkRect r = { 0, 0, SkIntToScalar(80), SkIntToScalar(80) };
     canvas.drawRect(r, paint);
     shader->unref();
 }
开发者ID:RobinWuDev,项目名称:Qt,代码行数:12,代码来源:colorcube.cpp

示例11: test_bitmap

static void test_bitmap(skiatest::Reporter* reporter) {
    SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);

    SkBitmap bmp;
    bmp.setConfig(info);

    // test 1: bitmap without pixel data
    SkShader* shader = SkShader::CreateBitmapShader(bmp,
        SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
    REPORTER_ASSERT(reporter, shader);
    REPORTER_ASSERT(reporter, !shader->isOpaque());
    shader->unref();

    // From this point on, we have pixels
    bmp.allocPixels(info);

    // test 2: not opaque by default
    shader = SkShader::CreateBitmapShader(bmp,
        SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
    REPORTER_ASSERT(reporter, shader);
    REPORTER_ASSERT(reporter, !shader->isOpaque());
    shader->unref();

    // test 3: explicitly opaque
    bmp.setAlphaType(kOpaque_SkAlphaType);
    shader = SkShader::CreateBitmapShader(bmp,
        SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
    REPORTER_ASSERT(reporter, shader);
    REPORTER_ASSERT(reporter, shader->isOpaque());
    shader->unref();

    // test 4: explicitly not opaque
    bmp.setAlphaType(kPremul_SkAlphaType);
    shader = SkShader::CreateBitmapShader(bmp,
        SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
    REPORTER_ASSERT(reporter, shader);
    REPORTER_ASSERT(reporter, !shader->isOpaque());
    shader->unref();

}
开发者ID:alexanderbill,项目名称:skia,代码行数:40,代码来源:ShaderOpacityTest.cpp

示例12: make_bitmapfade

static SkShader* make_bitmapfade(const SkBitmap& bm)
{
    SkPoint pts[2];
    SkColor colors[2];

    pts[0].set(0, 0);
    pts[1].set(0, SkIntToScalar(bm.height()));
    colors[0] = SK_ColorBLACK;
    colors[1] = SkColorSetARGB(0, 0, 0, 0);
    SkShader* shaderA = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp_TileMode);

    SkShader* shaderB = SkShader::CreateBitmapShader(bm,
                        SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);

    SkXfermode* mode = SkPorterDuff::CreateXfermode(SkPorterDuff::kDstIn_Mode);

    SkShader* shader = new SkComposeShader(shaderB, shaderA, mode);
    shaderA->unref();
    shaderB->unref();
    mode->unref();
    
    return shader;
}
开发者ID:Html5Lexloo,项目名称:o3d,代码行数:23,代码来源:SampleShaders.cpp

示例13: switch

void
sk_set_fill_style(caskbench_context_t *ctx, const shapes_t *shape)
{
    SkShader* shader = NULL;
    switch (shape->fill_type) {
        case CB_FILL_NONE:
            ctx->skia_paint->setStyle(SkPaint::kStroke_Style);
            break;
        case CB_FILL_SOLID:
            if (shape->stroke_width <= 0)
                ctx->skia_paint->setStyle(SkPaint::kFill_Style);
            else
                ctx->skia_paint->setStyle(SkPaint::kStrokeAndFill_Style);
            break;
        case CB_FILL_LINEAR_GRADIENT:
            if(shape->shape_type == CB_SHAPE_STAR || shape->shape_type == CB_SHAPE_CIRCLE)
                shader = skiaCreateLinearGradientShader(shape->y-shape->radius, shape->y + shape->radius);
            else
                shader = skiaCreateLinearGradientShader(shape->y, shape->y + shape->height);
            ctx->skia_paint->setStyle(SkPaint::kFill_Style);
            ctx->skia_paint->setShader(shader);
            break;
        case CB_FILL_RADIAL_GRADIENT:
            shader = skiaCreateRadialGradientShader(shape);
            ctx->skia_paint->setStyle(SkPaint::kFill_Style);
            ctx->skia_paint->setShader(shader);
            break;
        case CB_FILL_IMAGE_PATTERN:
            if (ctx->stock_image_path) {
            shader = skiaCreateBitmapShader(ctx->stock_image_path);
            ctx->skia_paint->setStyle(SkPaint::kFill_Style);
            ctx->skia_paint->setShader(shader);
            }
            break;
#if 0
        case CB_FILL_HERRINGBONE_PATTERN:  /* TODO */
            break;
#endif
        default:
            break;
    }

    if (shader)
        shader->unref();
}
开发者ID:codekiddy2,项目名称:caskbench,代码行数:45,代码来源:skia-shapes.cpp

示例14:

static cairo_status_t
_cairo_skia_context_set_source_surface (void *abstract_cr,
					cairo_surface_t *surface,
					double	   x,
					double	   y)
{
    cairo_skia_context_t *cr = (cairo_skia_context_t *) abstract_cr;
    cairo_pattern_t *pattern;
    cairo_matrix_t matrix;
    cairo_status_t status;

    if (surface->type == CAIRO_SURFACE_TYPE_SKIA) {
	cairo_skia_surface_t *esurf = (cairo_skia_surface_t *) surface;
	SkShader *shader;

	shader = SkShader::CreateBitmapShader (*esurf->bitmap,
					       SkShader::kClamp_TileMode, /* XXX */
					       SkShader::kClamp_TileMode);

	cr->paint->setShader (shader);
	shader->unref ();

	cr->paint->setFilterLevel (true ?
		(SkPaint::kLow_FilterLevel) : (SkPaint::kNone_FilterLevel));

	return CAIRO_STATUS_SUCCESS;
    }

    pattern = cairo_pattern_create_for_surface (surface);
    if (unlikely (pattern->status))
	return pattern->status;

    cairo_matrix_init_translate (&matrix, -x, -y);
    cairo_pattern_set_matrix (pattern, &matrix);

    status = _cairo_skia_context_set_source (cr, pattern);
    cairo_pattern_destroy (pattern);

    return status;
}
开发者ID:behdad,项目名称:cairo,代码行数:40,代码来源:cairo-skia-context.cpp

示例15:

 virtual ~ClampView() {
     fGrad->unref();
 }
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:3,代码来源:SampleClamp.cpp


注:本文中的SkShader::unref方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。