SkCanvas* Request::getCanvas() { GrContextFactory* factory = fContextFactory; SkGLContext* gl = factory->getContextInfo(GrContextFactory::kNative_GLContextType, GrContextFactory::kNone_GLContextOptions).fGLContext; gl->makeCurrent(); SkASSERT(fDebugCanvas); SkCanvas* target = fSurface->getCanvas(); return target; }
DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_newTextureImage, reporter, context, glContext) { GrContextFactory otherFactory; GrContextFactory::ContextInfo otherContextInfo = otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType); glContext->makeCurrent(); std::function<SkImage*()> imageFactories[] = { create_image, create_codec_image, create_data_image, // Create an image from a picture. create_picture_image, // Create a texture image. [context] { return create_gpu_image(context); }, // Create a texture image in a another GrContext. [glContext, otherContextInfo] { otherContextInfo.fGLContext->makeCurrent(); SkImage* otherContextImage = create_gpu_image(otherContextInfo.fGrContext); glContext->makeCurrent(); return otherContextImage; } }; for (auto factory : imageFactories) { SkAutoTUnref<SkImage> image(factory()); if (!image) { ERRORF(reporter, "Error creating image."); continue; } GrTexture* origTexture = as_IB(image)->peekTexture(); SkAutoTUnref<SkImage> texImage(image->newTextureImage(context)); if (!texImage) { // We execpt to fail if image comes from a different GrContext. if (!origTexture || origTexture->getContext() == context) { ERRORF(reporter, "newTextureImage failed."); } continue; } GrTexture* copyTexture = as_IB(texImage)->peekTexture(); if (!copyTexture) { ERRORF(reporter, "newTextureImage returned non-texture image."); continue; } if (origTexture) { if (origTexture != copyTexture) { ERRORF(reporter, "newTextureImage made unnecessary texture copy."); } } if (image->width() != texImage->width() || image->height() != texImage->height()) { ERRORF(reporter, "newTextureImage changed the image size."); } if (image->isOpaque() != texImage->isOpaque()) { ERRORF(reporter, "newTextureImage changed image opaqueness."); } } }
SkCanvas* Request::getCanvas() { #if SK_SUPPORT_GPU GrContextFactory* factory = fContextFactory; GLTestContext* gl = factory->getContextInfo(GrContextFactory::kNativeGL_ContextType, GrContextFactory::kNone_ContextOptions).glContext(); if (!gl) { gl = factory->getContextInfo(GrContextFactory::kMESA_ContextType, GrContextFactory::kNone_ContextOptions).glContext(); } if (gl) { gl->makeCurrent(); } #endif SkASSERT(fDebugCanvas); // create the appropriate surface if necessary if (!fSurface) { this->enableGPU(fGPUEnabled); } SkCanvas* target = fSurface->getCanvas(); return target; }