blob: 16405b488d635ca0dec2c2aba25ddeb6b289907b [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2011 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.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@google.comac10a2d2010-12-22 21:39:39 +000010#include "GrTypes.h"
11
tomhudson@google.com6bf38b52012-02-14 15:11:59 +000012#include "gl/GrGLConfig.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000013
reed@google.comac10a2d2010-12-22 21:39:39 +000014#include "GrGpu.h"
bsalomon@google.com5739d2c2012-05-31 15:07:19 +000015#include "gl/GrGpuGL.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000016
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000017GrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrContext* context) {
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000018
epoger@google.com17b78942011-08-26 14:40:38 +000019 const GrGLInterface* glInterface = NULL;
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000020 SkAutoTUnref<const GrGLInterface> glInterfaceUnref;
bsalomon@google.com0b77d682011-08-19 13:28:54 +000021
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000022 if (kOpenGL_GrBackend == backend) {
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000023 glInterface = reinterpret_cast<const GrGLInterface*>(backendContext);
bsalomon@google.com0b77d682011-08-19 13:28:54 +000024 if (NULL == glInterface) {
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000025 glInterface = GrGLDefaultInterface();
26 // By calling GrGLDefaultInterface we've taken a ref on the
27 // returned object. We only want to hold that ref until after
28 // the GrGpu is constructed and has taken ownership.
29 glInterfaceUnref.reset(glInterface);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000030 }
bsalomon@google.com0b77d682011-08-19 13:28:54 +000031 if (NULL == glInterface) {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000032#ifdef SK_DEBUG
bsalomon@google.com6150c202011-10-07 19:55:03 +000033 GrPrintf("No GL interface provided!\n");
bsalomon@google.com0b77d682011-08-19 13:28:54 +000034#endif
35 return NULL;
36 }
robertphillips@google.com6177e692013-02-28 20:16:25 +000037 GrGLContext ctx(glInterface);
38 if (ctx.isInitialized()) {
39 return SkNEW_ARGS(GrGpuGL, (ctx, context));
bsalomon@google.combf2a4692011-05-04 12:35:39 +000040 }
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000041 }
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000042 return NULL;
reed@google.comac10a2d2010-12-22 21:39:39 +000043}