180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2011 Google Inc. 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "GrTypes.h" 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "gl/GrGLConfig.h" 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "GrGpu.h" 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "gl/GrGpuGL.h" 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 17096defe64d408e54474fe19f418c95bf1a554fc7Derek SollenbergerGrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrContext* context) { 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const GrGLInterface* glInterface = NULL; 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkAutoTUnref<const GrGLInterface> glInterfaceUnref; 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 22363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger if (kOpenGL_GrBackend == backend) { 23096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger glInterface = reinterpret_cast<const GrGLInterface*>(backendContext); 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (NULL == glInterface) { 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru glInterface = GrGLDefaultInterface(); 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // By calling GrGLDefaultInterface we've taken a ref on the 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // returned object. We only want to hold that ref until after 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // the GrGpu is constructed and has taken ownership. 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru glInterfaceUnref.reset(glInterface); 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (NULL == glInterface) { 320a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenberger#ifdef SK_DEBUG 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GrPrintf("No GL interface provided!\n"); 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 37096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger GrGLContext ctx(glInterface); 38096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger if (ctx.isInitialized()) { 39096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger return SkNEW_ARGS(GrGpuGL, (ctx, context)); 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 44