blob: 7cfc8d4d14abf0781959e1b57f95eb50b2b5a4e5 [file] [log] [blame]
{{/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/}}
{{/* ---- Includes ---- */}}
{{Include "cpp_common.tmpl"}}
{{/* ---- Overrides ---- */}}
{{Global "C++.EnumTypeOverride" "uint32_t"}}
{{$filename := print (Global "API") "_exports.cpp" }}
{{$ | Macro "Exports" | Format (Global "clang-format") | Write $filename}}
{{define "Exports"}}
{{AssertType $ "API"}}
{{Macro "C++.AOSP.Copyright"}}
#include "{{Global "API"}}_imports.h"
#include "{{Global "API"}}_types.h"
#include "spy.h"
#include <gapic/get_gfx_proc_address.h>
#include <gapic/log.h>
#include <gapic/target.h> // STDCALL
#include <memory>
#include <string.h>
using namespace gapii;
extern "C"
{{range $c := AllCommands $}}
{{if not (GetAnnotation $c "synthetic")}}
{{$name := Macro "CmdName" $c}}
EXPORT {{Macro "C++.ReturnType" $c}} STDCALL {{$name}}({{Macro "C++.CallParameters" $c}});
{{end}}
{{end}}
EXPORT void* STDCALL eglGetProcAddress(const char* name);
EXPORT void* STDCALL wglGetProcAddress(const char* name);
EXPORT void* STDCALL glXGetProcAddress(const char* name);
EXPORT void* STDCALL glXGetProcAddressARB(const char* name);
»} // extern "C"
namespace
std::unique_ptr<Spy> gSpy; // Must be accessed via spy() below, gets destroyed with the library.
// spy lazily constructs and returns the instance to the spy.
Spy* spy() {
static bool initializedOnce = false;
if (!initializedOnce) {
gSpy.reset(new Spy());
GAPID_INFO("Registering spy symbols...\n");
{{range $i, $c := AllCommands $}}
{{$name := Macro "CmdName" $c}}
{{if not (GetAnnotation $c "synthetic")}}
gSpy->RegisterSymbol("{{$name}}", reinterpret_cast<void*>({{$name}}));
{{end}}
{{end}}
gSpy->RegisterSymbol("eglGetProcAddress", reinterpret_cast<void*>(eglGetProcAddress));
gSpy->RegisterSymbol("wglGetProcAddress", reinterpret_cast<void*>(wglGetProcAddress));
gSpy->RegisterSymbol("glXGetProcAddress", reinterpret_cast<void*>(glXGetProcAddress));
gSpy->RegisterSymbol("glXGetProcAddressARB", reinterpret_cast<void*>(glXGetProcAddressARB));
initializedOnce = true;
}
return gSpy.get();
}
void* STDCALL GetSpyProcAddress(const char* name) {
if (void* proc = spy()->LookupSymbol(name)) {
return proc;
} else {
GAPID_WARNING("%s will NOT be captured.\n", name);
return gapic::GetGfxProcAddress(name, true);
}
}
»} // anonymous namespace
extern "C"
{{range $c := AllCommands $}}
{{if not (GetAnnotation $c "synthetic")}}
{{$name := Macro "CmdName" $c}}
EXPORT {{Macro "C++.ReturnType" $c}} STDCALL {{$name}}({{Macro "C++.CallParameters" $c}}) {
GAPID_INFO("{{$name}}()\n");
{{if not (IsVoid $c.Return.Type)}}return §{{end}}
spy()->{{$name}}({{Macro "C++.CallArguments" $c}});
}
{{end}}
{{end}}
EXPORT void* STDCALL eglGetProcAddress(const char* name) { return GetSpyProcAddress(name); }
EXPORT void* STDCALL wglGetProcAddress(const char* name) { return GetSpyProcAddress(name); }
EXPORT void* STDCALL glXGetProcAddress(const char* name) { return GetSpyProcAddress(name); }
EXPORT void* STDCALL glXGetProcAddressARB(const char* name) { return GetSpyProcAddress(name); }
»} // extern "C"
{{end}}