本文整理汇总了C++中SkIRect::y方法的典型用法代码示例。如果您正苦于以下问题:C++ SkIRect::y方法的具体用法?C++ SkIRect::y怎么用?C++ SkIRect::y使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkIRect
的用法示例。
在下文中一共展示了SkIRect::y方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: extractScaledImageFragment
// This function is used to scale an image and extract a scaled fragment.
//
// ALGORITHM
//
// Because the scaled image size has to be integers, we approximate the real
// scale with the following formula (only X direction is shown):
//
// scaledImageWidth = round(scaleX * imageRect.width())
// approximateScaleX = scaledImageWidth / imageRect.width()
//
// With this method we maintain a constant scale factor among fragments in
// the scaled image. This allows fragments to stitch together to form the
// full scaled image. The downside is there will be a small difference
// between |scaleX| and |approximateScaleX|.
//
// A scaled image fragment is identified by:
//
// - Scaled image size
// - Scaled image fragment rectangle (IntRect)
//
// Scaled image size has been determined and the next step is to compute the
// rectangle for the scaled image fragment which needs to be an IntRect.
//
// scaledSrcRect = srcRect * (approximateScaleX, approximateScaleY)
// enclosingScaledSrcRect = enclosingIntRect(scaledSrcRect)
//
// Finally we extract the scaled image fragment using
// (scaledImageSize, enclosingScaledSrcRect).
//
SkBitmap NativeImageSkia::extractScaledImageFragment(const SkRect& srcRect, float scaleX, float scaleY, SkRect* scaledSrcRect) const
{
SkISize imageSize = SkISize::Make(bitmap().width(), bitmap().height());
SkISize scaledImageSize = SkISize::Make(clampToInteger(roundf(imageSize.width() * scaleX)),
clampToInteger(roundf(imageSize.height() * scaleY)));
SkRect imageRect = SkRect::MakeWH(imageSize.width(), imageSize.height());
SkRect scaledImageRect = SkRect::MakeWH(scaledImageSize.width(), scaledImageSize.height());
SkMatrix scaleTransform;
scaleTransform.setRectToRect(imageRect, scaledImageRect, SkMatrix::kFill_ScaleToFit);
scaleTransform.mapRect(scaledSrcRect, srcRect);
bool ok = scaledSrcRect->intersect(scaledImageRect);
ASSERT_UNUSED(ok, ok);
SkIRect enclosingScaledSrcRect = enclosingIntRect(*scaledSrcRect);
// |enclosingScaledSrcRect| can be larger than |scaledImageSize| because
// of float inaccuracy so clip to get inside.
ok = enclosingScaledSrcRect.intersect(SkIRect::MakeSize(scaledImageSize));
ASSERT_UNUSED(ok, ok);
// scaledSrcRect is relative to the pixel snapped fragment we're extracting.
scaledSrcRect->offset(-enclosingScaledSrcRect.x(), -enclosingScaledSrcRect.y());
return resizedBitmap(scaledImageSize, enclosingScaledSrcRect);
}
示例2: readPixels
bool SkPixmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels, size_t dstRB,
int x, int y) const {
if (kUnknown_SkColorType == requestedDstInfo.colorType()) {
return false;
}
if (nullptr == dstPixels || dstRB < requestedDstInfo.minRowBytes()) {
return false;
}
if (0 == requestedDstInfo.width() || 0 == requestedDstInfo.height()) {
return false;
}
SkIRect srcR = SkIRect::MakeXYWH(x, y, requestedDstInfo.width(), requestedDstInfo.height());
if (!srcR.intersect(0, 0, this->width(), this->height())) {
return false;
}
// the intersect may have shrunk info's logical size
const SkImageInfo dstInfo = requestedDstInfo.makeWH(srcR.width(), srcR.height());
// if x or y are negative, then we have to adjust pixels
if (x > 0) {
x = 0;
}
if (y > 0) {
y = 0;
}
// here x,y are either 0 or negative
dstPixels = ((char*)dstPixels - y * dstRB - x * dstInfo.bytesPerPixel());
const SkImageInfo srcInfo = this->info().makeWH(dstInfo.width(), dstInfo.height());
const void* srcPixels = this->addr(srcR.x(), srcR.y());
return SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRB,
srcInfo, srcPixels, this->rowBytes(), this->ctable());
}
示例3: asFragmentProcessor
bool SkMagnifierImageFilter::asFragmentProcessor(GrFragmentProcessor** fp,
GrProcessorDataManager* procDataManager,
GrTexture* texture, const SkMatrix&,
const SkIRect&bounds) const {
if (fp) {
SkScalar yOffset = texture->origin() == kTopLeft_GrSurfaceOrigin ? fSrcRect.y() :
texture->height() - fSrcRect.height() * texture->height() / bounds.height()
- fSrcRect.y();
int boundsY = (texture->origin() == kTopLeft_GrSurfaceOrigin) ? bounds.y() :
(texture->height() - bounds.height());
SkRect effectBounds = SkRect::MakeXYWH(
SkIntToScalar(bounds.x()) / texture->width(),
SkIntToScalar(boundsY) / texture->height(),
SkIntToScalar(texture->width()) / bounds.width(),
SkIntToScalar(texture->height()) / bounds.height());
SkScalar invInset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1;
*fp = GrMagnifierEffect::Create(procDataManager,
texture,
effectBounds,
fSrcRect.x() / texture->width(),
yOffset / texture->height(),
fSrcRect.width() / bounds.width(),
fSrcRect.height() / bounds.height(),
bounds.width() * invInset,
bounds.height() * invInset);
}
return true;
}
示例4: trim
bool SkWritePixelsRec::trim(int dstWidth, int dstHeight) {
if (nullptr == fPixels || fRowBytes < fInfo.minRowBytes()) {
return false;
}
if (0 >= fInfo.width() || 0 >= fInfo.height()) {
return false;
}
int x = fX;
int y = fY;
SkIRect dstR = SkIRect::MakeXYWH(x, y, fInfo.width(), fInfo.height());
if (!dstR.intersect(0, 0, dstWidth, dstHeight)) {
return false;
}
// if x or y are negative, then we have to adjust pixels
if (x > 0) {
x = 0;
}
if (y > 0) {
y = 0;
}
// here x,y are either 0 or negative
fPixels = ((const char*)fPixels - y * fRowBytes - x * fInfo.bytesPerPixel());
// the intersect may have shrunk info's logical size
fInfo = fInfo.makeWH(dstR.width(), dstR.height());
fX = dstR.x();
fY = dstR.y();
return true;
}
示例5: updateHandle
void updateHandle(Handle hndl, const SkMatrix& ctm, const SkIRect& clip) override {
CGContextRef cg = (CGContextRef)hndl;
CGContextRestoreGState(cg);
CGContextSaveGState(cg);
CGContextClipToRect(cg, CGRectMake(clip.x(), clip.y(), clip.width(), clip.height()));
CGContextConcatCTM(cg, matrix_to_transform(cg, ctm));
}
示例6: sizeof
// Much of readPixels is exercised by copyTo testing, since readPixels is the backend for that
// method. Here we explicitly test subset copies.
//
DEF_TEST(BitmapReadPixels, reporter) {
const int W = 4;
const int H = 4;
const size_t rowBytes = W * sizeof(SkPMColor);
const SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(W, H);
SkPMColor srcPixels[16];
fill_4x4_pixels(srcPixels);
SkBitmap srcBM;
srcBM.installPixels(srcInfo, srcPixels, rowBytes);
SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(W, H);
SkPMColor dstPixels[16];
const struct {
bool fExpectedSuccess;
SkIPoint fRequestedSrcLoc;
SkISize fRequestedDstSize;
// If fExpectedSuccess, check these, otherwise ignore
SkIPoint fExpectedDstLoc;
SkIRect fExpectedSrcR;
} gRec[] = {
{ true, { 0, 0 }, { 4, 4 }, { 0, 0 }, { 0, 0, 4, 4 } },
{ true, { 1, 1 }, { 2, 2 }, { 0, 0 }, { 1, 1, 3, 3 } },
{ true, { 2, 2 }, { 4, 4 }, { 0, 0 }, { 2, 2, 4, 4 } },
{ true, {-1,-1 }, { 2, 2 }, { 1, 1 }, { 0, 0, 1, 1 } },
{ false, {-1,-1 }, { 1, 1 }, { 0, 0 }, { 0, 0, 0, 0 } },
};
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
clear_4x4_pixels(dstPixels);
dstInfo = dstInfo.makeWH(gRec[i].fRequestedDstSize.width(),
gRec[i].fRequestedDstSize.height());
bool success = srcBM.readPixels(dstInfo, dstPixels, rowBytes,
gRec[i].fRequestedSrcLoc.x(), gRec[i].fRequestedSrcLoc.y());
REPORTER_ASSERT(reporter, gRec[i].fExpectedSuccess == success);
if (success) {
const SkIRect srcR = gRec[i].fExpectedSrcR;
const int dstX = gRec[i].fExpectedDstLoc.x();
const int dstY = gRec[i].fExpectedDstLoc.y();
// Walk the dst pixels, and check if we got what we expected
for (int y = 0; y < H; ++y) {
for (int x = 0; x < W; ++x) {
SkPMColor dstC = dstPixels[y*4+x];
// get into src coordinates
int sx = x - dstX + srcR.x();
int sy = y - dstY + srcR.y();
if (srcR.contains(sx, sy)) {
REPORTER_ASSERT(reporter, check_4x4_pixel(dstC, sx, sy));
} else {
REPORTER_ASSERT(reporter, 0 == dstC);
}
}
}
}
}
}
示例7: areBoundariesIntegerAligned
// Return true if the rectangle is aligned to integer boundaries.
// See comments for computeBitmapDrawRects() for how this is used.
static bool areBoundariesIntegerAligned(const SkRect& rect)
{
// Value is 1.19209e-007. This is the tolerance threshold.
const float epsilon = std::numeric_limits<float>::epsilon();
SkIRect roundedRect = roundedIntRect(rect);
return fabs(rect.x() - roundedRect.x()) < epsilon
&& fabs(rect.y() - roundedRect.y()) < epsilon
&& fabs(rect.right() - roundedRect.right()) < epsilon
&& fabs(rect.bottom() - roundedRect.bottom()) < epsilon;
}
示例8: make_unstretched_key
static void make_unstretched_key(GrUniqueKey* key, uint32_t imageID, const SkIRect& subset) {
SkASSERT(SkIsU16(subset.width()));
SkASSERT(SkIsU16(subset.height()));
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(key, kDomain, 4);
builder[0] = imageID;
builder[1] = subset.x();
builder[2] = subset.y();
builder[3] = subset.width() | (subset.height() << 16);
}
示例9: surface
sk_sp<SkImage> SkImage_Generator::onMakeSubset(const SkIRect& subset) const {
// TODO: make this lazy, by wrapping the subset inside a new generator or something
// For now, we do effectively what we did before, make it a raster
const SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(),
this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
auto surface(SkSurface::MakeRaster(info));
if (!surface) {
return nullptr;
}
surface->getCanvas()->clear(0);
surface->getCanvas()->drawImage(this, SkIntToScalar(-subset.x()), SkIntToScalar(-subset.y()),
nullptr);
return surface->makeImageSnapshot();
}
示例10: filterImageGPUDeprecated
bool SkBlurImageFilter::filterImageGPUDeprecated(Proxy* proxy, const SkBitmap& src,
const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
#if SK_SUPPORT_GPU
SkBitmap input = src;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (!this->filterInputGPUDeprecated(0, proxy, src, ctx, &input, &srcOffset)) {
return false;
}
SkIRect srcBounds = input.bounds();
srcBounds.offset(srcOffset);
SkIRect dstBounds;
if (!this->applyCropRect(this->mapContext(ctx), srcBounds, &dstBounds)) {
return false;
}
if (!srcBounds.intersect(dstBounds)) {
return false;
}
SkVector sigma = map_sigma(fSigma, ctx.ctm());
if (sigma.x() == 0 && sigma.y() == 0) {
input.extractSubset(result, srcBounds);
offset->fX = srcBounds.x();
offset->fY = srcBounds.y();
return true;
}
offset->fX = dstBounds.fLeft;
offset->fY = dstBounds.fTop;
srcBounds.offset(-srcOffset);
dstBounds.offset(-srcOffset);
SkRect srcBoundsF(SkRect::Make(srcBounds));
GrTexture* inputTexture = input.getTexture();
SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(inputTexture->getContext(),
inputTexture,
false,
SkRect::Make(dstBounds),
&srcBoundsF,
sigma.x(),
sigma.y()));
if (!tex) {
return false;
}
GrWrapTextureInBitmap(tex, dstBounds.width(), dstBounds.height(), false, result);
return true;
#else
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
#endif
}
示例11: fInnerThreshold
GrAlphaThresholdFragmentProcessor::GrAlphaThresholdFragmentProcessor(GrTexture* texture,
GrTexture* maskTexture,
float innerThreshold,
float outerThreshold,
const SkIRect& bounds)
: fInnerThreshold(innerThreshold)
, fOuterThreshold(outerThreshold)
, fImageCoordTransform(kLocal_GrCoordSet,
GrCoordTransform::MakeDivByTextureWHMatrix(texture), texture,
GrTextureParams::kNone_FilterMode)
, fImageTextureAccess(texture)
, fMaskCoordTransform(kLocal_GrCoordSet,
make_div_and_translate_matrix(maskTexture, -bounds.x(), -bounds.y()),
maskTexture,
GrTextureParams::kNone_FilterMode)
, fMaskTextureAccess(maskTexture) {
this->initClassID<GrAlphaThresholdFragmentProcessor>();
this->addCoordTransform(&fImageCoordTransform);
this->addTextureAccess(&fImageTextureAccess);
this->addCoordTransform(&fMaskCoordTransform);
this->addTextureAccess(&fMaskTextureAccess);
}
示例12: onApplyFilter
SkImage* SkImage_Base::onApplyFilter(SkImageFilter* filter, SkIPoint* offsetResult,
bool forceResultToOriginalSize) const {
SkBitmap src;
if (!this->getROPixels(&src)) {
return nullptr;
}
const SkIRect srcBounds = SkIRect::MakeWH(this->width(), this->height());
if (forceResultToOriginalSize) {
const SkIRect clipBounds = srcBounds;
SkRasterImageFilterProxy proxy;
SkImageFilter::Context ctx(SkMatrix::I(), clipBounds, SkImageFilter::Cache::Get(),
SkImageFilter::kExact_SizeConstraint);
SkBitmap dst;
if (filter->filterImage(&proxy, src, ctx, &dst, offsetResult)) {
dst.setImmutable();
return SkImage::NewFromBitmap(dst);
}
} else {
const SkIRect dstR = compute_fast_ibounds(filter, srcBounds);
SkImageInfo info = SkImageInfo::MakeN32Premul(dstR.width(), dstR.height());
SkAutoTUnref<SkSurface> surface(this->onNewSurface(info));
SkPaint paint;
paint.setImageFilter(filter);
surface->getCanvas()->drawImage(this, SkIntToScalar(-dstR.x()), SkIntToScalar(-dstR.y()),
&paint);
offsetResult->set(dstR.x(), dstR.y());
return surface->newImageSnapshot();
}
return nullptr;
}
示例13: onDecodeRegion
bool SkJPEGImageDecoder::onDecodeRegion(SkBitmap* bm, SkIRect region) {
if (index == NULL) {
return false;
}
jpeg_decompress_struct *cinfo = index->cinfo;
SkIRect rect = SkIRect::MakeWH(this->imageWidth, this->imageHeight);
if (!rect.intersect(region)) {
// If the requested region is entirely outsides the image, just
// returns false
return false;
}
SkAutoMalloc srcStorage;
skjpeg_error_mgr sk_err;
cinfo->err = jpeg_std_error(&sk_err);
sk_err.error_exit = skjpeg_error_exit;
if (setjmp(sk_err.fJmpBuf)) {
return false;
}
int requestedSampleSize = this->getSampleSize();
cinfo->scale_denom = requestedSampleSize;
if (this->getPreferQualityOverSpeed()) {
cinfo->dct_method = JDCT_ISLOW;
} else {
cinfo->dct_method = JDCT_IFAST;
}
SkBitmap::Config config = this->getPrefConfig(k32Bit_SrcDepth, false);
if (config != SkBitmap::kARGB_8888_Config &&
config != SkBitmap::kARGB_4444_Config &&
config != SkBitmap::kRGB_565_Config) {
config = SkBitmap::kARGB_8888_Config;
}
/* default format is RGB */
cinfo->out_color_space = JCS_RGB;
#ifdef ANDROID_RGB
cinfo->dither_mode = JDITHER_NONE;
if (config == SkBitmap::kARGB_8888_Config) {
cinfo->out_color_space = JCS_RGBA_8888;
} else if (config == SkBitmap::kRGB_565_Config) {
cinfo->out_color_space = JCS_RGB_565;
if (this->getDitherImage()) {
cinfo->dither_mode = JDITHER_ORDERED;
}
}
#endif
int startX = rect.fLeft;
int startY = rect.fTop;
int width = rect.width();
int height = rect.height();
jpeg_init_read_tile_scanline(cinfo, index->index,
&startX, &startY, &width, &height);
int skiaSampleSize = recompute_sampleSize(requestedSampleSize, *cinfo);
int actualSampleSize = skiaSampleSize * (DCTSIZE / cinfo->min_DCT_scaled_size);
SkBitmap *bitmap = new SkBitmap;
SkAutoTDelete<SkBitmap> adb(bitmap);
#ifdef ANDROID_RGB
/* short-circuit the SkScaledBitmapSampler when possible, as this gives
a significant performance boost.
*/
if (skiaSampleSize == 1 &&
((config == SkBitmap::kARGB_8888_Config &&
cinfo->out_color_space == JCS_RGBA_8888) ||
(config == SkBitmap::kRGB_565_Config &&
cinfo->out_color_space == JCS_RGB_565)))
{
bitmap->setConfig(config, cinfo->output_width, height);
bitmap->setIsOpaque(true);
// Check ahead of time if the swap(dest, src) is possible or not.
// If yes, then we will stick to AllocPixelRef since it's cheaper
// with the swap happening. If no, then we will use alloc to allocate
// pixels to prevent garbage collection.
//
// Not using a recycled-bitmap and the output rect is same as the
// decoded region.
int w = rect.width() / actualSampleSize;
int h = rect.height() / actualSampleSize;
bool swapOnly = (rect == region) && bm->isNull() &&
(w == bitmap->width()) && (h == bitmap->height()) &&
((startX - rect.x()) / actualSampleSize == 0) &&
((startY - rect.y()) / actualSampleSize == 0);
if (swapOnly) {
if (!this->allocPixelRef(bitmap, NULL)) {
return return_false(*cinfo, *bitmap, "allocPixelRef");
}
} else {
if (!bitmap->allocPixels()) {
return return_false(*cinfo, *bitmap, "allocPixels");
}
}
SkAutoLockPixels alp(*bitmap);
JSAMPLE* rowptr = (JSAMPLE*)bitmap->getPixels();
//.........这里部分代码省略.........
示例14: filterImageGPU
bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
SkBitmap colorBM = src;
SkIPoint colorOffset = SkIPoint::Make(0, 0);
if (getColorInput() && !getColorInput()->getInputResultGPU(proxy, src, ctx, &colorBM,
&colorOffset)) {
return false;
}
SkBitmap displacementBM = src;
SkIPoint displacementOffset = SkIPoint::Make(0, 0);
if (getDisplacementInput() &&
!getDisplacementInput()->getInputResultGPU(proxy, src, ctx, &displacementBM,
&displacementOffset)) {
return false;
}
SkIRect bounds;
// Since GrDisplacementMapEffect does bounds checking on color pixel access, we don't need to
// pad the color bitmap to bounds here.
if (!this->applyCropRect(ctx, colorBM, colorOffset, &bounds)) {
return false;
}
SkIRect displBounds;
if (!this->applyCropRect(ctx, proxy, displacementBM,
&displacementOffset, &displBounds, &displacementBM)) {
return false;
}
if (!bounds.intersect(displBounds)) {
return false;
}
GrTexture* color = colorBM.getTexture();
GrTexture* displacement = displacementBM.getTexture();
GrContext* context = color->getContext();
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = bounds.width();
desc.fHeight = bounds.height();
desc.fConfig = kSkia8888_GrPixelConfig;
SkAutoTUnref<GrTexture> dst(
context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch));
if (!dst) {
return false;
}
SkVector scale = SkVector::Make(fScale, fScale);
ctx.ctm().mapVectors(&scale, 1);
GrPaint paint;
SkMatrix offsetMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(displacement);
offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displacementOffset.fX),
SkIntToScalar(colorOffset.fY - displacementOffset.fY));
paint.addColorProcessor(
GrDisplacementMapEffect::Create(fXChannelSelector,
fYChannelSelector,
scale,
displacement,
offsetMatrix,
color,
colorBM.dimensions()))->unref();
SkIRect colorBounds = bounds;
colorBounds.offset(-colorOffset);
SkMatrix matrix;
matrix.setTranslate(-SkIntToScalar(colorBounds.x()),
-SkIntToScalar(colorBounds.y()));
context->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, matrix,
SkRect::Make(colorBounds));
offset->fX = bounds.left();
offset->fY = bounds.top();
WrapTexture(dst, bounds.width(), bounds.height(), result);
return true;
}
示例15: MakeFromGpu
sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* source,
const Context& ctx,
SkIPoint* offset) const {
SkIPoint colorOffset = SkIPoint::Make(0, 0);
sk_sp<SkSpecialImage> color(this->filterInput(1, source, ctx, &colorOffset));
if (!color) {
return nullptr;
}
SkIPoint displOffset = SkIPoint::Make(0, 0);
sk_sp<SkSpecialImage> displ(this->filterInput(0, source, ctx, &displOffset));
if (!displ) {
return nullptr;
}
const SkIRect srcBounds = SkIRect::MakeXYWH(colorOffset.x(), colorOffset.y(),
color->width(), color->height());
// Both paths do bounds checking on color pixel access, we don't need to
// pad the color bitmap to bounds here.
SkIRect bounds;
if (!this->applyCropRect(ctx, srcBounds, &bounds)) {
return nullptr;
}
SkIRect displBounds;
displ = this->applyCropRect(ctx, displ.get(), &displOffset, &displBounds);
if (!displ) {
return nullptr;
}
if (!bounds.intersect(displBounds)) {
return nullptr;
}
const SkIRect colorBounds = bounds.makeOffset(-colorOffset.x(), -colorOffset.y());
SkVector scale = SkVector::Make(fScale, fScale);
ctx.ctm().mapVectors(&scale, 1);
#if SK_SUPPORT_GPU
if (source->isTextureBacked()) {
GrContext* context = source->getContext();
sk_sp<GrTexture> colorTexture(color->asTextureRef(context));
sk_sp<GrTexture> displTexture(displ->asTextureRef(context));
if (!colorTexture || !displTexture) {
return nullptr;
}
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = bounds.width();
desc.fHeight = bounds.height();
desc.fConfig = kSkia8888_GrPixelConfig;
SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(desc));
if (!dst) {
return nullptr;
}
GrPaint paint;
SkMatrix offsetMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(displTexture.get());
offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displOffset.fX),
SkIntToScalar(colorOffset.fY - displOffset.fY));
paint.addColorFragmentProcessor(
GrDisplacementMapEffect::Create(fXChannelSelector,
fYChannelSelector,
scale,
displTexture.get(),
offsetMatrix,
colorTexture.get(),
SkISize::Make(color->width(),
color->height())))->unref();
paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
SkMatrix matrix;
matrix.setTranslate(-SkIntToScalar(colorBounds.x()), -SkIntToScalar(colorBounds.y()));
SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTarget()));
if (!drawContext) {
return nullptr;
}
drawContext->drawRect(GrClip::WideOpen(), paint, matrix, SkRect::Make(colorBounds));
offset->fX = bounds.left();
offset->fY = bounds.top();
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()),
kNeedNewImageUniqueID_SpecialImage,
dst);
}
#endif
SkBitmap colorBM, displBM;
if (!color->getROPixels(&colorBM) || !displ->getROPixels(&displBM)) {
return nullptr;
}
//.........这里部分代码省略.........