| {{/* |
| * Copyright 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. |
| */}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Entry point. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "Api"}} |
| {{template "AOSPCopyright"}} |
| ¶ |
| {{template "C++.GeneratedHeader"}} |
| ¶ |
| #include "GetGfxProcAddress.h" |
| #include "GfxApi.h" |
| #include "Interpreter.h" |
| #include "Log.h" |
| #include "Stack.h" |
| ¶ |
| namespace android { |
| namespace caze { |
| namespace gfxapi { |
| namespace { |
| ¶ |
| {{range $i, $c := $.Functions}} |
| {{if not (GetAnnotation $c "synthetic")}} |
| {{template "CommandHandler" $c}} |
| {{end}} |
| {{end}} |
| ¶ |
| } // end of anonymous namespace |
| ¶ |
| {{range $i, $c := $.Functions}} |
| {{if not (GetAnnotation $c "synthetic")}} |
| {{template "FunctionPtrDecl" $c}} |
| {{end}} |
| {{end}} |
| ¶ |
| {{template "Register" $}} |
| {{template "Initialize" $}} |
| ¶ |
| } // end of namespace gfxapi |
| } // end of namespace caze |
| } // end of namespace android |
| ¶ |
| {{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Emits the C++ function-pointer variable extern for a given command. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "FunctionPtrDecl"}} |
| {{AssertType $ "Function"}} |
| |
| {{Macro "FunctionPtrType" $}} {{$.Name}} = nullptr; |
| {{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Emits the Register function that registers all the functions with the |
| interpreter. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "Register"}} |
| void Register(Interpreter* interpreter) { |
| {{range $i, $c := $.Functions}} |
| {{if not (GetAnnotation $c "synthetic")}} |
| interpreter->registerFunction(Ids::{{Macro "C++.Public" $c.Name}}, call{{Macro "C++.Public" $c.Name}}); |
| {{end}} |
| {{end}} |
| } |
| {{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Emits the Initialize function that looks-up the API function addresses for |
| the currently bound context. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "Initialize"}} |
| void Initialize() { |
| {{range $i, $c := $.Functions}} |
| {{if not (GetAnnotation $c "synthetic")}} |
| {{$c.Name}} = reinterpret_cast<{{Macro "FunctionPtrType" $c}}>(GetGfxProcAddress("{{$c.Name}}")); |
| {{end}} |
| {{end}} |
| } |
| {{end}} |
| |
| |
| {{define "CommandHandler"}} |
| bool call{{Macro "C++.Public" $.Name}}(Stack* stack, bool pushReturn) { |
| {{range $i, $p := (Reverse $.CallParameters)}} |
| {{Macro "C++.ParameterType" $p}} {{$p.Name}} = stack->pop<{{Macro "C++.ParameterType" $p}}>(); |
| {{end}} |
| |
| if (stack->isValid()) { |
| CAZE_INFO("{{$.Name}}(§ |
| {{range $i, $p := $.CallParameters}} |
| {{if $i}}, {{end}}§ |
| {{if $p.Output}}%p§ |
| {{else }}{{Macro "PrintfFormatCode" (TypeOf $p)}}§ |
| {{end}} |
| {{end}} |
| )\n"§ |
| {{range $i, $p := $.CallParameters}} |
| , {{$p.Name}}§ |
| {{end}} |
| ); |
| |
| if ({{$.Name}} != nullptr) { |
| {{if not (IsVoid $.Return.Type)}} |
| {{Macro "C++.ReturnType" $}} return_value = {{Macro "Call" $}}; |
| CAZE_INFO("Returned: {{Macro "PrintfFormatCode" $.Return.Type}}\n", return_value); |
| if (pushReturn) { |
| stack->push<{{Macro "C++.ReturnType" $}}>(return_value); |
| } |
| {{else}} |
| {{Macro "Call" $}}; |
| {{end}} |
| } else { |
| CAZE_WARNING("Attempted to call unsupported function {{$.Name}}\n"); |
| } |
| |
| {{if 0}} {{/* Enable for debugging */}} |
| if (int err = glGetError()) { |
| CAZE_WARNING("{{$.Name}} returned error: 0x%x\n", err); |
| } |
| {{end}} |
| |
| return true; |
| } else { |
| CAZE_WARNING("Error during calling function {{$.Name}}\n"); |
| return false; |
| } |
| } |
| ¶ |
| {{end}} |
| |
| {{Include "GfxApiCommon.tmpl" "../../../gfxapi/cpp_common.tmpl"}} |
| {{$ | Macro "Api" | Format (Global "clang-format") | Write "GfxApi.cpp"}} |