aboutsummaryrefslogtreecommitdiffhomepage
path: root/site
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2016-11-28 16:34:06 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-29 18:02:16 +0000
commitfc74ec7c7ade8f1c5566138a7b70baae112d535c (patch)
tree2fd2b7d876a08af8014a524f2561aeab6defd0b6 /site
parent56b50792531c956be3e0c472b098255c62c7e755 (diff)
Fix documents for creating a GPU surface.
NOTRY=true DOCS_PREVIEW= https://skia.org/?cl=5284 Change-Id: I9ca559576d9e7fdff612cfe79628303bc7677bd7 Reviewed-on: https://skia-review.googlesource.com/5284 Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'site')
-rw-r--r--site/user/api/canvas.md36
1 files changed, 22 insertions, 14 deletions
diff --git a/site/user/api/canvas.md b/site/user/api/canvas.md
index afeb68514f..1b60ec51b6 100644
--- a/site/user/api/canvas.md
+++ b/site/user/api/canvas.md
@@ -7,7 +7,7 @@ Skia has multiple backends which receive SkCanvas drawing commands,
including:
- [Raster](#raster) - CPU-only.
-- [Ganesh](#ganesh) - Skia's GPU-accelerated backend.
+- [GPU](#gpu) - Skia's GPU-accelerated backend.
- [SkPDF](#skpdf) - PDF document creation.
- [SkPicture](#skpicture) - Skia's display list format.
- [NullCanvas](#nullcanvas) - Useful for testing only.
@@ -68,26 +68,34 @@ explicitly, instead of asking Skia to manage it.
return std::move(pixelMemory);
}
-<span id="ganesh"></span>
-Ganesh
+<span id="gpu"></span>
+GPU
------
-Ganesh Surfaces must have a `GrContext` object which manages the
-GPU context, and related caches for textures and fonts. In this
-example, we use a `GrContextFactory` to create a context.
+GPU Surfaces must have a `GrContext` object which manages the
+GPU context, and related caches for textures and fonts. GrContexts
+are matched one to one with OpenGL contexts or Vulkan devices. That is, all
+SkSurfaces that will be rendered to using the same OpenGL context or Vulkan
+device should share a GrContext. Skia does not create a OpenGL context or Vulkan
+device for you. In OpenGL mode it also assumes that the correct OpenGL context
+has been made current to the current thread when Skia calls are made.
<!--?prettify lang=cc?-->
-
- #include "GrContextFactory.h"
+ #include "GrContext.h"
+ #include "gl/GrGLInterface.h"
#include "SkData.h"
#include "SkImage.h"
#include "SkStream.h"
#include "SkSurface.h"
- void ganesh(int width, int height,
- void(*draw)(SkCanvas*),
- const char* path) {
- GrContextFactory grFactory;
- GrContext* context = grFactory.get(GrContextFactory::kNative_GLContextType);
+
+ void gl_example(int width, int height, void(*draw)(SkCanvas*), const char* path) {
+ // You've already created your OpenGL context and bound it.
+ const GrGLInterface* interface = nullptr;
+ // Leaving interface as null makes Skia extract pointers to OpenGL functions for the current
+ // context in a platform-specific way. Alternatively, you may create your own GrGLInterface and
+ // initialize it however you like to attach to an alternate OpenGL implementation or intercept
+ // Skia's OpenGL calls.
+ GrContext* context = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) interface);
SkImageInfo info = SkImageInfo:: MakeN32Premul(width, height);
sk_sp<SkSurface> gpuSurface(
SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
@@ -97,7 +105,7 @@ example, we use a `GrContextFactory` to create a context.
}
SkCanvas* gpuCanvas = gpuSurface->getCanvas();
draw(gpuCanvas);
- sk_sp<SkImage> img(s->newImageSnapshot());
+ sk_sp<SkImage> img(gpuSurface->makeImageSnapshot());
if (!img) { return; }
sk_sp<SkData> png(img->encode());
if (!png) { return; }