本文整理汇总了C++中SkIRect::setXYWH方法的典型用法代码示例。如果您正苦于以下问题:C++ SkIRect::setXYWH方法的具体用法?C++ SkIRect::setXYWH怎么用?C++ SkIRect::setXYWH使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkIRect
的用法示例。
在下文中一共展示了SkIRect::setXYWH方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onDrawContent
virtual void onDrawContent(SkCanvas* canvas) {
SkIRect srcRect;
SkRect dstRect;
SkPaint paint;
paint.setFilterBitmap(true);
// Test that bitmap draws from malloc-backed bitmaps respect
// the constrained texture domain.
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(5.0f, 5.0f, 305.0f, 305.0f);
canvas->drawBitmapRect(fBM, &srcRect, dstRect, &paint);
// Test that bitmap draws across separate devices also respect
// the constrainted texture domain.
// Note: GPU-backed bitmaps follow a different rendering path
// when copying from one GPU device to another.
SkAutoTUnref<SkDevice> secondDevice(canvas->createCompatibleDevice(
SkBitmap::kARGB_8888_Config, 5, 5, true));
SkCanvas secondCanvas(secondDevice.get());
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(1.0f, 1.0f, 3.0f, 3.0f);
secondCanvas.drawBitmapRect(fBM, &srcRect, dstRect, &paint);
SkBitmap deviceBitmap = secondDevice->accessBitmap(false);
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(405.0f, 5.0f, 305.0f, 305.0f);
canvas->drawBitmapRect(deviceBitmap, &srcRect, dstRect, &paint);
// Test that bitmap blurring using a subrect
// renders correctly
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(5.0f, 405.0f, 305.0f, 305.0f);
SkMaskFilter* mf = SkBlurMaskFilter::Create(
5,
SkBlurMaskFilter::kNormal_BlurStyle,
SkBlurMaskFilter::kHighQuality_BlurFlag |
SkBlurMaskFilter::kIgnoreTransform_BlurFlag);
paint.setMaskFilter(mf)->unref();
canvas->drawBitmapRect(deviceBitmap, &srcRect, dstRect, &paint);
// Blur and a rotation + NULL src rect
// This should not trigger the texture domain code
// but it will test a code path in SkGpuDevice::drawBitmap
// that handles blurs with rects transformed to non-
// orthogonal rects. It also tests the NULL src rect handling
mf = SkBlurMaskFilter::Create(
5,
SkBlurMaskFilter::kNormal_BlurStyle,
SkBlurMaskFilter::kHighQuality_BlurFlag);
paint.setMaskFilter(mf)->unref();
dstRect.setXYWH(-150.0f, -150.0f, 300.0f, 300.0f);
canvas->translate(550, 550);
canvas->rotate(45);
canvas->drawBitmapRect(fBM, NULL, dstRect, &paint);
}
示例2: onDraw
virtual void onDraw(SkCanvas* canvas) {
drawBG(canvas);
SkBitmap sprite;
sprite.setConfig(SkBitmap::kARGB_8888_Config, 4, 4, 4*sizeof(SkColor));
const SkColor spriteData[16] = {
SK_ColorBLACK, SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW,
SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorRED,
SK_ColorGREEN, SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLUE,
SK_ColorYELLOW, SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorBLACK
};
sprite.allocPixels();
sprite.lockPixels();
SkPMColor* addr = sprite.getAddr32(0, 0);
for (size_t i = 0; i < SK_ARRAY_COUNT(spriteData); ++i) {
addr[i] = SkPreMultiplyColor(spriteData[i]);
}
sprite.unlockPixels();
// We draw a magnified subrect of the sprite
// sample interpolation may cause color bleeding around edges
// the subrect is a pure white area
SkIRect srcRect;
SkRect dstRect;
SkPaint paint;
paint.setFilterBitmap(true);
//First row : full texture with and without filtering
srcRect.setXYWH(0, 0, 4, 4);
dstRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0)
, SkIntToScalar(100), SkIntToScalar(100));
canvas->drawBitmapRect(sprite, &srcRect, dstRect, &paint);
dstRect.setXYWH(SkIntToScalar(100), SkIntToScalar(0)
, SkIntToScalar(100), SkIntToScalar(100));
canvas->drawBitmapRect(sprite, &srcRect, dstRect);
//Second row : sub rect of texture with and without filtering
srcRect.setXYWH(1, 1, 2, 2);
dstRect.setXYWH(SkIntToScalar(25), SkIntToScalar(125)
, SkIntToScalar(50), SkIntToScalar(50));
canvas->drawBitmapRect(sprite, &srcRect, dstRect, &paint);
dstRect.setXYWH(SkIntToScalar(125), SkIntToScalar(125)
, SkIntToScalar(50), SkIntToScalar(50));
canvas->drawBitmapRect(sprite, &srcRect, dstRect);
}
示例3: sampledDecode
SkCodec::Result SkSampledCodec::sampledDecode(const SkImageInfo& info, void* pixels,
size_t rowBytes, const AndroidOptions& options) {
// We should only call this function when sampling.
SkASSERT(options.fSampleSize > 1);
// Create options struct for the codec.
SkCodec::Options sampledOptions;
sampledOptions.fZeroInitialized = options.fZeroInitialized;
sampledOptions.fPremulBehavior = SkTransferFunctionBehavior::kIgnore;
// FIXME: This was already called by onGetAndroidPixels. Can we reduce that?
int sampleSize = options.fSampleSize;
int nativeSampleSize;
SkISize nativeSize = this->accountForNativeScaling(&sampleSize, &nativeSampleSize);
// Check if there is a subset.
SkIRect subset;
int subsetY = 0;
int subsetWidth = nativeSize.width();
int subsetHeight = nativeSize.height();
if (options.fSubset) {
// We will need to know about subsetting in the y-dimension in order to use the
// scanline decoder.
// Update the subset to account for scaling done by this->codec().
const SkIRect* subsetPtr = options.fSubset;
// Do the divide ourselves, instead of calling get_scaled_dimension. If
// X and Y are 0, they should remain 0, rather than being upgraded to 1
// due to being smaller than the sampleSize.
const int subsetX = subsetPtr->x() / nativeSampleSize;
subsetY = subsetPtr->y() / nativeSampleSize;
subsetWidth = get_scaled_dimension(subsetPtr->width(), nativeSampleSize);
subsetHeight = get_scaled_dimension(subsetPtr->height(), nativeSampleSize);
// The scanline decoder only needs to be aware of subsetting in the x-dimension.
subset.setXYWH(subsetX, 0, subsetWidth, nativeSize.height());
sampledOptions.fSubset = ⊂
}
// Since we guarantee that output dimensions are always at least one (even if the sampleSize
// is greater than a given dimension), the input sampleSize is not always the sampleSize that
// we use in practice.
const int sampleX = subsetWidth / info.width();
const int sampleY = subsetHeight / info.height();
const int samplingOffsetY = get_start_coord(sampleY);
const int startY = samplingOffsetY + subsetY;
const int dstHeight = info.height();
const SkImageInfo nativeInfo = info.makeWH(nativeSize.width(), nativeSize.height());
{
// Although startScanlineDecode expects the bottom and top to match the
// SkImageInfo, startIncrementalDecode uses them to determine which rows to
// decode.
SkCodec::Options incrementalOptions = sampledOptions;
SkIRect incrementalSubset;
if (sampledOptions.fSubset) {
incrementalSubset.fTop = subsetY;
incrementalSubset.fBottom = subsetY + subsetHeight;
incrementalSubset.fLeft = sampledOptions.fSubset->fLeft;
incrementalSubset.fRight = sampledOptions.fSubset->fRight;
incrementalOptions.fSubset = &incrementalSubset;
}
const SkCodec::Result startResult = this->codec()->startIncrementalDecode(nativeInfo,
pixels, rowBytes, &incrementalOptions);
if (SkCodec::kSuccess == startResult) {
SkSampler* sampler = this->codec()->getSampler(true);
if (!sampler) {
return SkCodec::kUnimplemented;
}
if (sampler->setSampleX(sampleX) != info.width()) {
return SkCodec::kInvalidScale;
}
if (get_scaled_dimension(subsetHeight, sampleY) != info.height()) {
return SkCodec::kInvalidScale;
}
sampler->setSampleY(sampleY);
int rowsDecoded;
const SkCodec::Result incResult = this->codec()->incrementalDecode(&rowsDecoded);
if (incResult == SkCodec::kSuccess) {
return SkCodec::kSuccess;
}
SkASSERT(incResult == SkCodec::kIncompleteInput || incResult == SkCodec::kErrorInInput);
SkASSERT(rowsDecoded <= info.height());
this->codec()->fillIncompleteImage(info, pixels, rowBytes, options.fZeroInitialized,
info.height(), rowsDecoded);
return incResult;
} else if (startResult != SkCodec::kUnimplemented) {
return startResult;
} // kUnimplemented means use the old method.
}
// Start the scanline decode.
SkCodec::Result result = this->codec()->startScanlineDecode(nativeInfo,
//.........这里部分代码省略.........
示例4: onDraw
void onDraw(SkCanvas* canvas) override {
SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)};
static const int kMaxSrcRectSize = 1 << (SkNextLog2(gBmpSize) + 2);
static const int kPadX = 30;
static const int kPadY = 40;
SkPaint paint;
paint.setAlpha(0x20);
canvas->drawBitmapRect(fLargeBitmap, SkRect::MakeIWH(gSize, gSize), &paint);
canvas->translate(SK_Scalar1 * kPadX / 2,
SK_Scalar1 * kPadY / 2);
SkPaint blackPaint;
SkScalar titleHeight = SK_Scalar1 * 24;
blackPaint.setColor(SK_ColorBLACK);
blackPaint.setTextSize(titleHeight);
blackPaint.setAntiAlias(true);
sk_tool_utils::set_portable_typeface(&blackPaint);
SkString title;
title.printf("Bitmap size: %d x %d", gBmpSize, gBmpSize);
canvas->drawText(title.c_str(), title.size(), 0,
titleHeight, blackPaint);
canvas->translate(0, SK_Scalar1 * kPadY / 2 + titleHeight);
int rowCount = 0;
canvas->save();
for (int w = 1; w <= kMaxSrcRectSize; w *= 4) {
for (int h = 1; h <= kMaxSrcRectSize; h *= 4) {
SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSize - h) / 2, w, h);
fProc(canvas, fImage, fLargeBitmap, srcRect, dstRect);
SkString label;
label.appendf("%d x %d", w, h);
blackPaint.setAntiAlias(true);
blackPaint.setStyle(SkPaint::kFill_Style);
blackPaint.setTextSize(SK_Scalar1 * 10);
SkScalar baseline = dstRect.height() +
blackPaint.getTextSize() + SK_Scalar1 * 3;
canvas->drawText(label.c_str(), label.size(),
0, baseline,
blackPaint);
blackPaint.setStyle(SkPaint::kStroke_Style);
blackPaint.setStrokeWidth(SK_Scalar1);
blackPaint.setAntiAlias(false);
canvas->drawRect(dstRect, blackPaint);
canvas->translate(dstRect.width() + SK_Scalar1 * kPadX, 0);
++rowCount;
if ((dstRect.width() + kPadX) * rowCount > gSize) {
canvas->restore();
canvas->translate(0, dstRect.height() + SK_Scalar1 * kPadY);
canvas->save();
rowCount = 0;
}
}
}
{
// test the following code path:
// SkGpuDevice::drawPath() -> SkGpuDevice::drawWithMaskFilter()
SkIRect srcRect;
SkPaint paint;
SkBitmap bm;
bm = make_chessbm(5, 5);
paint.setFilterQuality(kLow_SkFilterQuality);
srcRect.setXYWH(1, 1, 3, 3);
SkMaskFilter* mf = SkBlurMaskFilter::Create(
kNormal_SkBlurStyle,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
SkBlurMaskFilter::kHighQuality_BlurFlag |
SkBlurMaskFilter::kIgnoreTransform_BlurFlag);
paint.setMaskFilter(mf)->unref();
canvas->drawBitmapRect(bm, srcRect, dstRect, &paint);
}
}
示例5: onClear
void GrVkGpuCommandBuffer::onClear(GrRenderTarget* target, const GrFixedClip& clip, GrColor color) {
// parent class should never let us get here with no RT
SkASSERT(target);
SkASSERT(!clip.hasWindowRectangles());
VkClearColorValue vkColor;
GrColorToRGBAFloat(color, vkColor.float32);
GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target);
if (fIsEmpty && !clip.scissorEnabled()) {
// We will change the render pass to do a clear load instead
GrVkRenderPass::LoadStoreOps vkColorOps(VK_ATTACHMENT_LOAD_OP_CLEAR,
VK_ATTACHMENT_STORE_OP_STORE);
GrVkRenderPass::LoadStoreOps vkStencilOps(VK_ATTACHMENT_LOAD_OP_LOAD,
VK_ATTACHMENT_STORE_OP_STORE);
const GrVkRenderPass* oldRP = fRenderPass;
const GrVkResourceProvider::CompatibleRPHandle& rpHandle =
vkRT->compatibleRenderPassHandle();
if (rpHandle.isValid()) {
fRenderPass = fGpu->resourceProvider().findRenderPass(rpHandle,
vkColorOps,
vkStencilOps);
} else {
fRenderPass = fGpu->resourceProvider().findRenderPass(*vkRT,
vkColorOps,
vkStencilOps);
}
SkASSERT(fRenderPass->isCompatible(*oldRP));
oldRP->unref(fGpu);
GrColorToRGBAFloat(color, fColorClearValue.color.float32);
fStartsWithClear = true;
return;
}
// We always do a sub rect clear with clearAttachments since we are inside a render pass
VkClearRect clearRect;
// Flip rect if necessary
SkIRect vkRect;
if (!clip.scissorEnabled()) {
vkRect.setXYWH(0, 0, vkRT->width(), vkRT->height());
} else if (kBottomLeft_GrSurfaceOrigin != vkRT->origin()) {
vkRect = clip.scissorRect();
} else {
const SkIRect& scissor = clip.scissorRect();
vkRect.setLTRB(scissor.fLeft, vkRT->height() - scissor.fBottom,
scissor.fRight, vkRT->height() - scissor.fTop);
}
clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop };
clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height() };
clearRect.baseArrayLayer = 0;
clearRect.layerCount = 1;
uint32_t colorIndex;
SkAssertResult(fRenderPass->colorAttachmentIndex(&colorIndex));
VkClearAttachment attachment;
attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
attachment.colorAttachment = colorIndex;
attachment.clearValue.color = vkColor;
fCommandBuffer->clearAttachments(fGpu, 1, &attachment, 1, &clearRect);
fIsEmpty = false;
return;
}
示例6: sampledDecode
SkCodec::Result SkSampledCodec::sampledDecode(const SkImageInfo& info, void* pixels,
size_t rowBytes, const AndroidOptions& options) {
// We should only call this function when sampling.
SkASSERT(options.fSampleSize > 1);
// Create options struct for the codec.
SkCodec::Options sampledOptions;
sampledOptions.fZeroInitialized = options.fZeroInitialized;
// FIXME: This was already called by onGetAndroidPixels. Can we reduce that?
int sampleSize = options.fSampleSize;
int nativeSampleSize;
SkISize nativeSize = this->accountForNativeScaling(&sampleSize, &nativeSampleSize);
// Check if there is a subset.
SkIRect subset;
int subsetY = 0;
int subsetWidth = nativeSize.width();
int subsetHeight = nativeSize.height();
if (options.fSubset) {
// We will need to know about subsetting in the y-dimension in order to use the
// scanline decoder.
// Update the subset to account for scaling done by this->codec().
SkIRect* subsetPtr = options.fSubset;
// Do the divide ourselves, instead of calling get_scaled_dimension. If
// X and Y are 0, they should remain 0, rather than being upgraded to 1
// due to being smaller than the sampleSize.
const int subsetX = subsetPtr->x() / nativeSampleSize;
subsetY = subsetPtr->y() / nativeSampleSize;
subsetWidth = get_scaled_dimension(subsetPtr->width(), nativeSampleSize);
subsetHeight = get_scaled_dimension(subsetPtr->height(), nativeSampleSize);
// The scanline decoder only needs to be aware of subsetting in the x-dimension.
subset.setXYWH(subsetX, 0, subsetWidth, nativeSize.height());
sampledOptions.fSubset = ⊂
}
// Start the scanline decode.
SkCodec::Result result = this->codec()->startScanlineDecode(
info.makeWH(nativeSize.width(), nativeSize.height()), &sampledOptions,
options.fColorPtr, options.fColorCount);
if (SkCodec::kSuccess != result) {
return result;
}
SkSampler* sampler = this->codec()->getSampler(true);
if (!sampler) {
return SkCodec::kUnimplemented;
}
// Since we guarantee that output dimensions are always at least one (even if the sampleSize
// is greater than a given dimension), the input sampleSize is not always the sampleSize that
// we use in practice.
const int sampleX = subsetWidth / info.width();
const int sampleY = subsetHeight / info.height();
if (sampler->setSampleX(sampleX) != info.width()) {
return SkCodec::kInvalidScale;
}
if (get_scaled_dimension(subsetHeight, sampleY) != info.height()) {
return SkCodec::kInvalidScale;
}
const int samplingOffsetY = get_start_coord(sampleY);
const int startY = samplingOffsetY + subsetY;
int dstHeight = info.height();
switch(this->codec()->getScanlineOrder()) {
case SkCodec::kTopDown_SkScanlineOrder: {
if (!this->codec()->skipScanlines(startY)) {
this->codec()->fillIncompleteImage(info, pixels, rowBytes, options.fZeroInitialized,
dstHeight, 0);
return SkCodec::kIncompleteInput;
}
void* pixelPtr = pixels;
for (int y = 0; y < dstHeight; y++) {
if (1 != this->codec()->getScanlines(pixelPtr, 1, rowBytes)) {
this->codec()->fillIncompleteImage(info, pixels, rowBytes,
options.fZeroInitialized, dstHeight, y + 1);
return SkCodec::kIncompleteInput;
}
if (y < dstHeight - 1) {
if (!this->codec()->skipScanlines(sampleY - 1)) {
this->codec()->fillIncompleteImage(info, pixels, rowBytes,
options.fZeroInitialized, dstHeight, y + 1);
return SkCodec::kIncompleteInput;
}
}
pixelPtr = SkTAddOffset<void>(pixelPtr, rowBytes);
}
return SkCodec::kSuccess;
}
case SkCodec::kOutOfOrder_SkScanlineOrder:
case SkCodec::kBottomUp_SkScanlineOrder: {
// Note that these modes do not support subsetting.
SkASSERT(0 == subsetY && nativeSize.height() == subsetHeight);
int y;
for (y = 0; y < nativeSize.height(); y++) {
int srcY = this->codec()->nextScanline();
if (is_coord_necessary(srcY, sampleY, dstHeight)) {
//.........这里部分代码省略.........