本文整理汇总了C++中SkRect::width方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRect::width方法的具体用法?C++ SkRect::width怎么用?C++ SkRect::width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRect
的用法示例。
在下文中一共展示了SkRect::width方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createTextureFromImage
GLuint VideoLayerManager::createTextureFromImage(int buttonType)
{
SkRect rect = SkRect(m_buttonRect);
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height());
bitmap.allocPixels();
bitmap.eraseColor(0);
SkCanvas canvas(bitmap);
canvas.drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode);
RenderSkinMediaButton::Draw(&canvas, m_buttonRect, buttonType, true, 0,
false);
GLuint texture;
glGenTextures(1, &texture);
GLUtils::createTextureWithBitmap(texture, bitmap);
bitmap.reset();
return texture;
}
示例2: test_inset
static void test_inset(skiatest::Reporter* reporter) {
SkRRect rr, rr2;
SkRect r = { 0, 0, 100, 100 };
rr.setRect(r);
rr.inset(-20, -20, &rr2);
REPORTER_ASSERT(reporter, rr2.isRect());
rr.inset(20, 20, &rr2);
REPORTER_ASSERT(reporter, rr2.isRect());
rr.inset(r.width()/2, r.height()/2, &rr2);
REPORTER_ASSERT(reporter, rr2.isEmpty());
rr.setRectXY(r, 20, 20);
rr.inset(19, 19, &rr2);
REPORTER_ASSERT(reporter, rr2.isSimple());
rr.inset(20, 20, &rr2);
REPORTER_ASSERT(reporter, rr2.isRect());
}
示例3: getGlyphMetrics
static void getGlyphMetrics(HB_Font hbFont, HB_Glyph glyph, HB_GlyphMetrics* metrics)
{
SkPaint* paint = static_cast<SkPaint*>(hbFont->userData);
paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
uint16_t glyph16 = glyph;
SkScalar width;
SkRect bounds;
paint->getTextWidths(&glyph16, sizeof(glyph16), &width, &bounds);
metrics->x = SkScalarToHBFixed(bounds.fLeft);
metrics->y = SkScalarToHBFixed(bounds.fTop);
metrics->width = SkScalarToHBFixed(bounds.width());
metrics->height = SkScalarToHBFixed(bounds.height());
metrics->xOffset = SkScalarToHBFixed(width);
// We can't actually get the |y| correct because Skia doesn't export
// the vertical advance. However, nor we do ever render vertical text at
// the moment so it's unimportant.
metrics->yOffset = 0;
}
示例4: drawRect
void SkPDFDevice::drawRect(const SkDraw& d, const SkRect& r,
const SkPaint& paint) {
if (paint.getPathEffect()) {
// Create a path for the rectangle and apply the path effect to it.
SkPath path;
path.addRect(r);
paint.getFillPath(path, &path);
SkPaint noEffectPaint(paint);
SkSafeUnref(noEffectPaint.setPathEffect(NULL));
drawPath(d, path, noEffectPaint, NULL, true);
return;
}
updateGSFromPaint(paint, false);
// Skia has 0,0 at top left, pdf at bottom left. Do the right thing.
SkScalar bottom = r.fBottom < r.fTop ? r.fBottom : r.fTop;
SkPDFUtils::AppendRectangle(r.fLeft, bottom, r.width(), r.height(),
&fContent);
SkPDFUtils::PaintPath(paint.getStyle(), SkPath::kWinding_FillType,
&fContent);
}
示例5: measure
DEF_FUZZ(PathMeasure, fuzz) {
uint8_t bits;
fuzz->next(&bits);
SkScalar distance[6];
for (auto index = 0; index < 6; ++index) {
fuzz->next(&distance[index]);
}
SkPath path;
BuildPath(fuzz, &path, SkPath::Verb::kDone_Verb);
SkRect bounds = path.getBounds();
SkScalar maxDim = SkTMax(bounds.width(), bounds.height());
SkScalar resScale = maxDim / 1000;
SkPathMeasure measure(path, bits & 1, resScale);
SkPoint position;
SkVector tangent;
ignoreResult(measure.getPosTan(distance[0], &position, &tangent));
SkPath dst;
ignoreResult(measure.getSegment(distance[1], distance[2], &dst, (bits >> 1) & 1));
ignoreResult(measure.nextContour());
ignoreResult(measure.getPosTan(distance[3], &position, &tangent));
ignoreResult(measure.getSegment(distance[4], distance[5], &dst, (bits >> 2) & 1));
}
示例6: SkIntToScalar
std::unique_ptr<GrFragmentProcessor> GrMagnifierEffect::TestCreate(GrProcessorTestData* d) {
sk_sp<GrTextureProxy> proxy = d->textureProxy(0);
const int kMaxWidth = 200;
const int kMaxHeight = 200;
const SkScalar kMaxInset = 20.0f;
uint32_t width = d->fRandom->nextULessThan(kMaxWidth);
uint32_t height = d->fRandom->nextULessThan(kMaxHeight);
SkScalar inset = d->fRandom->nextRangeScalar(1.0f, kMaxInset);
SkIRect bounds = SkIRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight));
SkRect srcRect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
auto effect = GrMagnifierEffect::Make(std::move(proxy),
bounds,
srcRect,
srcRect.width() / bounds.width(),
srcRect.height() / bounds.height(),
bounds.width() / inset,
bounds.height() / inset);
SkASSERT(effect);
return effect;
}
示例7: setupCurrentSlide
void Viewer::setupCurrentSlide(int previousSlide) {
if (fCurrentSlide == previousSlide) {
return; // no change; do nothing
}
// prepare dimensions for image slides
fSlides[fCurrentSlide]->load(SkIntToScalar(fWindow->width()), SkIntToScalar(fWindow->height()));
fGesture.reset();
fDefaultMatrix.reset();
fDefaultMatrixInv.reset();
if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) {
const SkRect contentRect = fWindow->getContentRect();
const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions();
const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize.height());
if (contentRect.width() > 0 && contentRect.height() > 0) {
fDefaultMatrix.setRectToRect(slideBounds, contentRect, SkMatrix::kStart_ScaleToFit);
SkAssertResult(fDefaultMatrix.invert(&fDefaultMatrixInv));
}
}
if (fWindow->supportsContentRect()) {
const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions();
SkRect windowRect = fWindow->getContentRect();
fDefaultMatrixInv.mapRect(&windowRect);
fGesture.setTransLimit(SkRect::MakeWH(SkIntToScalar(slideSize.width()),
SkIntToScalar(slideSize.height())),
windowRect);
}
this->updateTitle();
this->updateUIState();
if (previousSlide >= 0) {
fSlides[previousSlide]->unload();
}
fWindow->inval();
}
示例8: onDraw
virtual void onDraw(SkCanvas* canvas) {
SkPath path;
path.moveTo(0, 0);
path.cubicTo(140, 150, 40, 10, 170, 150);
SkPaint paint;
SkRect bounds = path.getBounds();
for (SkScalar dy = -1; dy <= 1; dy += 1) {
canvas->save();
for (SkScalar dx = -1; dx <= 1; dx += 1) {
canvas->save();
canvas->clipRect(bounds);
canvas->translate(dx, dy);
canvas->drawPath(path, paint);
canvas->restore();
canvas->translate(bounds.width(), 0);
}
canvas->restore();
canvas->translate(0, bounds.height());
}
}
示例9: clip
sk_sp<SkSpecialImage> SkImageFilter::DrawWithFP(GrContext* context,
sk_sp<GrFragmentProcessor> fp,
const SkIRect& bounds) {
GrPaint paint;
paint.addColorFragmentProcessor(fp.get());
paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
sk_sp<GrDrawContext> drawContext(context->newDrawContext(GrContext::kLoose_BackingFit,
bounds.width(), bounds.height(),
kRGBA_8888_GrPixelConfig));
if (!drawContext) {
return nullptr;
}
SkRect srcRect = SkRect::Make(bounds);
SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
GrClip clip(dstRect);
drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect);
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()),
kNeedNewImageUniqueID_SpecialImage,
drawContext->asTexture());
}
示例10: SkiaGetGlyphWidthAndExtents
static void SkiaGetGlyphWidthAndExtents(SkPaint* paint, hb_codepoint_t codepoint, hb_position_t* width, hb_glyph_extents_t* extents)
{
ALOG_ASSERT(codepoint <= 0xFFFF);
paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
SkScalar skWidth;
SkRect skBounds;
uint16_t glyph = codepoint;
paint->getTextWidths(&glyph, sizeof(glyph), &skWidth, &skBounds);
if (kDebugGlyphs) {
ALOGD("returned glyph for %i: width = %f", codepoint, skWidth);
}
if (width)
*width = SkScalarToHBFixed(skWidth);
if (extents) {
// Invert y-axis because Skia is y-grows-down but we set up harfbuzz to be y-grows-up.
extents->x_bearing = SkScalarToHBFixed(skBounds.fLeft);
extents->y_bearing = SkScalarToHBFixed(-skBounds.fTop);
extents->width = SkScalarToHBFixed(skBounds.width());
extents->height = SkScalarToHBFixed(-skBounds.height());
}
}
示例11: toString
static void toString(const SkRRect& rrect, SkString* str) {
SkRect r = rrect.getBounds();
str->appendf("[%g,%g %g:%g]",
SkScalarToFloat(r.fLeft), SkScalarToFloat(r.fTop),
SkScalarToFloat(r.width()), SkScalarToFloat(r.height()));
if (rrect.isOval()) {
str->append("()");
} else if (rrect.isSimple()) {
const SkVector& rad = rrect.getSimpleRadii();
str->appendf("(%g,%g)", rad.x(), rad.y());
} else if (rrect.isComplex()) {
SkVector radii[4] = {
rrect.radii(SkRRect::kUpperLeft_Corner),
rrect.radii(SkRRect::kUpperRight_Corner),
rrect.radii(SkRRect::kLowerRight_Corner),
rrect.radii(SkRRect::kLowerLeft_Corner),
};
str->appendf("(%g,%g %g,%g %g,%g %g,%g)",
radii[0].x(), radii[0].y(),
radii[1].x(), radii[1].y(),
radii[2].x(), radii[2].y(),
radii[3].x(), radii[3].y());
}
}
示例12: onFilterImageDeprecated
bool SkImageSource::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
SkRect dstRect;
ctx.ctm().mapRect(&dstRect, fDstRect);
SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height());
if (fSrcRect == bounds && dstRect == bounds) {
// No regions cropped out or resized; return entire image.
offset->fX = offset->fY = 0;
return fImage->asLegacyBitmap(result, SkImage::kRO_LegacyBitmapMode);
}
const SkIRect dstIRect = dstRect.roundOut();
SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstIRect.width(), dstIRect.height()));
if (nullptr == device.get()) {
return false;
}
SkCanvas canvas(device.get());
SkPaint paint;
// Subtract off the integer component of the translation (will be applied in loc, below).
dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop));
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
// FIXME: this probably shouldn't be necessary, but drawImageRect asserts
// None filtering when it's translate-only
paint.setFilterQuality(
fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.height() ?
kNone_SkFilterQuality : fFilterQuality);
canvas.drawImageRect(fImage, fSrcRect, dstRect, &paint, SkCanvas::kStrict_SrcRectConstraint);
*result = device.get()->accessBitmap(false);
offset->fX = dstIRect.fLeft;
offset->fY = dstIRect.fTop;
return true;
}
示例13: bounceMe
void bounceMe() {
SkScalar width = fSrcR.width();
bounce(&fSrcR.fLeft, &fDX, fLimitR.fLeft, fLimitR.fRight - width);
fSrcR.fRight = fSrcR.fLeft + width;
}
示例14:
*
* The portion in the layer, will end up SRC_OVERing the 0x80 layer pixels onto the canvas' red
* pixels, making magenta.
*
* Thus the expected result is the upper half to be magenta 0xFF7F0080, and the lower half to be
* light blue 0xFF7F7FFF.
*/
DEF_SIMPLE_GM(dont_clip_to_layer, canvas, 120, 120) {
const SkRect r { 10, 10, 110, 110 };
// Wrap the entire test inside a red layer, so we don't punch the actual gm's alpha with
// kSrc_Mode, which makes it hard to view (we like our GMs to have opaque pixels).
canvas->saveLayer(&r, nullptr);
canvas->drawColor(SK_ColorRED);
SkRect r0 = SkRect::MakeXYWH(r.left(), r.top(), r.width(), r.height()/2);
SkCanvas::SaveLayerRec rec;
rec.fPaint = nullptr;
rec.fBounds = &r0;
rec.fBackdrop = nullptr;
rec.fSaveLayerFlags = 1 << 31;//SkCanvas::kDontClipToLayer_Legacy_SaveLayerFlag;
canvas->saveLayer(rec);
do_draw(canvas, r);
canvas->restore();
canvas->restore(); // red-layer
}
/** Draw a 2px border around the target, then red behind the target;
set the clip to match the target, then draw >> the target in blue.
示例15: drawGL
bool VideoLayerAndroid::drawGL()
{
// Lazily allocated the textures.
if (!m_createdTexture) {
m_backgroundTextureId = createBackgroundTexture();
m_spinnerOuterTextureId = createSpinnerOuterTexture();
m_spinnerInnerTextureId = createSpinnerInnerTexture();
m_posterTextureId = createPosterTexture();
m_createdTexture = true;
}
SkRect rect = SkRect::MakeSize(getSize());
GLfloat surfaceMatrix[16];
SkRect innerRect = SkRect(buttonRect);
if (innerRect.contains(rect))
innerRect = rect;
innerRect.offset((rect.width() - IMAGESIZE) / 2 , (rect.height() - IMAGESIZE) / 2);
// Draw the poster image, the progressing image or the Video depending
// on the player's state.
if (m_playerState == PREPARING) {
// Show the progressing animation, with two rotating circles
// SSG
if (m_surfaceTexture.get() && (m_surfaceTexture->getTimestamp() > 0)) {
m_surfaceTexture->getTransformMatrix(surfaceMatrix);
GLuint textureId =
TilesManager::instance()->videoLayerManager()->getTextureId(uniqueId());
TilesManager::instance()->shader()->drawVideoLayerQuad(m_drawTransform,
surfaceMatrix,
rect, textureId);
TilesManager::instance()->videoLayerManager()->updateMatrix(uniqueId(),
surfaceMatrix);
} else {
TilesManager::instance()->shader()->drawLayerQuad(m_drawTransform, rect,
m_backgroundTextureId,
1, true);
}
TransformationMatrix addReverseRotation;
TransformationMatrix addRotation = m_drawTransform;
addRotation.translate(innerRect.fLeft, innerRect.fTop);
addRotation.translate(IMAGESIZE / 2, IMAGESIZE / 2);
addReverseRotation = addRotation;
addRotation.rotate(m_rotateDegree);
addRotation.translate(-IMAGESIZE / 2, -IMAGESIZE / 2);
SkRect size = SkRect::MakeWH(innerRect.width(), innerRect.height());
TilesManager::instance()->shader()->drawLayerQuad(addRotation, size,
m_spinnerOuterTextureId,
1, true);
addReverseRotation.rotate(-m_rotateDegree);
addReverseRotation.translate(-IMAGESIZE / 2, -IMAGESIZE / 2);
TilesManager::instance()->shader()->drawLayerQuad(addReverseRotation, size,
m_spinnerInnerTextureId,
1, true);
m_rotateDegree += ROTATESTEP;
} else if (m_playerState == PLAYING && m_surfaceTexture.get()) {
// Show the real video.
m_surfaceTexture->updateTexImage();
m_surfaceTexture->getTransformMatrix(surfaceMatrix);
GLuint textureId =
TilesManager::instance()->videoLayerManager()->getTextureId(uniqueId());
TilesManager::instance()->shader()->drawVideoLayerQuad(m_drawTransform,
surfaceMatrix,
rect, textureId);
TilesManager::instance()->videoLayerManager()->updateMatrix(uniqueId(),
surfaceMatrix);
} else {
GLuint textureId =
TilesManager::instance()->videoLayerManager()->getTextureId(uniqueId());
GLfloat* matrix =
TilesManager::instance()->videoLayerManager()->getMatrix(uniqueId());
if (textureId && matrix) {
// Show the screen shot for each video.
TilesManager::instance()->shader()->drawVideoLayerQuad(m_drawTransform,
matrix,
rect, textureId);
} else {
// Show the static poster b/c there is no screen shot available.
TilesManager::instance()->shader()->drawLayerQuad(m_drawTransform, rect,
m_backgroundTextureId,
1, true);
TilesManager::instance()->shader()->drawLayerQuad(m_drawTransform, innerRect,
m_posterTextureId,
1, true);
}
}
return drawChildrenGL();
}