#include "include/core/SkBitmap.h" #include "include/core/SkCanvas.h" #include "include/gpu/GrContext.h" #include "include/gpu/GrTexture.h" ... // Assume that we have loaded an image file into a SkBitmap object SkBitmap bitmap; ... // Create a GrTexture from the bitmap GrContext* context = ...; // Initialize a GrContext object GrTexture* texture = context->textureProvider()->createTexture(bitmap, GrTextureType::k2D, GrMipMapped::kNo, GrRenderable::kNo, GrProtected::kNo);
// Assume that we have a SkCanvas object SkCanvas* canvas = ...; // Assume that we have a GrTexture object GrTexture* texture = ...; // Create a SkPaint object with the GrTexture as its shader SkPaint paint; paint.setShader(texture->asShader()); // Draw a rectangle using the paint object canvas->drawRect(SkRect::MakeLTRB(0, 0, 100, 100), paint);In this example, we create a SkPaint object with the GrTexture object as its shader, and use it to fill a rectangle shape in a SkCanvas object. Package library: Skia Graphics Library.