Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(556)

Side by Side Diff: src/gpu/gl/mesa/SkMesaGLContext.cpp

Issue 1815823002: Move SkGLContext and some GrGLInterface implementations to skgputest module (Closed) Base URL: https://chromium.googlesource.com/skia.git@debugobject
Patch Set: fix windows and android? Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/mesa/SkMesaGLContext.h ('k') | src/gpu/gl/nacl/SkCreatePlatformGLContext_nacl.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include <GL/osmesa.h>
9
10 #include "gl/mesa/SkMesaGLContext.h"
11 #include "gl/GrGLDefines.h"
12
13 static const GrGLint gBOGUS_SIZE = 16;
14
15 SkMesaGLContext::SkMesaGLContext()
16 : fContext(static_cast<Context>(0))
17 , fImage(nullptr) {
18 GR_STATIC_ASSERT(sizeof(Context) == sizeof(OSMesaContext));
19
20 /* Create an RGBA-mode context */
21 #if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
22 /* specify Z, stencil, accum sizes */
23 fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr);
24 #else
25 fContext = (Context)OSMesaCreateContext(OSMESA_BGRA, nullptr);
26 #endif
27 if (!fContext) {
28 SkDebugf("OSMesaCreateContext failed!\n");
29 this->destroyGLContext();
30 return;
31 }
32 // Allocate the image buffer
33 fImage = (GrGLubyte *) sk_malloc_throw(gBOGUS_SIZE * gBOGUS_SIZE *
34 4 * sizeof(GrGLubyte));
35 if (!fImage) {
36 SkDebugf("Alloc image buffer failed!\n");
37 this->destroyGLContext();
38 return;
39 }
40
41 // Bind the buffer to the context and make it current
42 if (!OSMesaMakeCurrent((OSMesaContext)fContext,
43 fImage,
44 GR_GL_UNSIGNED_BYTE,
45 gBOGUS_SIZE,
46 gBOGUS_SIZE)) {
47 SkDebugf("OSMesaMakeCurrent failed!\n");
48 this->destroyGLContext();
49 return;
50 }
51
52 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateMesaInterface());
53 if (nullptr == gl.get()) {
54 SkDebugf("Could not create GL interface!\n");
55 this->destroyGLContext();
56 return;
57 }
58
59 if (!gl->validate()) {
60 SkDebugf("Could not validate GL interface!\n");
61 this->destroyGLContext();
62 return;
63 }
64
65 this->init(gl.release());
66 }
67
68 SkMesaGLContext::~SkMesaGLContext() {
69 this->teardown();
70 this->destroyGLContext();
71 }
72
73 void SkMesaGLContext::destroyGLContext() {
74 if (fImage) {
75 sk_free(fImage);
76 fImage = nullptr;
77 }
78
79 if (fContext) {
80 OSMesaDestroyContext((OSMesaContext)fContext);
81 fContext = static_cast<Context>(0);
82 }
83 }
84
85
86
87 void SkMesaGLContext::onPlatformMakeCurrent() const {
88 if (fContext) {
89 if (!OSMesaMakeCurrent((OSMesaContext)fContext, fImage,
90 GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, gBOGUS_SIZE)) {
91 SkDebugf("Could not make MESA context current.");
92 }
93 }
94 }
95
96 void SkMesaGLContext::onPlatformSwapBuffers() const { }
97
98 GrGLFuncPtr SkMesaGLContext::onPlatformGetProcAddress(const char* procName) cons t {
99 return OSMesaGetProcAddress(procName);
100 }
OLDNEW
« no previous file with comments | « src/gpu/gl/mesa/SkMesaGLContext.h ('k') | src/gpu/gl/nacl/SkCreatePlatformGLContext_nacl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698