Skip to content

Instantly share code, notes, and snippets.

@maks
Last active December 25, 2015 07:29
Show Gist options
  • Select an option

  • Save maks/6939475 to your computer and use it in GitHub Desktop.

Select an option

Save maks/6939475 to your computer and use it in GitHub Desktop.
profiler wrapper for pixman
#include <GeckoProfilerFunc.h>
//~ #include <GeckoProfiler.h>
#include "profiler-wrapper.h"
extern "C"
{
void* moz_call_enter(const char *aInfo, uint32_t line) {
return mozilla_sampler_call_enter(aInfo, NULL, false, line);
}
void moz_call_exit(void* handle) {
mozilla_sampler_call_exit(handle);
}
//~ void mks_profile() {
//~ PROFILER_LABEL("PIXMAN", "lookup_composite");
//~ }
}
// Returns a handle to pass on exit. This can check that we are popping the
// correct callstack.
#ifdef __cplusplus
extern "C" {
#endif
void* moz_call_enter(const char *aInfo, uint32_t line);
void moz_call_exit(void* handle);
//~ void mks_profile();
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
static void
dummy_composite_rect (pixman_implementation_t *imp,
pixman_composite_info_t *info)
{
}
void
_pixman_implementation_lookup_composite (pixman_implementation_t *toplevel,
pixman_op_t op,
pixman_format_code_t src_format,
uint32_t src_flags,
pixman_format_code_t mask_format,
uint32_t mask_flags,
pixman_format_code_t dest_format,
uint32_t dest_flags,
pixman_implementation_t **out_imp,
pixman_composite_func_t *out_func)
{
//__android_log_print(ANDROID_LOG_DEBUG,"MAKS", "lookup composite op:%d src:%d flags: %d", op, src_format, src_flags);
void* sampleHandle = moz_call_enter("PIXMAN:lookup_composite", 90);
//~ mks_profile();
pixman_implementation_t *imp;
cache_t *cache;
int i;
/* Check cache for fast paths */
cache = PIXMAN_GET_THREAD_LOCAL (fast_path_cache);
for (i = 0; i < N_CACHED_FAST_PATHS; ++i)
{
const pixman_fast_path_t *info = &(cache->cache[i].fast_path);
/* Note that we check for equality here, not whether
* the cached fast path matches. This is to prevent
* us from selecting an overly general fast path
* when a more specific one would work.
*/
if (info->op == op &&
info->src_format == src_format &&
info->mask_format == mask_format &&
info->dest_format == dest_format &&
info->src_flags == src_flags &&
info->mask_flags == mask_flags &&
info->dest_flags == dest_flags &&
info->func)
{
*out_imp = cache->cache[i].imp;
*out_func = cache->cache[i].fast_path.func;
goto update_cache;
}
}
for (imp = toplevel; imp != NULL; imp = imp->fallback)
{
const pixman_fast_path_t *info = imp->fast_paths;
while (info->op != PIXMAN_OP_NONE)
{
if ((info->op == op || info->op == PIXMAN_OP_any) &&
/* Formats */
((info->src_format == src_format) ||
(info->src_format == PIXMAN_any)) &&
((info->mask_format == mask_format) ||
(info->mask_format == PIXMAN_any)) &&
((info->dest_format == dest_format) ||
(info->dest_format == PIXMAN_any)) &&
/* Flags */
(info->src_flags & src_flags) == info->src_flags &&
(info->mask_flags & mask_flags) == info->mask_flags &&
(info->dest_flags & dest_flags) == info->dest_flags)
{
*out_imp = imp;
*out_func = info->func;
/* Set i to the last spot in the cache so that the
* move-to-front code below will work
*/
i = N_CACHED_FAST_PATHS - 1;
goto update_cache;
}
++info;
}
}
/* We should never reach this point */
_pixman_log_error (
FUNC,
"No composite function found\n"
"\n"
"The most likely cause of this is that this system has issues with\n"
"thread local storage\n");
*out_imp = NULL;
*out_func = dummy_composite_rect;
moz_call_exit(sampleHandle);
return;
update_cache:
if (i)
{
while (i--)
cache->cache[i + 1] = cache->cache[i];
cache->cache[0].imp = *out_imp;
cache->cache[0].fast_path.op = op;
cache->cache[0].fast_path.src_format = src_format;
cache->cache[0].fast_path.src_flags = src_flags;
cache->cache[0].fast_path.mask_format = mask_format;
cache->cache[0].fast_path.mask_flags = mask_flags;
cache->cache[0].fast_path.dest_format = dest_format;
cache->cache[0].fast_path.dest_flags = dest_flags;
cache->cache[0].fast_path.func = *out_func;
}
moz_call_exit(sampleHandle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment