本文整理汇总了C++中SkTLazy::getMaybeNull方法的典型用法代码示例。如果您正苦于以下问题:C++ SkTLazy::getMaybeNull方法的具体用法?C++ SkTLazy::getMaybeNull怎么用?C++ SkTLazy::getMaybeNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkTLazy
的用法示例。
在下文中一共展示了SkTLazy::getMaybeNull方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onGenerateTexture
GrTexture* SkPictureImageGenerator::onGenerateTexture(GrContext* ctx, SkImageUsageType usage,
const SkIRect* subset) {
const SkImageInfo& info = this->getInfo();
SkImageInfo surfaceInfo = subset ? info.makeWH(subset->width(), subset->height()) : info;
//
// TODO: respect the usage, by possibly creating a different (pow2) surface
//
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx,
SkSurface::kYes_Budgeted,
surfaceInfo));
if (!surface.get()) {
return nullptr;
}
SkMatrix matrix = fMatrix;
if (subset) {
matrix.postTranslate(-subset->x(), -subset->y());
}
surface->getCanvas()->clear(0); // does NewRenderTarget promise to do this for us?
surface->getCanvas()->drawPicture(fPicture, &matrix, fPaint.getMaybeNull());
SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
if (!image.get()) {
return nullptr;
}
return SkSafeRef(image->getTexture());
}
示例2: saveLayerAlpha
int SkiaCanvas::saveLayerAlpha(float left, float top, float right, float bottom,
int alpha, SaveFlags::Flags flags) {
SkTLazy<SkPaint> alphaPaint;
if (static_cast<unsigned>(alpha) < 0xFF) {
alphaPaint.init()->setAlpha(alpha);
}
return this->saveLayer(left, top, right, bottom, alphaPaint.getMaybeNull(),
flags);
}
示例3: onGetPixels
bool SkPictureImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
SkPMColor ctable[], int* ctableCount) {
if (info != getInfo() || ctable || ctableCount) {
return false;
}
SkBitmap bitmap;
if (!bitmap.installPixels(info, pixels, rowBytes)) {
return false;
}
bitmap.eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry));
canvas.drawPicture(fPicture, &fMatrix, fPaint.getMaybeNull());
return true;
}
示例4: onGenerateScaledPixels
bool SkPictureImageGenerator::onGenerateScaledPixels(const SkISize& scaledSize,
const SkIPoint& scaledOrigin,
const SkPixmap& scaledPixels) {
int w = scaledSize.width();
int h = scaledSize.height();
const SkScalar scaleX = SkIntToScalar(w) / this->getInfo().width();
const SkScalar scaleY = SkIntToScalar(h) / this->getInfo().height();
SkMatrix matrix = SkMatrix::MakeScale(scaleX, scaleY);
matrix.postTranslate(-SkIntToScalar(scaledOrigin.x()), -SkIntToScalar(scaledOrigin.y()));
SkBitmap bitmap;
if (!bitmap.installPixels(scaledPixels)) {
return false;
}
bitmap.eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry));
matrix.preConcat(fMatrix);
canvas.drawPicture(fPicture, &matrix, fPaint.getMaybeNull());
return true;
}
示例5: onDrawRect
void GrDrawTarget::onDrawRect(const SkRect& rect,
const SkMatrix* matrix,
const SkRect* localRect,
const SkMatrix* localMatrix) {
GrDrawState::AutoViewMatrixRestore avmr;
if (NULL != matrix) {
avmr.set(this->drawState(), *matrix);
}
set_vertex_attributes(this->drawState(), NULL != localRect);
AutoReleaseGeometry geo(this, 4, 0);
if (!geo.succeeded()) {
GrPrintf("Failed to get space for vertices!\n");
return;
}
size_t vsize = this->drawState()->getVertexSize();
geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize);
if (NULL != localRect) {
GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) +
sizeof(GrPoint));
coords->setRectFan(localRect->fLeft, localRect->fTop,
localRect->fRight, localRect->fBottom,
vsize);
if (NULL != localMatrix) {
localMatrix->mapPointsWithStride(coords, vsize, 4);
}
}
SkTLazy<SkRect> bounds;
if (this->getDrawState().willEffectReadDstColor()) {
bounds.init();
this->getDrawState().getViewMatrix().mapRect(bounds.get(), rect);
}
this->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4, bounds.getMaybeNull());
}
示例6: openLibResult
DEF_TEST(CanvasState_test_complex_layers, reporter) {
const int WIDTH = 400;
const int HEIGHT = 400;
const int SPACER = 10;
SkRect rect = SkRect::MakeXYWH(SkIntToScalar(SPACER), SkIntToScalar(SPACER),
SkIntToScalar(WIDTH-(2*SPACER)),
SkIntToScalar((HEIGHT-(2*SPACER)) / 7));
const SkColorType colorTypes[] = {
kRGB_565_SkColorType, kN32_SkColorType
};
const int layerAlpha[] = { 255, 255, 0 };
const SkCanvas::SaveLayerFlags flags[] = {
static_cast<SkCanvas::SaveLayerFlags>(SkCanvas::kDontClipToLayer_Legacy_SaveLayerFlag),
0,
static_cast<SkCanvas::SaveLayerFlags>(SkCanvas::kDontClipToLayer_Legacy_SaveLayerFlag),
};
REPORTER_ASSERT(reporter, sizeof(layerAlpha) == sizeof(flags));
bool (*drawFn)(SkCanvasState* state, float l, float t,
float r, float b, int32_t s);
OpenLibResult openLibResult(reporter);
if (openLibResult.handle() != nullptr) {
*(void**) (&drawFn) = dlsym(openLibResult.handle(),
"complex_layers_draw_from_canvas_state");
} else {
drawFn = complex_layers_draw_from_canvas_state;
}
REPORTER_ASSERT(reporter, drawFn);
if (!drawFn) {
return;
}
for (size_t i = 0; i < SK_ARRAY_COUNT(colorTypes); ++i) {
SkBitmap bitmaps[2];
for (int j = 0; j < 2; ++j) {
bitmaps[j].allocPixels(SkImageInfo::Make(WIDTH, HEIGHT,
colorTypes[i],
kPremul_SkAlphaType));
SkCanvas canvas(bitmaps[j]);
canvas.drawColor(SK_ColorRED);
for (size_t k = 0; k < SK_ARRAY_COUNT(layerAlpha); ++k) {
SkTLazy<SkPaint> paint;
if (layerAlpha[k] != 0xFF) {
paint.init()->setAlpha(layerAlpha[k]);
}
// draw a rect within the layer's bounds and again outside the layer's bounds
canvas.saveLayer(SkCanvas::SaveLayerRec(&rect, paint.getMaybeNull(), flags[k]));
if (j) {
// Capture from the first Skia.
SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas);
REPORTER_ASSERT(reporter, state);
// And draw to it in the second Skia.
bool success = complex_layers_draw_from_canvas_state(state,
rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, SPACER);
REPORTER_ASSERT(reporter, success);
// And release it in the *first* Skia.
SkCanvasStateUtils::ReleaseCanvasState(state);
} else {
// Draw in the first Skia.
complex_layers_draw(&canvas, rect.fLeft, rect.fTop,
rect.fRight, rect.fBottom, SPACER);
}
canvas.restore();
// translate the canvas for the next iteration
canvas.translate(0, 2*(rect.height() + SPACER));
}
}
// now we memcmp the two bitmaps
REPORTER_ASSERT(reporter, bitmaps[0].getSize() == bitmaps[1].getSize());
REPORTER_ASSERT(reporter, !memcmp(bitmaps[0].getPixels(),
bitmaps[1].getPixels(),
bitmaps[0].getSize()));
}
}