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

Side by Side Diff: tools/gpu/gl/mesa/GLContext_mesa.cpp

Issue 1815823002: Move SkGLContext and some GrGLInterface implementations to skgputest module (Closed) Base URL: https://chromium.googlesource.com/skia.git@debugobject
Patch Set: rebase, readd null interface to main lib 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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include <GL/osmesa.h> 9 #include <GL/osmesa.h>
10 10
11 #include "gl/mesa/SkMesaGLContext.h" 11 #include "gl/mesa/GLContext_mesa.h"
12 #include "gl/GrGLDefines.h" 12 #include "gl/GrGLDefines.h"
13 13
14 #include "gl/GrGLAssembleInterface.h"
15 #include "gl/GrGLUtil.h"
16 #include "osmesa_wrapper.h"
17
18 namespace {
19
20 static GrGLFuncPtr osmesa_get(void* ctx, const char name[]) {
21 SkASSERT(nullptr == ctx);
22 SkASSERT(OSMesaGetCurrentContext());
23 return OSMesaGetProcAddress(name);
24 }
25
26 static const GrGLInterface* create_mesa_interface() {
27 if (nullptr == OSMesaGetCurrentContext()) {
28 return nullptr;
29 }
30 return GrGLAssembleInterface(nullptr, osmesa_get);
31 }
32
14 static const GrGLint gBOGUS_SIZE = 16; 33 static const GrGLint gBOGUS_SIZE = 16;
15 34
16 SkMesaGLContext::SkMesaGLContext() 35 class MesaGLContext : public sk_gpu_test::GLContext {
17 : fContext(static_cast<Context>(0)) 36 private:
18 , fImage(nullptr) { 37 typedef intptr_t Context;
38
39 public:
40 MesaGLContext();
41 ~MesaGLContext() override;
42
43 private:
44 void destroyGLContext();
45
46 void onPlatformMakeCurrent() const override;
47
48 void onPlatformSwapBuffers() const override;
49
50 GrGLFuncPtr onPlatformGetProcAddress(const char *) const override;
51
52 Context fContext;
53 GrGLubyte *fImage;
54 };
55
56 MesaGLContext::MesaGLContext() : fContext(static_cast<Context>(0)), fImage(nullp tr) {
19 GR_STATIC_ASSERT(sizeof(Context) == sizeof(OSMesaContext)); 57 GR_STATIC_ASSERT(sizeof(Context) == sizeof(OSMesaContext));
20 58
21 /* Create an RGBA-mode context */ 59 /* Create an RGBA-mode context */
22 #if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305 60 #if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
23 /* specify Z, stencil, accum sizes */ 61 /* specify Z, stencil, accum sizes */
24 fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr); 62 fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr);
25 #else 63 #else
26 fContext = (Context)OSMesaCreateContext(OSMESA_BGRA, nullptr); 64 fContext = (Context) OSMesaCreateContext(OSMESA_BGRA, nullptr);
27 #endif 65 #endif
28 if (!fContext) { 66 if (!fContext) {
29 SkDebugf("OSMesaCreateContext failed!\n"); 67 SkDebugf("OSMesaCreateContext failed!\n");
30 this->destroyGLContext(); 68 this->destroyGLContext();
31 return; 69 return;
32 } 70 }
33 // Allocate the image buffer 71 // Allocate the image buffer
34 fImage = (GrGLubyte *) sk_malloc_throw(gBOGUS_SIZE * gBOGUS_SIZE * 72 fImage = (GrGLubyte *) sk_malloc_throw(gBOGUS_SIZE * gBOGUS_SIZE *
35 4 * sizeof(GrGLubyte)); 73 4 * sizeof(GrGLubyte));
36 if (!fImage) { 74 if (!fImage) {
37 SkDebugf("Alloc image buffer failed!\n"); 75 SkDebugf("Alloc image buffer failed!\n");
38 this->destroyGLContext(); 76 this->destroyGLContext();
39 return; 77 return;
40 } 78 }
41 79
42 // Bind the buffer to the context and make it current 80 // Bind the buffer to the context and make it current
43 if (!OSMesaMakeCurrent((OSMesaContext)fContext, 81 if (!OSMesaMakeCurrent((OSMesaContext) fContext,
44 fImage, 82 fImage,
45 GR_GL_UNSIGNED_BYTE, 83 GR_GL_UNSIGNED_BYTE,
46 gBOGUS_SIZE, 84 gBOGUS_SIZE,
47 gBOGUS_SIZE)) { 85 gBOGUS_SIZE)) {
48 SkDebugf("OSMesaMakeCurrent failed!\n"); 86 SkDebugf("OSMesaMakeCurrent failed!\n");
49 this->destroyGLContext(); 87 this->destroyGLContext();
50 return; 88 return;
51 } 89 }
52 90
53 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateMesaInterface()); 91 SkAutoTUnref<const GrGLInterface> gl(create_mesa_interface());
54 if (nullptr == gl.get()) { 92 if (nullptr == gl.get()) {
55 SkDebugf("Could not create GL interface!\n"); 93 SkDebugf("Could not create GL interface!\n");
56 this->destroyGLContext(); 94 this->destroyGLContext();
57 return; 95 return;
58 } 96 }
59 97
60 if (!gl->validate()) { 98 if (!gl->validate()) {
61 SkDebugf("Could not validate GL interface!\n"); 99 SkDebugf("Could not validate GL interface!\n");
62 this->destroyGLContext(); 100 this->destroyGLContext();
63 return; 101 return;
64 } 102 }
65 103
66 this->init(gl.release()); 104 this->init(gl.release());
67 } 105 }
68 106
69 SkMesaGLContext::~SkMesaGLContext() { 107 MesaGLContext::~MesaGLContext() {
70 this->teardown(); 108 this->teardown();
71 this->destroyGLContext(); 109 this->destroyGLContext();
72 } 110 }
73 111
74 void SkMesaGLContext::destroyGLContext() { 112 void MesaGLContext::destroyGLContext() {
75 if (fImage) { 113 if (fImage) {
76 sk_free(fImage); 114 sk_free(fImage);
77 fImage = nullptr; 115 fImage = nullptr;
78 } 116 }
79 117
80 if (fContext) { 118 if (fContext) {
81 OSMesaDestroyContext((OSMesaContext)fContext); 119 OSMesaDestroyContext((OSMesaContext) fContext);
82 fContext = static_cast<Context>(0); 120 fContext = static_cast<Context>(0);
83 } 121 }
84 } 122 }
85 123
86 124
87 125 void MesaGLContext::onPlatformMakeCurrent() const {
88 void SkMesaGLContext::onPlatformMakeCurrent() const {
89 if (fContext) { 126 if (fContext) {
90 if (!OSMesaMakeCurrent((OSMesaContext)fContext, fImage, 127 if (!OSMesaMakeCurrent((OSMesaContext) fContext, fImage,
91 GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, gBOGUS_SIZE)) { 128 GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, gBOGUS_SIZE)) {
92 SkDebugf("Could not make MESA context current."); 129 SkDebugf("Could not make MESA context current.");
93 } 130 }
94 } 131 }
95 } 132 }
96 133
97 void SkMesaGLContext::onPlatformSwapBuffers() const { } 134 void MesaGLContext::onPlatformSwapBuffers() const { }
98 135
99 GrGLFuncPtr SkMesaGLContext::onPlatformGetProcAddress(const char* procName) cons t { 136 GrGLFuncPtr MesaGLContext::onPlatformGetProcAddress(const char *procName) const {
100 return OSMesaGetProcAddress(procName); 137 return OSMesaGetProcAddress(procName);
101 } 138 }
139 } // anonymous namespace
140
141
142 namespace sk_gpu_test {
143 GLContext *CreateMesaGLContext() {
144 MesaGLContext *ctx = new MesaGLContext;
145 if (!ctx->isValid()) {
146 delete ctx;
147 return nullptr;
148 }
149 return ctx;
150 }
151 } // sk_gpu_test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698