void RenderSkinButton::Draw(SkCanvas* canvas, const IntRect& r, RenderSkinAndroid::State newState)
{
    // If we failed to decode, do nothing.  This way the browser still works,
    // and webkit will still draw the label and layout space for us.
    if (!gDecoded) {
        return;
    }
    
    // Ensure that the state is within the valid range of our array.
    SkASSERT(static_cast<unsigned>(newState) < 
            static_cast<unsigned>(RenderSkinAndroid::kNumStates));

    // Set up the ninepatch information for drawing.
    SkRect bounds(r);
    const PatchData& pd = gFiles[newState];
    int marginValue = pd.margin + pd.outset;

    SkIRect margin;

    margin.set(marginValue, marginValue, marginValue, marginValue);
    if (gHighRes) {
    /* FIXME: it shoudn't be necessary to offset the button here,
       but gives the right results. */
        bounds.offset(0, SK_Scalar1 * 2);
    /* FIXME: This temporarily gets around the fact that the margin values and
       positioning were created for a low res asset, which was used on
       g1-like devices. A better fix would be to read the offset information
       out of the png. */
        margin.set(10, 9, 10, 14);
    }
    // Draw to the canvas.
    SkNinePatch::DrawNine(canvas, bounds, gButton[newState], margin);
}
void ScrollbarThemeChromiumLinux::paintThumb(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect)
{
    const bool hovered = scrollbar->hoveredPart() == ThumbPart;
    const int midx = rect.x() + rect.width() / 2;
    const int midy = rect.y() + rect.height() / 2;
    const bool vertical = scrollbar->orientation() == VerticalScrollbar;
    SkCanvas* const canvas = gc->platformContext()->canvas();

    SkScalar thumb[3];
    SkColorToHSV(hovered
                 ? PlatformThemeChromiumGtk::thumbActiveColor()
                 : PlatformThemeChromiumGtk::thumbInactiveColor(),
                 thumb);

    SkPaint paint;
    paint.setColor(PlatformThemeChromiumGtk::saturateAndBrighten(thumb, 0, 0.02));

    SkIRect skrect;
    if (vertical)
        skrect.set(rect.x(), rect.y(), midx + 1, rect.y() + rect.height());
    else
        skrect.set(rect.x(), rect.y(), rect.x() + rect.width(), midy + 1);

    canvas->drawIRect(skrect, paint);

    paint.setColor(PlatformThemeChromiumGtk::saturateAndBrighten(thumb, 0, -0.02));

    if (vertical)
        skrect.set(midx + 1, rect.y(), rect.x() + rect.width(), rect.y() + rect.height());
    else
        skrect.set(rect.x(), midy + 1, rect.x() + rect.width(), rect.y() + rect.height());

    canvas->drawIRect(skrect, paint);

    SkScalar track[3];
    SkColorToHSV(PlatformThemeChromiumGtk::trackColor(), track);
    paint.setColor(PlatformThemeChromiumGtk::outlineColor(track, thumb));
    drawBox(canvas, rect, paint);

    if (rect.height() > 10 && rect.width() > 10) {
        const int grippyHalfWidth = 2;
        const int interGrippyOffset = 3;
        if (vertical) {
            drawHorizLine(canvas, midx - grippyHalfWidth, midx + grippyHalfWidth, midy - interGrippyOffset, paint);
            drawHorizLine(canvas, midx - grippyHalfWidth, midx + grippyHalfWidth, midy,                     paint);
            drawHorizLine(canvas, midx - grippyHalfWidth, midx + grippyHalfWidth, midy + interGrippyOffset, paint);
        } else {
            drawVertLine(canvas, midx - interGrippyOffset, midy - grippyHalfWidth, midy + grippyHalfWidth, paint);
            drawVertLine(canvas, midx,                     midy - grippyHalfWidth, midy + grippyHalfWidth, paint);
            drawVertLine(canvas, midx + interGrippyOffset, midy - grippyHalfWidth, midy + grippyHalfWidth, paint);
        }
    }
}
static void show_bm(SkCanvas* canvas, int width, int height, SkColor color) {
    SkBitmap bm;
    make_bm(&bm, width, height, color);

    SkPaint paint;
    SkRect r;
    SkIRect ir;

    paint.setStyle(SkPaint::kStroke_Style);

    ir.set(0, 0, 128, 128);
    r.set(ir);

    canvas->save();
    canvas->clipRect(r);
    canvas->drawBitmap(bm, 0, 0, NULL);
    canvas->restore();
    canvas->drawRect(r, paint);

    r.offset(SkIntToScalar(150), 0);
    // exercises extract bitmap, but not shader
    canvas->drawBitmapRect(bm, &ir, r, NULL);
    canvas->drawRect(r, paint);

    r.offset(SkIntToScalar(150), 0);
    // exercises bitmapshader
    canvas->drawBitmapRect(bm, NULL, r, NULL);
    canvas->drawRect(r, paint);
}
Example #4
0
static SkIRect webRectToSkIRect(const WebRect& webRect)
{
    SkIRect irect;
    irect.set(webRect.x, webRect.y,
        webRect.x + webRect.width - 1, webRect.y + webRect.height - 1);
    return irect;
}
Example #5
0
    virtual void onDraw(SkCanvas* canvas) {
        this->drawBG(canvas);

      //  canvas->scale(1.5f, 1.5f);
        
        canvas->drawBitmap(fBM, 0, 0);
        
        SkIRect margins;
        SkRect  dst;
        int d = 25;
        
        margins.set(d, d, d, d);
        margins.fLeft   = fBM.width()/2 - 1;
        margins.fTop    = fBM.height()/2 - 1;
        margins.fRight  = fBM.width() - margins.fLeft - 1;
        margins.fBottom = fBM.height() - margins.fTop - 1;

   //     canvas->translate(fX/5, fY/5);
        canvas->translate(0, 76);

        dst.set(0, 0, SkIntToScalar(200), SkIntToScalar(200));
        
        SkPaint paint;
        paint.setAntiAlias(false);
        paint.setDither(true);
        paint.setFilterBitmap(false);
    //    SkNinePatch::DrawNine(canvas, dst, fBM, margins, &paint);
        test_rects(canvas, fBM, &paint);
    }
void addCornerArc(SkPath* path, const SkRect& rect, const IntSize& size, int startAngle)
{
    SkIRect ir;
    int rx = SkMin32(SkScalarRound(rect.width()), size.width());
    int ry = SkMin32(SkScalarRound(rect.height()), size.height());

    ir.set(-rx, -ry, rx, ry);
    switch (startAngle) {
    case 0:
        ir.offset(rect.fRight - ir.fRight, rect.fBottom - ir.fBottom);
        break;
    case 90:
        ir.offset(rect.fLeft - ir.fLeft, rect.fBottom - ir.fBottom);
        break;
    case 180:
        ir.offset(rect.fLeft - ir.fLeft, rect.fTop - ir.fTop);
        break;
    case 270:
        ir.offset(rect.fRight - ir.fRight, rect.fTop - ir.fTop);
        break;
    default:
        ASSERT(0);
    }

    SkRect r;
    r.set(ir);
    path->arcTo(r, SkIntToScalar(startAngle), SkIntToScalar(90), false);
}
bool Snapshot::clipRegionOp(float left, float top, float right, float bottom, SkRegion::Op op) {
    SkIRect tmp;
    tmp.set(left, top, right, bottom);
    clipRegion->op(tmp, op);
    copyClipRectFromRegion();
    return true;
}
void RenderSkinButton::Draw(SkCanvas* canvas, const IntRect& r, RenderSkinAndroid::State newState)
{
    // If we failed to decode, do nothing.  This way the browser still works,
    // and webkit will still draw the label and layout space for us.
    if (!gDecoded) {
        return;
    }
    
    // Ensure that the state is within the valid range of our array.
    SkASSERT(static_cast<unsigned>(newState) < 
            static_cast<unsigned>(RenderSkinAndroid::kNumStates));

    // Set up the ninepatch information for drawing.
    SkRect bounds;
    android_setrect(&bounds, r);
    const PatchData& pd = gFiles[newState];
    int marginValue = pd.margin + pd.outset;

    SkIRect margin;

    margin.set(marginValue, marginValue, marginValue, marginValue);
    
    // Draw to the canvas.
    SkNinePatch::DrawNine(canvas, bounds, gButton[newState], margin);
}
Example #9
0
 virtual void onDraw(SkCanvas* canvas)
 {
     this->drawBG(canvas);
     
     canvas->drawBitmap(fBitmap, 0, 0, NULL);
     
     SkIRect subset;
     const int SRC_WIDTH = 16;
     const int SRC_HEIGHT = 16;
     
     subset.set(0, 0, SRC_WIDTH, SRC_HEIGHT);
     subset.offset(fCurrX, fCurrY);
     
     SkDebugf("---- src x=%d y=%d\n", subset.fLeft, subset.fTop);
     
     SkRect  dst0, dst1;
     SkScalar y = SkIntToScalar(fBitmap.height() + 16);
     
     dst0.set(SkIntToScalar(50), y,
              SkIntToScalar(50+SRC_WIDTH),
              y + SkIntToScalar(SRC_HEIGHT));
     dst1 = dst0;
     dst1.offset(SkIntToScalar(200), 0);
     dst1.fRight = dst1.fLeft + 8 * dst0.width();
     dst1.fBottom = dst1.fTop + 8 * dst0.height();
     
     canvas->drawBitmapRect(fBitmap, &subset, dst0, NULL);
     canvas->drawBitmapRect(fBitmap, &subset, dst1, NULL);
     
     SkPaint paint;
     paint.setColor(0x88FF0000);
     canvas->drawRect(dst0, paint);
     paint.setColor(0x880000FF);
     canvas->drawRect(dst1, paint);
 }
void WebTestThemeControlWin::nestedBoxes(int indentLeft, int indentTop, int indentRight, int indentBottom, SkColor outerColor, SkColor innerColor)
{
    SkIRect lirect;
    box(m_irect, outerColor);
    lirect.set(m_irect.fLeft + indentLeft, m_irect.fTop + indentTop, m_irect.fRight - indentRight, m_irect.fBottom - indentBottom);
    box(lirect, innerColor);
}
Example #11
0
void SkPageFlipper::inval(const SkIRect& rect) {
    SkIRect r;
    r.set(0, 0, fWidth, fHeight);
    if (r.intersect(rect)) {
        fDirty1->op(r, SkRegion::kUnion_Op);
    }
}
static jboolean Region_op0(JNIEnv* env, jobject, jlong dstHandle, jint left, jint top, jint right, jint bottom, jint op) {
    SkRegion* dst = reinterpret_cast<SkRegion*>(dstHandle);
    SkIRect ir;

    ir.set(left, top, right, bottom);
    bool result = dst->op(ir, (SkRegion::Op)op);
    return boolTojboolean(result);
}
static void make_rgn(SkRegion* rgn, int left, int top, int right, int bottom,
                     size_t count, int32_t runs[]) {
    SkIRect r;
    r.set(left, top, right, bottom);
    
    rgn->debugSetRuns(runs, count);
    SkASSERT(rgn->getBounds() == r);
}
Example #14
0
void BaseRenderer::renderTiledContent(TileRenderInfo& renderInfo)
{
    const bool visualIndicator = TilesManager::instance()->getShowVisualIndicator();
    const SkSize& tileSize = renderInfo.tileSize;

    SkCanvas canvas;
    setupCanvas(renderInfo, &canvas);

    if (!canvas.getDevice()) {
        // TODO: consider ALOGE
        ALOGV("Error: No Device");
        return;
    }

    double before;
    if (visualIndicator) {
        canvas.save();
        before = currentTimeMS();
    }

    canvas.translate(-renderInfo.x * tileSize.width(), -renderInfo.y * tileSize.height());
    canvas.scale(renderInfo.scale, renderInfo.scale);
    if (renderInfo.tilePainter == NULL) {
        ALOGV("Error: No tilePainter");
        return;
    }
    renderInfo.tilePainter->paint(&canvas);
    if (renderInfo.baseTile && renderInfo.baseTile->backTexture())
        checkForPureColor(renderInfo, &canvas);
    else
        renderInfo.isPureColor = false;

    if (visualIndicator) {
        double after = currentTimeMS();
        canvas.restore();
        unsigned int updateCount = renderInfo.tilePainter->getUpdateCount() & UPDATE_COUNT_MASK;
        const int color = updateCount & UPDATE_COUNT_ALPHA_MASK;

        // only color the invalidated area
        SkPaint paint;
        paint.setARGB(color, 0, 255, 0);
        SkIRect rect;
        rect.set(0, 0, tileSize.width(), tileSize.height());
        canvas.drawIRect(rect, paint);

        drawTileInfo(&canvas, renderInfo, updateCount, after - before);

        // paint the tile boundaries
        paint.setARGB(64, 255, 0, 0);
        paint.setStrokeWidth(3);
        canvas.drawLine(0, 0, tileSize.width(), tileSize.height(), paint);
        paint.setARGB(64, 0, 255, 0);
        canvas.drawLine(0, tileSize.height(), tileSize.width(), 0, paint);
        paint.setARGB(128, 0, 0, 255);
        canvas.drawLine(tileSize.width(), 0, tileSize.width(), tileSize.height(), paint);
    }
    renderingComplete(renderInfo, &canvas);
}
Example #15
0
// stolen from SkDraw.cpp - D1G_NoBounder_RectClip
static void SkGL_Draw1Glyph(const SkDraw1Glyph& state, const SkGlyph& glyph,
                            int x, int y) {
    SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0);

    SkGLDrawProcs* procs = (SkGLDrawProcs*)state.fDraw->fProcs;
    
    x += glyph.fLeft;
    y  += glyph.fTop;
    
    // check if we're clipped out (nothing to draw)
	SkIRect bounds;
	bounds.set(x, y, x + glyph.fWidth, y + glyph.fHeight);
    if (!SkIRect::Intersects(state.fClip->getBounds(), bounds)) {
        return;
    }
    
    // now dig up our texture cache
    
    SkGlyphCache* gcache = state.fCache;
    void* auxData;
    SkGLTextCache* textCache = NULL;
    
    if (gcache->getAuxProcData(SkGLDevice::GlyphCacheAuxProc, &auxData)) {
        textCache = (SkGLTextCache*)auxData;            
    }
    if (NULL == textCache) {
        // need to create one
        textCache = SkNEW(SkGLTextCache);
        gcache->setAuxProc(SkGLDevice::GlyphCacheAuxProc, textCache);
    }
    
    int offset;
    SkGLTextCache::Strike* strike = textCache->findGlyph(glyph, &offset);
    if (NULL == strike) {
        // make sure the glyph has an image
        uint8_t* aa = (uint8_t*)glyph.fImage;               
        if (NULL == aa) {
            aa = (uint8_t*)gcache->findImage(glyph);
            if (NULL == aa) {
                return; // can't rasterize glyph
            }
        }
        strike = textCache->addGlyphAndBind(glyph, aa, &offset);
        if (NULL == strike) {
            // too big to cache, need to draw as is...
            return;
        }
    }
    
    const int shiftW = strike->widthShift();
    const int shiftH = strike->heightShift();
    
    SkFixed left = offset << (16 - shiftW);
    SkFixed right = (offset + glyph.fWidth) << (16 - shiftW);
    SkFixed bottom = glyph.fHeight << (16 - shiftH);

    procs->addQuad(strike->texture(), x, y, glyph, left, right, bottom);
}
bool RenderThemeChromiumSkia::paintSliderThumb(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
{
    // Make a thumb similar to the scrollbar thumb.
    const bool hovered = isHovered(o) || toRenderSlider(o->parent())->inDragMode();
    const int midx = rect.x() + rect.width() / 2;
    const int midy = rect.y() + rect.height() / 2;
    const bool vertical = (o->style()->appearance() == SliderThumbVerticalPart);
    SkCanvas* const canvas = i.context->platformContext()->canvas();

    const SkColor thumbLightGrey = SkColorSetARGB(0xff, 0xf4, 0xf2, 0xef);
    const SkColor thumbDarkGrey = SkColorSetARGB(0xff, 0xea, 0xe5, 0xe0);
    SkPaint paint;
    paint.setColor(hovered ? SK_ColorWHITE : thumbLightGrey);

    SkIRect skrect;
    if (vertical)
        skrect.set(rect.x(), rect.y(), midx + 1, rect.bottom());
    else
        skrect.set(rect.x(), rect.y(), rect.right(), midy + 1);

    canvas->drawIRect(skrect, paint);

    paint.setColor(hovered ? thumbLightGrey : thumbDarkGrey);

    if (vertical)
        skrect.set(midx + 1, rect.y(), rect.right(), rect.bottom());
    else
        skrect.set(rect.x(), midy + 1, rect.right(), rect.bottom());

    canvas->drawIRect(skrect, paint);

    const SkColor borderDarkGrey = SkColorSetARGB(0xff, 0x9d, 0x96, 0x8e);
    paint.setColor(borderDarkGrey);
    drawBox(canvas, rect, paint);

    if (rect.height() > 10 && rect.width() > 10) {
        drawHorizLine(canvas, midx - 2, midx + 2, midy, paint);
        drawHorizLine(canvas, midx - 2, midx + 2, midy - 3, paint);
        drawHorizLine(canvas, midx - 2, midx + 2, midy + 3, paint);
    }

    return false;
}
Example #17
0
DEF_TEST(BitmapCopy_extractSubset, reporter) {
    for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) {
        SkBitmap srcOpaque, srcPremul;
        setup_src_bitmaps(&srcOpaque, &srcPremul, gPairs[i].fColorType);

        SkBitmap bitmap(srcOpaque);
        SkBitmap subset;
        SkIRect r;
        // Extract a subset which has the same width as the original. This
        // catches a bug where we cloned the genID incorrectly.
        r.set(0, 1, W, 3);
        bitmap.setIsVolatile(true);
        // Relies on old behavior of extractSubset failing if colortype is unknown
        if (kUnknown_SkColorType != bitmap.colorType() && bitmap.extractSubset(&subset, r)) {
            REPORTER_ASSERT(reporter, subset.width() == W);
            REPORTER_ASSERT(reporter, subset.height() == 2);
            REPORTER_ASSERT(reporter, subset.alphaType() == bitmap.alphaType());
            REPORTER_ASSERT(reporter, subset.isVolatile() == true);

            // Test copying an extracted subset.
            for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) {
                SkBitmap copy;
                bool success = subset.copyTo(&copy, gPairs[j].fColorType);
                if (!success) {
                    // Skip checking that success matches fValid, which is redundant
                    // with the code below.
                    REPORTER_ASSERT(reporter, gPairs[i].fColorType != gPairs[j].fColorType);
                    continue;
                }

                // When performing a copy of an extracted subset, the gen id should
                // change.
                REPORTER_ASSERT(reporter, copy.getGenerationID() != subset.getGenerationID());

                REPORTER_ASSERT(reporter, copy.width() == W);
                REPORTER_ASSERT(reporter, copy.height() == 2);

                if (gPairs[i].fColorType == gPairs[j].fColorType) {
                    SkAutoLockPixels alp0(subset);
                    SkAutoLockPixels alp1(copy);
                    // they should both have, or both not-have, a colortable
                    bool hasCT = subset.getColorTable() != nullptr;
                    REPORTER_ASSERT(reporter, (copy.getColorTable() != nullptr) == hasCT);
                }
            }
        }

        bitmap = srcPremul;
        bitmap.setIsVolatile(false);
        if (bitmap.extractSubset(&subset, r)) {
            REPORTER_ASSERT(reporter, subset.alphaType() == bitmap.alphaType());
            REPORTER_ASSERT(reporter, subset.isVolatile() == false);
        }
    }
}
bool Snapshot::clipRegionOp(float left, float top, float right, float bottom, SkRegion::Op op) {
#if STENCIL_BUFFER_SIZE
    SkIRect tmp;
    tmp.set(left, top, right, bottom);
    clipRegion->op(tmp, op);
    copyClipRectFromRegion();
    return true;
#else
    return false;
#endif
}
Example #19
0
    bool CopyTilesRenderer::render(SkBitmap** out) {
        int i = 0;
        bool success = true;
        SkBitmap dst;
        for (int x = 0; x < this->getViewWidth(); x += fLargeTileWidth) {
            for (int y = 0; y < this->getViewHeight(); y += fLargeTileHeight) {
                SkAutoCanvasRestore autoRestore(fCanvas, true);
                // Translate so that we draw the correct portion of the picture.
                // Perform a postTranslate so that the scaleFactor does not interfere with the
                // positioning.
                SkMatrix mat(fCanvas->getTotalMatrix());
                mat.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
                fCanvas->setMatrix(mat);
                // Draw the picture
                fCanvas->drawPicture(*fPicture);
                // Now extract the picture into tiles
                const SkBitmap& baseBitmap = fCanvas->getDevice()->accessBitmap(false);
                SkIRect subset;
                for (int tileY = 0; tileY < fLargeTileHeight; tileY += this->getTileHeight()) {
                    for (int tileX = 0; tileX < fLargeTileWidth; tileX += this->getTileWidth()) {
                        subset.set(tileX, tileY, tileX + this->getTileWidth(),
                                   tileY + this->getTileHeight());
                        SkDEBUGCODE(bool extracted =)
                        baseBitmap.extractSubset(&dst, subset);
                        SkASSERT(extracted);
                        if (!fOutputDir.isEmpty()) {
                            // Similar to write() in PictureRenderer.cpp, but just encodes
                            // a bitmap directly.
                            // TODO: Share more common code with write() to do this, to properly
                            // write out the JSON summary, etc.
                            SkString pathWithNumber;
                            make_filepath(&pathWithNumber, fOutputDir, fInputFilename);
                            pathWithNumber.remove(pathWithNumber.size() - 4, 4);
                            pathWithNumber.appendf("%i.png", i++);
                            SkBitmap copy;
#if SK_SUPPORT_GPU
                            if (isUsingGpuDevice()) {
                                dst.pixelRef()->readPixels(&copy, &subset);
                            } else {
#endif
                                dst.copyTo(&copy);
#if SK_SUPPORT_GPU
                            }
#endif
                            success &= SkImageEncoder::EncodeFile(pathWithNumber.c_str(), copy,
                                                                  SkImageEncoder::kPNG_Type, 100);
                        }
                    }
                }
            }
        }
        return success;
    }
void PluginWidgetAndroid::computeVisiblePluginRect() {

    // ensure the visibleDocRect has been set (i.e. not equal to zero)
    if (m_visibleDocRect.isEmpty() || !m_pluginWindow || m_requestedVisibleRectCount < 1)
        return;

    // create a rect that will contain as many of the rects that will fit on screen
    SkIRect visibleRect;
    visibleRect.setEmpty();

    for (int counter = 0; counter < m_requestedVisibleRectCount; counter++) {

        ANPRectI* rect = &m_requestedVisibleRects[counter];

        // create skia rect for easier manipulation and convert it to page coordinates
        SkIRect pluginRect;
        pluginRect.set(rect->left, rect->top, rect->right, rect->bottom);
        pluginRect.offset(m_pluginWindow->x, m_pluginWindow->y);

        // ensure the rect falls within the plugin's bounds
        if (!m_pluginBounds.contains(pluginRect)) {
#if DEBUG_VISIBLE_RECTS
            PLUGIN_LOG("%s (%d,%d,%d,%d) !contain (%d,%d,%d,%d)", __FUNCTION__,
                       m_pluginBounds.fLeft, m_pluginBounds.fTop,
                       m_pluginBounds.fRight, m_pluginBounds.fBottom,
                       pluginRect.fLeft, pluginRect.fTop,
                       pluginRect.fRight, pluginRect.fBottom);
            // assume that the desired outcome is to clamp to the container
            if (pluginRect.intersect(m_pluginBounds)) {
                visibleRect = pluginRect;
            }
#endif
            continue;
        }

        // combine this new rect with the higher priority rects
        pluginRect.join(visibleRect);

        // check to see if the new rect could be made to fit within the screen
        // bounds. If this is the highest priority rect then attempt to center
        // even if it doesn't fit on the screen.
        if (counter > 0 && (m_visibleDocRect.width() < pluginRect.width() ||
                            m_visibleDocRect.height() < pluginRect.height()))
          break;

        // set the new visible rect
        visibleRect = pluginRect;
    }

    m_requestedVisibleRect = visibleRect;
    scrollToVisiblePluginRect();
}
Example #21
0
static void drawbug(SkCanvas* canvas, SkScalar scale) {
    SkBitmap    bm, bm2;
    
    SkImageDecoder::DecodeFile("/skimages/btn_default_normal.9.png", &bm);
    SkPaint paint;
    
    SkIRect subset;
    subset.set(1, 1, bm.width() - 1, bm.height() - 1);
    bm.extractSubset(&bm2, subset);
    
#if 0
    SkPoint verts[16], texs[16];
    uint16_t    index[54];
    
    SkShader* s = SkShader::CreateBitmapShader(bm2, SkShader::kClamp_TileMode,
                                        SkShader::kClamp_TileMode);
    paint.setShader(s)->unref();
    
    setup_vertexbug(verts, texs, index);
    int indexCount = 6;    // 54
    canvas->drawVertices(SkCanvas::kTriangles_VertexMode, 16, verts, texs,
                         NULL, NULL, &index[6], indexCount, paint);

#if 0
    paint.setShader(NULL);
    canvas->drawVertices(SkCanvas::kTriangles_VertexMode, 16, verts, NULL,
                         NULL, NULL, index, indexCount, paint);
#endif
#else
    SkRect  dst;
    SkIRect margin;
    
    dst.set(SkIntToScalar(10), SkIntToScalar(10),
            SkIntToScalar(100) + scale,
            SkIntToScalar(40) + scale);
    margin.set(9, 9, 9, 9);
    SkNinePatch::DrawNine(canvas, dst, bm2, margin, NULL);
#endif
}
Example #22
0
static bool clip_to_limit(const SkRegion& orig, SkRegion* reduced) {
    // need to limit coordinates such that the width/height of our rect can be represented
    // in SkFixed (16.16). See skbug.com/7998
    const int32_t limit = 32767 >> 1;

    SkIRect limitR;
    limitR.set(-limit, -limit, limit, limit);
    if (limitR.contains(orig.getBounds())) {
        return false;
    }
    reduced->op(orig, limitR, SkRegion::kIntersect_Op);
    return true;
}
Example #23
0
	NinePatchView() {
        SkImageDecoder::DecodeFile("/skimages/btn_default_normal_disable.9.png", &fBM);
        
        // trim off the edge guide-lines
        SkBitmap tmp;
        SkIRect r;
        r.set(1, 1, fBM.width() - 1, fBM.height() - 1);
        fBM.extractSubset(&tmp, r);
        fBM.swap(tmp);
        
        fX = SkIntToScalar(fBM.width());
        fY = 0;
    }
Example #24
0
void DraggedTabView::PaintDetachedView(gfx::Canvas* canvas)
{
    gfx::Size ps = GetPreferredSize();
    gfx::CanvasSkia scale_canvas(ps.width(), ps.height(), false);
    SkBitmap& bitmap_device = const_cast<SkBitmap&>(
                                  skia::GetTopDevice(scale_canvas)->accessBitmap(true));
    bitmap_device.eraseARGB(0, 0, 0, 0);

    int tab_height = renderer_bounds_.back().height();
    scale_canvas.FillRectInt(kDraggedTabBorderColor, 0,
                             tab_height - kDragFrameBorderSize,
                             ps.width(), ps.height() - tab_height);
    int image_x = kDragFrameBorderSize;
    int image_y = tab_height;
    int image_w = ps.width() - kTwiceDragFrameBorderSize;
    int image_h = contents_size_.height();
    scale_canvas.FillRectInt(SK_ColorBLACK, image_x, image_y, image_w, image_h);
    photobooth_->PaintScreenshotIntoCanvas(
        &scale_canvas,
        gfx::Rect(image_x, image_y, image_w, image_h));
    for(size_t i=0; i<renderers_.size(); ++i)
    {
        renderers_[i]->Paint(&scale_canvas);
    }

    SkIRect subset;
    subset.set(0, 0, ps.width(), ps.height());
    SkBitmap mipmap = scale_canvas.ExtractBitmap();
    mipmap.buildMipMap(true);

    SkShader* bitmap_shader =
        SkShader::CreateBitmapShader(mipmap, SkShader::kClamp_TileMode,
                                     SkShader::kClamp_TileMode);

    SkMatrix shader_scale;
    shader_scale.setScale(kScalingFactor, kScalingFactor);
    bitmap_shader->setLocalMatrix(shader_scale);

    SkPaint paint;
    paint.setShader(bitmap_shader);
    paint.setAntiAlias(true);
    bitmap_shader->unref();

    SkRect rc;
    rc.fLeft = 0;
    rc.fTop = 0;
    rc.fRight = SkIntToScalar(ps.width());
    rc.fBottom = SkIntToScalar(ps.height());
    canvas->AsCanvasSkia()->drawRect(rc, paint);
}
Example #25
0
void SampleWindow::afterChildren(SkCanvas* orig) {
    switch (fCanvasType) {
    case kRaster_CanvasType:
        break;
    case kPicture_CanvasType:
        if (true) {
            SkPicture* pict = new SkPicture(*fPicture);
            fPicture->unref();
            orig->drawPicture(*pict);
            pict->unref();
        } else if (true) {
            SkDynamicMemoryWStream ostream;
            fPicture->serialize(&ostream);
            fPicture->unref();

            SkMemoryStream istream(ostream.getStream(), ostream.getOffset());
            SkPicture pict(&istream);
            orig->drawPicture(pict);
        } else {
            fPicture->draw(orig);
            fPicture->unref();
        }
        fPicture = NULL;
        break;
#ifdef SK_SUPPORT_GL
    case kOpenGL_CanvasType:
        glFlush();
        delete fGLCanvas;
        fGLCanvas = NULL;
#ifdef USE_OFFSCREEN
        reverseRedAndBlue(orig->getDevice()->accessBitmap(true));
#endif
        break;
#endif
    }

//    if ((fScrollTestX | fScrollTestY) != 0)
    {
        const SkBitmap& bm = orig->getDevice()->accessBitmap(true);
        int dx = fScrollTestX * 7;
        int dy = fScrollTestY * 7;
        SkIRect r;
        SkRegion inval;

        r.set(50, 50, 50+100, 50+100);
        bm.scrollRect(&r, dx, dy, &inval);
        paint_rgn(bm, r, inval);
    }
}
// http://code.google.com/p/skia/issues/detail?id=87
// Lines which is not clipped by boundary based clipping, 
// but skipped after tessellation, should be cleared by the blitter.
static void TestFillPathInverse(skiatest::Reporter* reporter) {
  FakeBlitter blitter;
  SkIRect clip;
  SkPath path;
  int height = 100;
  int width  = 200;
  int expected_lines = 5;
  clip.set(0, height - expected_lines, width, height);
  path.moveTo(0.0, 0.0);
  path.quadTo(width/2, height, width, 0.0);
  path.close();
  path.setFillType(SkPath::kInverseWinding_FillType);
  SkScan::FillPath(path, clip, &blitter);

  REPORTER_ASSERT(reporter, blitter.m_blitCount == expected_lines);
}
Example #27
0
// http://code.google.com/p/skia/issues/detail?id=87
// Lines which is not clipped by boundary based clipping,
// but skipped after tessellation, should be cleared by the blitter.
DEF_TEST(FillPathInverse, reporter) {
    FakeBlitter blitter;
    SkIRect clip;
    SkPath path;
    int height = 100;
    int width  = 200;
    int expected_lines = 5;
    clip.set(0, height - expected_lines, width, height);
    path.moveTo(0.0f, 0.0f)
        .quadTo(SkIntToScalar(width/2), SkIntToScalar(height),
              SkIntToScalar(width), 0.0f)
        .close()
        .setFillType(SkPath::kInverseWinding_FillType);
    SkScan::FillPath(path, clip, &blitter);

    REPORTER_ASSERT(reporter, blitter.m_blitCount == expected_lines);
}
Example #28
0
void nestedBoxes(SkCanvas *canvas,
    SkIRect irect,
    int indentLeft,
    int indentTop,
    int indentRight,
    int indentBottom,
    SkColor outerColor,
    SkColor innerColor)
{
    SkIRect lirect;
    box(canvas, irect, outerColor);
    lirect.set(irect.fLeft + indentLeft,
        irect.fTop + indentTop,
        irect.fRight - indentRight,
        irect.fBottom - indentBottom);
    box(canvas, lirect, innerColor);
}
Example #29
0
    bool CopyTilesRenderer::render(const SkString* path) {
        int i = 0;
        bool success = true;
        SkBitmap dst;
        for (int x = 0; x < this->getViewWidth(); x += fLargeTileWidth) {
            for (int y = 0; y < this->getViewHeight(); y += fLargeTileHeight) {
                SkAutoCanvasRestore autoRestore(fCanvas, true);
                fCanvas->translate(SkIntToScalar(-x), SkIntToScalar(-y));
                // Draw the picture
                fCanvas->drawPicture(*fPicture);
                // Now extract the picture into tiles
                const SkBitmap& baseBitmap = fCanvas->getDevice()->accessBitmap(false);
                SkIRect subset;
                for (int tileY = 0; tileY < fLargeTileHeight; tileY += this->getTileHeight()) {
                    for (int tileX = 0; tileX < fLargeTileWidth; tileX += this->getTileWidth()) {
                        subset.set(tileX, tileY, tileX + this->getTileWidth(),
                                   tileY + this->getTileHeight());
                        SkDEBUGCODE(bool extracted =)
                        baseBitmap.extractSubset(&dst, subset);
                        SkASSERT(extracted);
                        if (path != NULL) {
                            // Similar to writeAppendNumber in PictureRenderer.cpp, but just encodes
                            // a bitmap directly.
                            SkString pathWithNumber(*path);
                            pathWithNumber.appendf("%i.png", i++);
                            SkBitmap copy;
#if SK_SUPPORT_GPU
                            if (isUsingGpuDevice()) {
                                dst.pixelRef()->readPixels(&copy, &subset);
                            } else {
#endif
                                dst.copyTo(&copy, dst.config());
#if SK_SUPPORT_GPU
                            }
#endif
                            success &= SkImageEncoder::EncodeFile(pathWithNumber.c_str(), copy,
                                                                  SkImageEncoder::kPNG_Type, 100);
                        }
                    }
                }
            }
        }
        return success;
    }
Example #30
0
void ACanvasSkia::DrawGraphic(AImage* pGraphic,int x,int y,int w,int h)
{
	_clip();
	SkRect rDst;
	SkIRect rSrc;
	if( w == 0 ) w = pGraphic->GetWidth();
	if( h == 0 ) h = pGraphic->GetHeight();
	rDst.set(x,y,x+w+1,y+h+1);
	rSrc.set(0,0,pGraphic->GetWidth(),pGraphic->GetHeight());

	SkBitmap skb;
	skb.setConfig(SkBitmap::kARGB_8888_Config,pGraphic->GetWidth(),pGraphic->GetHeight());
	skb.setPixels(pGraphic->GetPixels());
// 	SkPaint paint;
// 	paint.setFlags(0);
// 	paint.setAntiAlias(false);
	m_pCanvas->drawBitmapRect(skb,&rSrc,rDst);
	Reset();
}