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

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: 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 | « tools/gpu/gl/mesa/GLContext_mesa.h ('k') | tools/gpu/gl/mesa/osmesa_wrapper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1
1 /* 2 /*
2 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
3 * 4 *
4 * 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
5 * found in the LICENSE file. 6 * found in the LICENSE file.
6 */ 7 */
7 8
8 #include <GL/osmesa.h> 9 #include <GL/osmesa.h>
9 10
10 #include "gl/mesa/SkMesaGLContext.h" 11 #include "gl/mesa/GLContext_mesa.h"
11 #include "gl/GrGLDefines.h" 12 #include "gl/GrGLDefines.h"
12 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
13 static const GrGLint gBOGUS_SIZE = 16; 33 static const GrGLint gBOGUS_SIZE = 16;
14 34
15 SkMesaGLContext::SkMesaGLContext() 35 class MesaGLContext : public sk_gpu_test::GLContext {
16 : fContext(static_cast<Context>(0)) 36 private:
17 , 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) {
18 GR_STATIC_ASSERT(sizeof(Context) == sizeof(OSMesaContext)); 57 GR_STATIC_ASSERT(sizeof(Context) == sizeof(OSMesaContext));
19 58
20 /* Create an RGBA-mode context */ 59 /* Create an RGBA-mode context */
21 #if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305 60 #if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
22 /* specify Z, stencil, accum sizes */ 61 /* specify Z, stencil, accum sizes */
23 fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr); 62 fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr);
24 #else 63 #else
25 fContext = (Context)OSMesaCreateContext(OSMESA_BGRA, nullptr); 64 fContext = (Context) OSMesaCreateContext(OSMESA_BGRA, nullptr);
26 #endif 65 #endif
27 if (!fContext) { 66 if (!fContext) {
28 SkDebugf("OSMesaCreateContext failed!\n"); 67 SkDebugf("OSMesaCreateContext failed!\n");
29 this->destroyGLContext(); 68 this->destroyGLContext();
30 return; 69 return;
31 } 70 }
32 // Allocate the image buffer 71 // Allocate the image buffer
33 fImage = (GrGLubyte *) sk_malloc_throw(gBOGUS_SIZE * gBOGUS_SIZE * 72 fImage = (GrGLubyte *) sk_malloc_throw(gBOGUS_SIZE * gBOGUS_SIZE *
34 4 * sizeof(GrGLubyte)); 73 4 * sizeof(GrGLubyte));
35 if (!fImage) { 74 if (!fImage) {
36 SkDebugf("Alloc image buffer failed!\n"); 75 SkDebugf("Alloc image buffer failed!\n");
37 this->destroyGLContext(); 76 this->destroyGLContext();
38 return; 77 return;
39 } 78 }
40 79
41 // Bind the buffer to the context and make it current 80 // Bind the buffer to the context and make it current
42 if (!OSMesaMakeCurrent((OSMesaContext)fContext, 81 if (!OSMesaMakeCurrent((OSMesaContext) fContext,
43 fImage, 82 fImage,
44 GR_GL_UNSIGNED_BYTE, 83 GR_GL_UNSIGNED_BYTE,
45 gBOGUS_SIZE, 84 gBOGUS_SIZE,
46 gBOGUS_SIZE)) { 85 gBOGUS_SIZE)) {
47 SkDebugf("OSMesaMakeCurrent failed!\n"); 86 SkDebugf("OSMesaMakeCurrent failed!\n");
48 this->destroyGLContext(); 87 this->destroyGLContext();
49 return; 88 return;
50 } 89 }
51 90
52 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateMesaInterface()); 91 SkAutoTUnref<const GrGLInterface> gl(create_mesa_interface());
53 if (nullptr == gl.get()) { 92 if (nullptr == gl.get()) {
54 SkDebugf("Could not create GL interface!\n"); 93 SkDebugf("Could not create GL interface!\n");
55 this->destroyGLContext(); 94 this->destroyGLContext();
56 return; 95 return;
57 } 96 }
58 97
59 if (!gl->validate()) { 98 if (!gl->validate()) {
60 SkDebugf("Could not validate GL interface!\n"); 99 SkDebugf("Could not validate GL interface!\n");
61 this->destroyGLContext(); 100 this->destroyGLContext();
62 return; 101 return;
63 } 102 }
64 103
65 this->init(gl.release()); 104 this->init(gl.release());
66 } 105 }
67 106
68 SkMesaGLContext::~SkMesaGLContext() { 107 MesaGLContext::~MesaGLContext() {
69 this->teardown(); 108 this->teardown();
70 this->destroyGLContext(); 109 this->destroyGLContext();
71 } 110 }
72 111
73 void SkMesaGLContext::destroyGLContext() { 112 void MesaGLContext::destroyGLContext() {
74 if (fImage) { 113 if (fImage) {
75 sk_free(fImage); 114 sk_free(fImage);
76 fImage = nullptr; 115 fImage = nullptr;
77 } 116 }
78 117
79 if (fContext) { 118 if (fContext) {
80 OSMesaDestroyContext((OSMesaContext)fContext); 119 OSMesaDestroyContext((OSMesaContext) fContext);
81 fContext = static_cast<Context>(0); 120 fContext = static_cast<Context>(0);
82 } 121 }
83 } 122 }
84 123
85 124
86 125 void MesaGLContext::onPlatformMakeCurrent() const {
87 void SkMesaGLContext::onPlatformMakeCurrent() const {
88 if (fContext) { 126 if (fContext) {
89 if (!OSMesaMakeCurrent((OSMesaContext)fContext, fImage, 127 if (!OSMesaMakeCurrent((OSMesaContext) fContext, fImage,
90 GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, gBOGUS_SIZE)) { 128 GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, gBOGUS_SIZE)) {
91 SkDebugf("Could not make MESA context current."); 129 SkDebugf("Could not make MESA context current.");
92 } 130 }
93 } 131 }
94 } 132 }
95 133
96 void SkMesaGLContext::onPlatformSwapBuffers() const { } 134 void MesaGLContext::onPlatformSwapBuffers() const { }
97 135
98 GrGLFuncPtr SkMesaGLContext::onPlatformGetProcAddress(const char* procName) cons t { 136 GrGLFuncPtr MesaGLContext::onPlatformGetProcAddress(const char *procName) const {
99 return OSMesaGetProcAddress(procName); 137 return OSMesaGetProcAddress(procName);
100 } 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
« no previous file with comments | « tools/gpu/gl/mesa/GLContext_mesa.h ('k') | tools/gpu/gl/mesa/osmesa_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698