1 2 /* 3 * Copyright 2015 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 #ifndef SKCOMMANDBUFFERGLCONTEXT_DEFINED 9 #define SKCOMMANDBUFFERGLCONTEXT_DEFINED 10 11 #if SK_COMMAND_BUFFER 12 13 #include "gl/SkGLContext.h" 14 15 class SkCommandBufferGLContext : public SkGLContext { 16 public: 17 ~SkCommandBufferGLContext() override; 18 CreateES2()19 static SkCommandBufferGLContext* CreateES2() { 20 SkCommandBufferGLContext* ctx = new SkCommandBufferGLContext(kGLES2_ContextVersion); 21 if (!ctx->isValid()) { 22 delete ctx; 23 return nullptr; 24 } 25 return ctx; 26 } CreateES3()27 static SkCommandBufferGLContext* CreateES3() { 28 SkCommandBufferGLContext* ctx = new SkCommandBufferGLContext(kGLES3_ContextVersion); 29 if (!ctx->isValid()) { 30 delete ctx; 31 return nullptr; 32 } 33 return ctx; 34 } 35 Create(void * nativeWindow,int msaaSampleCount)36 static SkCommandBufferGLContext* Create(void* nativeWindow, int msaaSampleCount) { 37 SkCommandBufferGLContext* ctx = new SkCommandBufferGLContext(nativeWindow, 38 msaaSampleCount); 39 if (!ctx->isValid()) { 40 delete ctx; 41 return nullptr; 42 } 43 return ctx; 44 } 45 46 void presentCommandBuffer(); 47 48 bool makeCurrent(); 49 int getStencilBits(); 50 int getSampleCount(); 51 52 private: 53 enum ContextVersion { 54 kGLES2_ContextVersion, 55 kGLES3_ContextVersion 56 }; 57 SkCommandBufferGLContext(ContextVersion minContextVersion); 58 SkCommandBufferGLContext(void* nativeWindow, int msaaSampleCount); 59 void initializeGLContext(ContextVersion minContextVersion, void* nativeWindow, 60 const int* configAttribs, const int* surfaceAttribs); 61 void destroyGLContext(); 62 63 void onPlatformMakeCurrent() const override; 64 void onPlatformSwapBuffers() const override; 65 GrGLFuncPtr onPlatformGetProcAddress(const char* name) const override; 66 67 void* fContext; 68 void* fDisplay; 69 void* fSurface; 70 void* fConfig; 71 }; 72 73 #endif // SK_COMMAND_BUFFER 74 75 #endif 76