Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "GLFW/glfw3.h"
- #include "include/gpu/GrBackendSurface.h"
- #include "include/gpu/GrDirectContext.h"
- #include "include/gpu/gl/GrGLInterface.h"
- #include "include/core/SkCanvas.h"
- #include "include/core/SkColorSpace.h"
- #include "include/core/SkSurface.h"
- #include "include/utils/SkParsePath.h"
- #include <stdio.h>
- #include <stdlib.h>
- GrDirectContext *sContext = nullptr;
- SkSurface *sSurface = nullptr;
- void error_callback(int error, const char *description) {
- fputs(description, stderr);
- }
- void key_callback(GLFWwindow *window, int key, int scancode, int action,
- int mods) {
- if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
- glfwSetWindowShouldClose(window, GL_TRUE);
- }
- void init_skia(int w, int h) {
- auto interface = GrGLMakeNativeInterface();
- sContext = GrDirectContext::MakeGL(interface).release();
- GrGLFramebufferInfo framebufferInfo;
- framebufferInfo.fFBOID = 0;
- framebufferInfo.fFormat = GL_RGBA8;
- SkColorType colorType = kRGBA_8888_SkColorType;
- GrBackendRenderTarget backendRenderTarget(w, h, 0, 0, framebufferInfo);
- sSurface = SkSurface::MakeFromBackendRenderTarget(
- sContext, backendRenderTarget, kBottomLeft_GrSurfaceOrigin,
- colorType, nullptr, nullptr)
- .release();
- if (sSurface == nullptr)
- abort();
- }
- const int kWidth = 960;
- const int kHeight = 640;
- int main(void) {
- GLFWwindow *window;
- glfwSetErrorCallback(error_callback);
- if (!glfwInit()) {
- exit(EXIT_FAILURE);
- }
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- window = glfwCreateWindow(kWidth, kHeight, "SkPath render example", NULL, NULL);
- if (!window) {
- glfwTerminate();
- exit(EXIT_FAILURE);
- }
- glfwMakeContextCurrent(window);
- init_skia(kWidth, kHeight);
- glfwSwapInterval(0);
- glfwSetKeyCallback(window, key_callback);
- SkCanvas *canvas = sSurface->getCanvas();
- while (!glfwWindowShouldClose(window)) {
- glfwWaitEvents();
- canvas->clear(SK_ColorBLACK);
- canvas->save();
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setColor(SK_ColorWHITE);
- SkPath path;
- SkParsePath::FromSVGString(
- "m 70.088251,119.8771 15.654512,29.9861 H 74.806653 L "
- "60.960128,121.4205 h -6.923263 v 28.4427 H 44.555964 V 84.114257 "
- "h 18.52083 q 9.921874,0 14.596178,4.409722 4.718402,4.365624 "
- "4.718402,13.493751 0,6.65868 -3.130902,11.33298 -3.130902,4.63021 "
- "-9.172221,6.52639 z m -16.051386,-4.89479 h 7.408332 q 5.600347,0 "
- "8.378471,-3.2191 2.822222,-3.26319 2.822222,-9.74548 0,-5.732641 "
- "-2.601736,-8.59896 -2.601736,-2.910416 -7.805207,-2.910416 h "
- "-8.202082 z",
- &path);
- canvas->drawPath(path, paint);
- canvas->restore();
- sContext->flush();
- glfwSwapBuffers(window);
- }
- delete sSurface;
- delete sContext;
- glfwDestroyWindow(window);
- glfwTerminate();
- exit(EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement