blob: 5c639e37b25bbe1d5b64dcc322328c72b3ad7719 [file] [log] [blame]
/*
* Copyright (C) 2016 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.
*/
#ifndef GAPII_SPY_H
#define GAPII_SPY_H
#include "vulkan_spy.h"
#include "gles_spy.h"
#include <memory>
#include <unordered_map>
namespace gapii {
class Spy : public VulkanSpy {
public:
// get lazily constructs and returns the singleton instance to the spy.
static Spy* get();
void lock();
// resolve the imported functions. Call if the functions change due to
// external factors.
void resolveImports();
EGLBoolean eglInitialize(EGLDisplay dpy, EGLint* major, EGLint* minor);
EGLContext eglCreateContext(EGLDisplay display, EGLConfig config,
EGLContext share_context, EGLint* attrib_list);
EGLBoolean eglMakeCurrent(EGLDisplay display, EGLSurface draw, EGLSurface read,
EGLContext context);
BOOL wglMakeCurrent(HDC hdc, HGLRC hglrc);
CGLError CGLSetCurrentContext(CGLContextObj ctx);
Bool glXMakeContextCurrent(void* display, GLXDrawable draw, GLXDrawable read, GLXContext ctx);
Bool glXMakeCurrent(void* display, GLXDrawable drawable, GLXContext ctx);
// Intercepted GLES methods to optionally fake no support for precompiled shaders.
void glProgramBinary(uint32_t program, uint32_t binary_format, void* binary, int32_t binary_size);
void glProgramBinaryOES(uint32_t program, uint32_t binary_format, void* binary, int32_t binary_size);
void glShaderBinary(int32_t count, uint32_t* shaders, uint32_t binary_format, void* binary, int32_t binary_size);
void glGetInteger64v(uint32_t param, int64_t* values);
void glGetIntegerv(uint32_t param, int32_t* values);
GLubyte* glGetString(uint32_t name);
GLubyte* glGetStringi(uint32_t name, GLuint index);
void onPostDrawCall() override;
void onPreEndOfFrame() override;
inline void RegisterSymbol(const std::string& name, void* symbol) {
mSymbols.emplace(name, symbol);
}
inline void* LookupSymbol(const std::string& name) const {
const auto symbol = mSymbols.find(name);
return (symbol == mSymbols.end()) ? nullptr : symbol->second;
}
virtual void maybeAddErrorStateExtra(gapic::Vector<gapic::Encodable*>& extras) override;
void setFakeGlError(GLenum_Error error);
uint32_t glGetError();
protected:
virtual void onThreadSwitched(uint64_t threadID) override;
private:
Spy();
// observeFramebuffer captures the currently bound framebuffer's color
// buffer, and writes it to a FramebufferObservation atom.
void observeFramebuffer();
// getFramebufferAttachmentSize attempts to retrieve the currently bound
// framebuffer's color buffer dimensions, returning true on success or
// false if the dimensions could not be retrieved.
bool getFramebufferAttachmentSize(uint32_t& width, uint32_t& height);
std::shared_ptr<gapic::Encoder> mEncoder;
std::unordered_map<std::string, void*> mSymbols;
int mNumFrames;
int mNumDraws;
int mNumDrawsPerFrame;
int mObserveFrameFrequency;
int mObserveDrawFrequency;
bool mDisablePrecompiledShaders;
bool mRecordGLErrorState;
std::unordered_map<ContextID, GLenum_Error> mFakeGlError;
};
} // namespace gapii
#endif // GAPII_SPY_H