本文整理汇总了C++中GrContext::createUncachedTexture方法的典型用法代码示例。如果您正苦于以下问题:C++ GrContext::createUncachedTexture方法的具体用法?C++ GrContext::createUncachedTexture怎么用?C++ GrContext::createUncachedTexture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrContext
的用法示例。
在下文中一共展示了GrContext::createUncachedTexture方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testOne
void TestResult::testOne() {
sk_sp<SkPicture> pic;
{
SkString d;
d.printf(" {%d, \"%s\"},", fDirNo, fFilename);
SkString path = make_filepath(fDirNo, IN_DIR, fFilename);
SkFILEStream stream(path.c_str());
if (!stream.isValid()) {
SkDebugf("invalid stream %s\n", path.c_str());
goto finish;
}
if (fTestStep == kEncodeFiles) {
size_t length = stream.getLength();
SkTArray<char, true> bytes;
bytes.push_back_n(length);
stream.read(&bytes[0], length);
stream.rewind();
SkString wPath = make_filepath(0, outSkpDir, fFilename);
SkFILEWStream wStream(wPath.c_str());
wStream.write(&bytes[0], length);
wStream.flush();
}
pic = SkPicture::MakeFromStream(&stream);
if (!pic) {
SkDebugf("unable to decode %s\n", fFilename);
goto finish;
}
int pWidth = pic->width();
int pHeight = pic->height();
int pLargerWH = SkTMax(pWidth, pHeight);
GrContextFactory contextFactory;
#ifdef SK_BUILD_FOR_WIN
GrContext* context = contextFactory.get(kAngle);
#else
GrContext* context = contextFactory.get(kNative);
#endif
if (nullptr == context) {
SkDebugf("unable to allocate context for %s\n", fFilename);
goto finish;
}
int maxWH = context->getMaxRenderTargetSize();
int scale = 1;
while (pLargerWH / scale > maxWH) {
scale *= 2;
}
SkBitmap bitmap;
SkIPoint dim;
do {
dim.fX = (pWidth + scale - 1) / scale;
dim.fY = (pHeight + scale - 1) / scale;
bool success = bitmap.allocN32Pixels(dim.fX, dim.fY);
if (success) {
break;
}
SkDebugf("-%d-", scale);
} while ((scale *= 2) < 256);
if (scale >= 256) {
SkDebugf("unable to allocate bitmap for %s (w=%d h=%d) (sw=%d sh=%d)\n",
fFilename, pWidth, pHeight, dim.fX, dim.fY);
return;
}
SkCanvas skCanvas(bitmap);
drawPict(pic, &skCanvas, fScaleOversized ? scale : 1);
GrTextureDesc desc;
desc.fConfig = kRGBA_8888_GrPixelConfig;
desc.fFlags = kRenderTarget_GrTextureFlagBit;
desc.fWidth = dim.fX;
desc.fHeight = dim.fY;
desc.fSampleCnt = 0;
sk_sp<GrTexture> texture(context->createUncachedTexture(desc, nullptr, 0));
if (!texture) {
SkDebugf("unable to allocate texture for %s (w=%d h=%d)\n", fFilename,
dim.fX, dim.fY);
return;
}
SkGpuDevice grDevice(context, texture.get());
SkCanvas grCanvas(&grDevice);
drawPict(pic.get(), &grCanvas, fScaleOversized ? scale : 1);
SkBitmap grBitmap;
grBitmap.allocPixels(grCanvas.imageInfo());
grCanvas.readPixels(&grBitmap, 0, 0);
if (fTestStep == kCompareBits) {
fPixelError = similarBits(grBitmap, bitmap);
SkMSec skTime = timePict(pic, &skCanvas);
SkMSec grTime = timePict(pic, &grCanvas);
fTime = skTime - grTime;
} else if (fTestStep == kEncodeFiles) {
SkString pngStr = make_png_name(fFilename);
const char* pngName = pngStr.c_str();
writePict(grBitmap, outGrDir, pngName);
writePict(bitmap, outSkDir, pngName);
}
}
}
示例2: canvas
DEF_GPUTEST(ReadWriteAlpha, reporter, factory) {
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
if (!GrContextFactory::IsRenderingGLContext(glType)) {
continue;
}
GrContext* context = factory->get(glType);
if (NULL == context) {
continue;
}
unsigned char textureData[X_SIZE][Y_SIZE];
memset(textureData, 0, X_SIZE * Y_SIZE);
GrTextureDesc desc;
// let Skia know we will be using this texture as a render target
desc.fFlags = kRenderTarget_GrTextureFlagBit;
// it is a single channel texture
desc.fConfig = kAlpha_8_GrPixelConfig;
desc.fWidth = X_SIZE;
desc.fHeight = Y_SIZE;
// We are initializing the texture with zeros here
GrTexture* texture = context->createUncachedTexture(desc, textureData, 0);
if (!texture) {
return;
}
SkAutoTUnref<GrTexture> au(texture);
// create a distinctive texture
for (int y = 0; y < Y_SIZE; ++y) {
for (int x = 0; x < X_SIZE; ++x) {
textureData[x][y] = x*Y_SIZE+y;
}
}
// upload the texture
texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
textureData, 0);
unsigned char readback[X_SIZE][Y_SIZE];
// clear readback to something non-zero so we can detect readback failures
memset(readback, 0x1, X_SIZE * Y_SIZE);
// read the texture back
texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
readback, 0);
// make sure the original & read back versions match
bool match = true;
for (int y = 0; y < Y_SIZE; ++y) {
for (int x = 0; x < X_SIZE; ++x) {
if (textureData[x][y] != readback[x][y]) {
match = false;
}
}
}
REPORTER_ASSERT(reporter, match);
// Now try writing on the single channel texture
SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create(texture->asRenderTarget(),
SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)));
SkCanvas canvas(device);
SkPaint paint;
const SkRect rect = SkRect::MakeLTRB(-10, -10, X_SIZE + 10, Y_SIZE + 10);
paint.setColor(SK_ColorWHITE);
canvas.drawRect(rect, paint);
texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
readback, 0);
match = true;
for (int y = 0; y < Y_SIZE; ++y) {
for (int x = 0; x < X_SIZE; ++x) {
if (0xFF != readback[x][y]) {
match = false;
}
}
}
REPORTER_ASSERT(reporter, match);
}
}
示例3: onDraw
virtual void onDraw(SkCanvas* canvas) {
SkDevice* device = canvas->getDevice();
GrRenderTarget* target = (GrRenderTarget*) device->accessRenderTarget();
GrContext* ctx = GetGr();
if (ctx && target) {
SkPMColor gTextureData[(2 * S) * (2 * S)];
static const int stride = 2 * S;
static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40);
static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff);
static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00);
static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80);
static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00);
static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00);
for (int i = 0; i < 2; ++i) {
int offset = 0;
// fill upper-left
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = gray;
}
}
// fill upper-right
offset = S;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = white;
}
}
// fill lower left
offset = S * stride;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = black;
}
}
// fill lower right
offset = S * stride + S;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = gray;
}
}
GrTextureDesc desc;
desc.fAALevel = kNone_GrAALevel;
// use RT flag bit because in GL it makes the texture be bottom-up
desc.fFlags = i ? kRenderTarget_GrTextureFlagBit :
kNone_GrTextureFlags;
desc.fConfig = kSkia8888_PM_GrPixelConfig;
desc.fWidth = 2 * S;
desc.fHeight = 2 * S;
GrTexture* texture =
ctx->createUncachedTexture(desc, gTextureData, 0);
if (!texture) {
return;
}
GrAutoUnref au(texture);
ctx->setClip(GrRect::MakeWH(2*S, 2*S));
ctx->setRenderTarget(target);
GrPaint paint;
paint.reset();
paint.fColor = 0xffffffff;
paint.fSrcBlendCoeff = kOne_BlendCoeff;
paint.fDstBlendCoeff = kISA_BlendCoeff;
GrMatrix vm;
if (i) {
vm.setRotate(90 * SK_Scalar1,
S * SK_Scalar1,
S * SK_Scalar1);
} else {
vm.reset();
}
ctx->setMatrix(vm);
GrMatrix tm;
tm = vm;
GrMatrix* sampleMat = paint.textureSampler(0)->matrix();
*sampleMat = vm;
sampleMat->postIDiv(2*S, 2*S);
paint.setTexture(0, texture);
ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S));
// now update the lower right of the texture in first pass
// or upper right in second pass
offset = 0;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] =
((x + y) % 2) ? (i ? green : red) : blue;
}
}
texture->writePixels(S, (i ? 0 : S), S, S,
texture->config(), gTextureData,
4 * stride);
ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S));
}
}
//.........这里部分代码省略.........
示例4: render_page
static bool render_page(const SkString& outputDir,
const SkString& inputFilename,
const SkPdfRenderer& renderer,
int page) {
SkRect rect = renderer.MediaBox(page < 0 ? 0 :page);
// Exercise all pdf codepaths as in normal rendering, but no actual bits are changed.
if (!FLAGS_config.isEmpty() && strcmp(FLAGS_config[0], "nul") == 0) {
SkBitmap bitmap;
SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap)));
SkNulCanvas canvas(device);
renderer.renderPage(page < 0 ? 0 : page, &canvas, rect);
} else {
// 8888
SkRect rect = renderer.MediaBox(page < 0 ? 0 :page);
SkBitmap bitmap;
SkScalar width = SkScalarMul(rect.width(), SkDoubleToScalar(FLAGS_DPI / 72.0));
SkScalar height = SkScalarMul(rect.height(), SkDoubleToScalar(FLAGS_DPI / 72.0));
rect = SkRect::MakeWH(width, height);
SkColor background = FLAGS_transparentBackground ? SK_ColorTRANSPARENT : SK_ColorWHITE;
#ifdef PDF_DEBUG_3X
setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(width), 3 * (int)SkScalarToDouble(height),
background);
#else
setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDouble(height),
background);
#endif
SkAutoTUnref<SkBaseDevice> device;
if (strcmp(FLAGS_config[0], "8888") == 0) {
device.reset(SkNEW_ARGS(SkBitmapDevice, (bitmap)));
}
#if SK_SUPPORT_GPU
else if (strcmp(FLAGS_config[0], "gpu") == 0) {
SkAutoTUnref<GrSurface> target;
GrContext* gr = gContextFactory.get(GrContextFactory::kNative_GLContextType);
if (gr) {
// create a render target to back the device
GrTextureDesc desc;
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fFlags = kRenderTarget_GrTextureFlagBit;
desc.fWidth = SkScalarCeilToInt(width);
desc.fHeight = SkScalarCeilToInt(height);
desc.fSampleCnt = 0;
target.reset(gr->createUncachedTexture(desc, NULL, 0));
}
if (NULL == target.get()) {
SkASSERT(0);
return false;
}
device.reset(SkGpuDevice::Create(target));
}
#endif
else {
SkDebugf("unknown --config: %s\n", FLAGS_config[0]);
return false;
}
SkCanvas canvas(device);
#ifdef PDF_TRACE_DIFF_IN_PNG
gDumpBitmap = &bitmap;
gDumpCanvas = &canvas;
#endif
renderer.renderPage(page < 0 ? 0 : page, &canvas, rect);
SkString outputPath;
if (!make_output_filepath(&outputPath, outputDir, inputFilename, page)) {
return false;
}
SkImageEncoder::EncodeFile(outputPath.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100);
if (FLAGS_showMemoryUsage) {
SkDebugf("Memory usage after page %i rendered: %u\n",
page < 0 ? 0 : page, (unsigned int)renderer.bytesUsed());
}
}
return true;
}