Add ANGLE platform implementation template.

The platform implementation allows the app layer to pass in an
object, on which ANGLE can call virtual methods. Our current
platform will handle trace events, for app profiling, and
histogram records for statistics. The platform approach gives
a much more robust approach than using entry points for every
piece of functionality, and is based on the interop with Blink.

The default platform implementation does a no-op on every call.
The destructor is also private, to ensure we do not call the
destructor of the passed-in class.

BUG=436191

Change-Id: I05641b89a48a9cff81ced059518fceb5aa6c883b
Reviewed-on: https://chromium-review.googlesource.com/248631
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
This commit is contained in:
Jamie Madill 2015-02-17 16:03:16 -05:00
Родитель 32b5b147e7
Коммит 5feea56239
11 изменённых файлов: 215 добавлений и 24 удалений

Просмотреть файл

@ -10,13 +10,13 @@
#define LIBGLESV2_EXPORT_H_
#if defined(_WIN32)
# if defined(LIBGLESV2_IMPLEMENTATION)
# if defined(LIBGLESV2_IMPLEMENTATION) || defined(LIBANGLE_IMPLEMENTATION)
# define ANGLE_EXPORT __declspec(dllexport)
# else
# define ANGLE_EXPORT __declspec(dllimport)
# endif
#elif defined(__GNUC__)
# if defined(LIBGLESV2_IMPLEMENTATION)
# if defined(LIBGLESV2_IMPLEMENTATION) || defined(LIBANGLE_IMPLEMENTATION)
# define ANGLE_EXPORT __attribute__((visibility ("default")))
# else
# define ANGLE_EXPORT

107
include/platform/Platform.h Normal file
Просмотреть файл

@ -0,0 +1,107 @@
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Platform.h: The public interface ANGLE exposes to the API layer, for
// doing platform-specific tasks like gathering data, or for tracing.
#ifndef ANGLE_PLATFORM_H
#define ANGLE_PLATFORM_H
#include <stdint.h>
#include "../export.h"
namespace angle
{
class Platform
{
public:
ANGLE_EXPORT static void initialize(Platform*);
ANGLE_EXPORT static void shutdown();
ANGLE_EXPORT static Platform *current();
// Tracing --------
typedef uint64_t TraceEventHandle;
// Add a trace event to the platform tracing system. Depending on the actual
// enabled state, this event may be recorded or dropped.
// - phase specifies the type of event:
// - BEGIN ('B'): Marks the beginning of a scoped event.
// - END ('E'): Marks the end of a scoped event.
// - COMPLETE ('X'): Marks the beginning of a scoped event, but doesn't
// need a matching END event. Instead, at the end of the scope,
// updateTraceEventDuration() must be called with the TraceEventHandle
// returned from addTraceEvent().
// - INSTANT ('I'): Standalone, instantaneous event.
// - START ('S'): Marks the beginning of an asynchronous event (the end
// event can occur in a different scope or thread). The id parameter is
// used to match START/FINISH pairs.
// - FINISH ('F'): Marks the end of an asynchronous event.
// - COUNTER ('C'): Used to trace integer quantities that change over
// time. The argument values are expected to be of type int.
// - METADATA ('M'): Reserved for internal use.
// - categoryEnabled is the pointer returned by getTraceCategoryEnabledFlag.
// - name is the name of the event. Also used to match BEGIN/END and
// START/FINISH pairs.
// - id optionally allows events of the same name to be distinguished from
// each other. For example, to trace the consutruction and destruction of
// objects, specify the pointer as the id parameter.
// - numArgs specifies the number of elements in argNames, argTypes, and
// argValues.
// - argNames is the array of argument names. Use long-lived literal strings
// or specify the COPY flag.
// - argTypes is the array of argument types:
// - BOOL (1): bool
// - UINT (2): unsigned long long
// - INT (3): long long
// - DOUBLE (4): double
// - POINTER (5): void*
// - STRING (6): char* (long-lived null-terminated char* string)
// - COPY_STRING (7): char* (temporary null-terminated char* string)
// - CONVERTABLE (8): WebConvertableToTraceFormat
// - argValues is the array of argument values. Each value is the unsigned
// long long member of a union of all supported types.
// - flags can be 0 or one or more of the following, ORed together:
// - COPY (0x1): treat all strings (name, argNames and argValues of type
// string) as temporary so that they will be copied by addTraceEvent.
// - HAS_ID (0x2): use the id argument to uniquely identify the event for
// matching with other events of the same name.
// - MANGLE_ID (0x4): specify this flag if the id parameter is the value
// of a pointer.
virtual TraceEventHandle addTraceEvent(char phase,
const unsigned char *categoryEnabledFlag,
const char *name,
unsigned long long id,
double timestamp,
int numArgs,
const char **argNames,
const unsigned char *argTypes,
const unsigned long long *argValues,
unsigned char flags)
{
return 0;
}
// Set the duration field of a COMPLETE trace event.
virtual void updateTraceEventDuration(const unsigned char* categoryEnabledFlag, const char* name, TraceEventHandle) { }
// Callbacks for reporting histogram data.
// CustomCounts histogram has exponential bucket sizes, so that min=1, max=1000000, bucketCount=50 would do.
virtual void histogramCustomCounts(const char* name, int sample, int min, int max, int bucketCount) { }
// Enumeration histogram buckets are linear, boundaryValue should be larger than any possible sample value.
virtual void histogramEnumeration(const char* name, int sample, int boundaryValue) { }
// Unlike enumeration histograms, sparse histograms only allocate memory for non-empty buckets.
virtual void histogramSparse(const char* name, int sample) { }
protected:
virtual ~Platform() { }
};
}
#endif // ANGLE_PLATFORM_H

Просмотреть файл

@ -10,6 +10,15 @@
#include "libANGLE/Display.h"
#include <algorithm>
#include <iterator>
#include <map>
#include <sstream>
#include <vector>
#include <platform/Platform.h>
#include <EGL/eglext.h>
#include "common/debug.h"
#include "common/mathutil.h"
#include "common/platform.h"
@ -17,14 +26,6 @@
#include "libANGLE/Surface.h"
#include "libANGLE/renderer/DisplayImpl.h"
#include <algorithm>
#include <map>
#include <vector>
#include <sstream>
#include <iterator>
#include <EGL/eglext.h>
#if defined(ANGLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11)
# include "libANGLE/renderer/d3d/DisplayD3D.h"
#endif
@ -40,6 +41,44 @@
namespace egl
{
namespace
{
class DefaultPlatform : public angle::Platform
{
public:
DefaultPlatform() {}
~DefaultPlatform() override {}
};
DefaultPlatform *defaultPlatform = nullptr;
void InitDefaultPlatformImpl()
{
if (angle::Platform::current() == nullptr)
{
if (defaultPlatform == nullptr)
{
defaultPlatform = new DefaultPlatform();
}
angle::Platform::initialize(defaultPlatform);
}
}
void DeinitDefaultPlatformImpl()
{
if (defaultPlatform != nullptr)
{
if (angle::Platform::current() == defaultPlatform)
{
angle::Platform::shutdown();
}
SafeDelete(defaultPlatform);
}
}
typedef std::map<EGLNativeDisplayType, Display*> DisplayMap;
static DisplayMap *GetDisplayMap()
{
@ -47,8 +86,13 @@ static DisplayMap *GetDisplayMap()
return &displays;
}
}
Display *Display::getDisplay(EGLNativeDisplayType displayId, const AttributeMap &attribMap)
{
// Initialize the global platform if not already
InitDefaultPlatformImpl();
Display *display = NULL;
DisplayMap *displays = GetDisplayMap();
@ -195,6 +239,9 @@ void Display::terminate()
mImplementation->terminate();
mInitialized = false;
// De-init default platform
DeinitDefaultPlatformImpl();
}
std::vector<const Config*> Display::getConfigs(const egl::AttributeMap &attribs) const

41
src/libANGLE/Platform.cpp Normal file
Просмотреть файл

@ -0,0 +1,41 @@
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Platform.cpp: Implementation methods for angle::Platform.
#include <platform/Platform.h>
#include "common/debug.h"
#include "platform/Platform.h"
namespace angle
{
namespace
{
Platform *currentPlatform = nullptr;
}
// static
ANGLE_EXPORT Platform *Platform::current()
{
return currentPlatform;
}
// static
ANGLE_EXPORT void Platform::initialize(Platform *platformImpl)
{
ASSERT(platformImpl != nullptr);
currentPlatform = platformImpl;
}
// static
ANGLE_EXPORT void Platform::shutdown()
{
currentPlatform = nullptr;
}
}

Просмотреть файл

@ -25,6 +25,8 @@
],
'libangle_includes':
[
'../include/angle_gl.h',
'../include/export.h',
'../include/EGL/egl.h',
'../include/EGL/eglext.h',
'../include/EGL/eglplatform.h',
@ -37,7 +39,7 @@
'../include/GLSLANG/ShaderLang.h',
'../include/GLSLANG/ShaderVars.h',
'../include/KHR/khrplatform.h',
'../include/angle_gl.h',
'../include/platform/Platform.h',
],
'libangle_sources':
[
@ -74,6 +76,7 @@
'libANGLE/HandleAllocator.h',
'libANGLE/ImageIndex.h',
'libANGLE/ImageIndex.cpp',
'libANGLE/Platform.cpp',
'libANGLE/Program.cpp',
'libANGLE/Program.h',
'libANGLE/Query.cpp',
@ -426,7 +429,6 @@
'libGLESv2/entry_points_gles_3_0.h',
'libGLESv2/entry_points_gles_3_0_ext.cpp',
'libGLESv2/entry_points_gles_3_0_ext.h',
'libGLESv2/export.h',
'libGLESv2/global_state.cpp',
'libGLESv2/global_state.h',
'libGLESv2/libGLESv2.cpp',

Просмотреть файл

@ -9,9 +9,8 @@
#ifndef LIBGLESV2_ENTRYPOINTSEGL_H_
#define LIBGLESV2_ENTRYPOINTSEGL_H_
#include "libGLESv2/export.h"
#include <EGL/egl.h>
#include <export.h>
namespace egl
{

Просмотреть файл

@ -9,10 +9,9 @@
#ifndef LIBGLESV2_ENTRYPOINTSEGLEXT_H_
#define LIBGLESV2_ENTRYPOINTSEGLEXT_H_
#include "libGLESv2/export.h"
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <export.h>
namespace egl
{

Просмотреть файл

@ -9,9 +9,8 @@
#ifndef LIBGLESV2_ENTRYPOINTGLES20_H_
#define LIBGLESV2_ENTRYPOINTGLES20_H_
#include "libGLESv2/export.h"
#include <GLES2/gl2.h>
#include <export.h>
namespace gl
{

Просмотреть файл

@ -9,10 +9,9 @@
#ifndef LIBGLESV2_ENTRYPOINTGLES20EXT_H_
#define LIBGLESV2_ENTRYPOINTGLES20EXT_H_
#include "libGLESv2/export.h"
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <export.h>
namespace gl
{

Просмотреть файл

@ -9,9 +9,8 @@
#ifndef LIBGLESV2_ENTRYPOINTGLES30_H_
#define LIBGLESV2_ENTRYPOINTGLES30_H_
#include "libGLESv2/export.h"
#include <GLES3/gl3.h>
#include <export.h>
namespace gl
{

Просмотреть файл

@ -9,10 +9,9 @@
#ifndef LIBGLESV2_ENTRYPOINTGLES30EXT_H_
#define LIBGLESV2_ENTRYPOINTGLES30EXT_H_
#include "libGLESv2/export.h"
#include <GLES3/gl3.h>
#include <GLES3/gl3ext.h>
#include <export.h>
namespace gl
{