From: egdaniel Date: Thu, 26 Mar 2015 16:09:41 +0000 (-0700) Subject: Add support for using alternative backends (like DirectX) when creating a GrGpu. X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~3016 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=384181c8100e059a94b1708f8af766e598fab3d9;p=platform%2Fupstream%2FlibSkiaSharp.git Add support for using alternative backends (like DirectX) when creating a GrGpu. BUG=skia: Review URL: https://codereview.chromium.org/1038643002 --- diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi index d7d16e0..98c9175 100644 --- a/gyp/gpu.gypi +++ b/gyp/gpu.gypi @@ -104,6 +104,7 @@ '<(skia_src_path)/gpu/GrGpuResourcePriv.h', '<(skia_src_path)/gpu/GrGpuResource.cpp', '<(skia_src_path)/gpu/GrGpuFactory.cpp', + '<(skia_src_path)/gpu/GrGpuFactory.h', '<(skia_src_path)/gpu/GrIndexBuffer.h', '<(skia_src_path)/gpu/GrInvariantOutput.cpp', '<(skia_src_path)/gpu/GrInOrderDrawBuffer.cpp', diff --git a/src/gpu/GrGpuFactory.cpp b/src/gpu/GrGpuFactory.cpp index 4b09c14..74adf98 100644 --- a/src/gpu/GrGpuFactory.cpp +++ b/src/gpu/GrGpuFactory.cpp @@ -7,37 +7,49 @@ */ -#include "GrTypes.h" +#include "GrGpuFactory.h" #include "gl/GrGLConfig.h" #include "GrGpu.h" #include "gl/GrGLGpu.h" -GrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrContext* context) { - +static GrGpu* gl_gpu_create(GrBackendContext backendContext, GrContext* context) { const GrGLInterface* glInterface = NULL; SkAutoTUnref glInterfaceUnref; - if (kOpenGL_GrBackend == backend) { - glInterface = reinterpret_cast(backendContext); - if (NULL == glInterface) { - glInterface = GrGLDefaultInterface(); - // By calling GrGLDefaultInterface we've taken a ref on the - // returned object. We only want to hold that ref until after - // the GrGpu is constructed and has taken ownership. - glInterfaceUnref.reset(glInterface); - } - if (NULL == glInterface) { + glInterface = reinterpret_cast(backendContext); + if (NULL == glInterface) { + glInterface = GrGLDefaultInterface(); + // By calling GrGLDefaultInterface we've taken a ref on the + // returned object. We only want to hold that ref until after + // the GrGpu is constructed and has taken ownership. + glInterfaceUnref.reset(glInterface); + } + if (NULL == glInterface) { #ifdef SK_DEBUG - SkDebugf("No GL interface provided!\n"); + SkDebugf("No GL interface provided!\n"); #endif - return NULL; - } - GrGLContext ctx(glInterface); - if (ctx.isInitialized()) { - return SkNEW_ARGS(GrGLGpu, (ctx, context)); - } + return NULL; + } + GrGLContext ctx(glInterface); + if (ctx.isInitialized()) { + return SkNEW_ARGS(GrGLGpu, (ctx, context)); } return NULL; } + +static const int kMaxNumBackends = 4; +static CreateGpuProc gGpuFactories[kMaxNumBackends] = {gl_gpu_create, NULL, NULL, NULL}; + +GrGpuFactoryRegistrar::GrGpuFactoryRegistrar(int i, CreateGpuProc proc) { + gGpuFactories[i] = proc; +} + +GrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrContext* context) { + SkASSERT((int)backend < kMaxNumBackends); + if (!gGpuFactories[backend]) { + return NULL; + } + return (gGpuFactories[backend])(backendContext, context); +} diff --git a/src/gpu/GrGpuFactory.h b/src/gpu/GrGpuFactory.h new file mode 100644 index 0000000..180f264 --- /dev/null +++ b/src/gpu/GrGpuFactory.h @@ -0,0 +1,23 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrGpuFactory_DEFINED +#define GrGpuFactory_DEFINED + +#include "GrTypes.h" + +class GrGpu; +class GrContext; + +typedef GrGpu* (*CreateGpuProc)(GrBackendContext, GrContext*); + +class GrGpuFactoryRegistrar { +public: + GrGpuFactoryRegistrar(int i, CreateGpuProc proc); +}; + +#endif