Skip to content

Commit

Permalink
Merge branch 'mypaint-head', up to commit before first conflicting co…
Browse files Browse the repository at this point in the history
…mmit (48c4995 in MyPaint master)
  • Loading branch information
davissorenson committed Aug 10, 2013
2 parents 644cc9c + 9f8f0e0 commit ab83301
Show file tree
Hide file tree
Showing 70 changed files with 3,610 additions and 1,005 deletions.
2 changes: 1 addition & 1 deletion README.mypaint
Expand Up @@ -45,7 +45,7 @@ Debian users can fetch these dependencies by running:


# apt-get install g++ python-dev python-numpy \ # apt-get install g++ python-dev python-numpy \
libgtk-3-dev python-gi-dev gir1.2-gtk-3.0 python-gi-cairo \ libgtk-3-dev python-gi-dev gir1.2-gtk-3.0 python-gi-cairo \
swig scons gettext libpng12-dev liblcms2-dev swig scons gettext libpng12-dev liblcms2-dev libjson0-dev


Recommended: a pressure sensitive input device (graphic tablet) Recommended: a pressure sensitive input device (graphic tablet)


Expand Down
2 changes: 1 addition & 1 deletion SConstruct
Expand Up @@ -34,7 +34,7 @@ opts.Add(BoolVariable('enable_gegl', 'enable GEGL based code in build', False))
opts.Add(BoolVariable('enable_introspection', 'enable GObject introspection support', False)) opts.Add(BoolVariable('enable_introspection', 'enable GObject introspection support', False))
opts.Add(BoolVariable('enable_docs', 'enable documentation build', False)) opts.Add(BoolVariable('enable_docs', 'enable documentation build', False))
opts.Add(BoolVariable('enable_gperftools', 'enable gperftools in build, for profiling', False)) opts.Add(BoolVariable('enable_gperftools', 'enable gperftools in build, for profiling', False))
opts.Add(BoolVariable('enable_openmp', 'enable OpenMP for libmypaint', False)) opts.Add(BoolVariable('enable_openmp', 'enable OpenMP for multithreaded processing (on by default)', True))
opts.Add('python_binary', 'python executable to build for', default_python_binary) opts.Add('python_binary', 'python executable to build for', default_python_binary)
opts.Add('python_config', 'python-config to used', default_python_config) opts.Add('python_config', 'python-config to used', default_python_config)


Expand Down
1 change: 1 addition & 0 deletions brushlib/libmypaint.c
Expand Up @@ -10,6 +10,7 @@
#include "operationqueue.c" #include "operationqueue.c"
#include "rng-double.c" #include "rng-double.c"
#include "utils.c" #include "utils.c"
#include "tilemap.c"


#include "mypaint.c" #include "mypaint.c"
#include "mypaint-brush.c" #include "mypaint-brush.c"
Expand Down
4 changes: 4 additions & 0 deletions brushlib/mypaint-config.h
Expand Up @@ -5,6 +5,10 @@
#define MYPAINT_TILE_SIZE 64 #define MYPAINT_TILE_SIZE 64
#endif #endif


#ifndef MYPAINT_MAX_THREADS
#define MYPAINT_MAX_THREADS 16
#endif

// Start generated config // Start generated config
#define MYPAINT_CONFIG_USE_GLIB 0 #define MYPAINT_CONFIG_USE_GLIB 0


Expand Down
4 changes: 4 additions & 0 deletions brushlib/mypaint-config.h.in
Expand Up @@ -5,6 +5,10 @@
#define MYPAINT_TILE_SIZE 64 #define MYPAINT_TILE_SIZE 64
#endif #endif


#ifndef MYPAINT_MAX_THREADS
#define MYPAINT_MAX_THREADS 16
#endif

// Start generated config // Start generated config
@DEFINES@ @DEFINES@
// End generated config // End generated config
Expand Down
5 changes: 5 additions & 0 deletions brushlib/mypaint-tiled-surface.c
Expand Up @@ -139,6 +139,11 @@ mypaint_tiled_surface_tile_request_init(MyPaintTiledSurfaceTileRequestData *data
data->readonly = readonly; data->readonly = readonly;
data->buffer = NULL; data->buffer = NULL;
data->context = NULL; data->context = NULL;
#ifdef _OPENMP
data->thread_id = omp_get_thread_num();
#else
data->thread_id = -1;
#endif
} }


// Must be threadsafe // Must be threadsafe
Expand Down
1 change: 1 addition & 0 deletions brushlib/mypaint-tiled-surface.h
Expand Up @@ -16,6 +16,7 @@ typedef struct {
gboolean readonly; gboolean readonly;
guint16 *buffer; guint16 *buffer;
gpointer context; /* Only to be used by the surface implemenations. */ gpointer context; /* Only to be used by the surface implemenations. */
int thread_id;
} MyPaintTiledSurfaceTileRequestData; } MyPaintTiledSurfaceTileRequestData;


void void
Expand Down
18 changes: 18 additions & 0 deletions brushlib/mypaint.c
@@ -1,7 +1,25 @@


#include <mypaint-config.h>

#ifdef _OPENMP
#include <omp.h>
#endif

void
ensure_max_threads_not_exceeded()
{
#ifdef _OPENMP
const int max_threads = omp_get_max_threads();
if (max_threads > MYPAINT_MAX_THREADS) {
omp_set_num_threads(MYPAINT_MAX_THREADS);
}
#endif
}

void void
mypaint_init() mypaint_init()
{ {
ensure_max_threads_not_exceeded();
//bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); //bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
} }


81 changes: 7 additions & 74 deletions brushlib/operationqueue.c
Expand Up @@ -22,14 +22,6 @@
#include "operationqueue.h" #include "operationqueue.h"
#include "fifo.h" #include "fifo.h"


// A size of 10 means the map spans x=[-10,9], y=[-10,9]
// The tile with TileIndex (x,y) is stored in the map at offset
// offset=((self->size + y) * rowstride) + (self->size + index.x)
typedef struct {
Fifo **map;
int size;
} TileMap;

struct _OperationQueue { struct _OperationQueue {
TileMap *tile_map; TileMap *tile_map;


Expand All @@ -46,73 +38,14 @@ operation_delete_func(void *user_data) {
} }




TileMap *
tile_map_new(int size)
{
TileMap *self = (TileMap *)malloc(sizeof(TileMap));

self->size = size;
const int map_size = 2*self->size*2*self->size;
self->map = (Fifo **)malloc(map_size*sizeof(Fifo *));
for(int i = 0; i < map_size; i++) {
self->map[i] = NULL;
}

return self;
}

void void
tile_map_free(TileMap *self, gboolean free_items) free_fifo(void *item) {
{ Fifo *op_queue = item;
const int map_size = 2*self->size*2*self->size; if (op_queue) {
if (free_items) { fifo_free(op_queue, operation_delete_func);
for(int i = 0; i < map_size; i++) {
Fifo *op_queue = self->map[i];
if (op_queue) {
fifo_free(op_queue, operation_delete_func);
}
}
}
free(self->map);

free(self);
}

/* Get the data in the tile map for a given tile @index.
* Must be reentrant and lock-free on different @index */
Fifo **
tile_map_get(TileMap *self, TileIndex index)
{
const int rowstride = self->size*2;
const int offset = ((self->size + index.y) * rowstride) + self->size + index.x;
assert(offset < 2*self->size*2*self->size);
assert(offset >= 0);
return self->map + offset;
}

/* Copy
* The size of @other must be equal or larger to that of @self */
void
tile_map_copy_to(TileMap *self, TileMap *other)
{
assert(other->size >= self->size);

for(int y = -self->size; y < self->size; y++) {
for(int x = -self->size; x < self->size; x++) {
TileIndex index = {x, y};
*tile_map_get(other, index) = *tile_map_get(self, index);
}
} }
} }


/* Must be reentrant and lock-free on different @index */
static gboolean
tile_map_contains(TileMap *self, TileIndex index)
{
return (index.x >= -self->size && index.x < self->size
&& index.y >= -self->size && index.y < self->size);
}

gboolean gboolean
operation_queue_resize(OperationQueue *self, int new_size) operation_queue_resize(OperationQueue *self, int new_size)
{ {
Expand All @@ -128,7 +61,7 @@ operation_queue_resize(OperationQueue *self, int new_size)
} }
return TRUE; return TRUE;
} else { } else {
TileMap *new_tile_map = tile_map_new(new_size); TileMap *new_tile_map = tile_map_new(new_size, sizeof(Fifo *), free_fifo);
const int new_map_size = new_size*2*new_size*2; const int new_map_size = new_size*2*new_size*2;
TileIndex *new_dirty_tiles = (TileIndex *)malloc(new_map_size*sizeof(TileIndex)); TileIndex *new_dirty_tiles = (TileIndex *)malloc(new_map_size*sizeof(TileIndex));


Expand Down Expand Up @@ -245,7 +178,7 @@ operation_queue_add(OperationQueue *self, TileIndex index, OperationDataDrawDab
#endif #endif
} }


Fifo **queue_pointer = tile_map_get(self->tile_map, index); Fifo **queue_pointer = (Fifo **)tile_map_get(self->tile_map, index);
Fifo *op_queue = *queue_pointer; Fifo *op_queue = *queue_pointer;


if (op_queue == NULL) { if (op_queue == NULL) {
Expand Down Expand Up @@ -279,7 +212,7 @@ operation_queue_pop(OperationQueue *self, TileIndex index)
return NULL; return NULL;
} }


Fifo **queue_pointer = tile_map_get(self->tile_map, index); Fifo **queue_pointer = (Fifo **)tile_map_get(self->tile_map, index);
Fifo *op_queue = *queue_pointer; Fifo *op_queue = *queue_pointer;


if (!op_queue) { if (!op_queue) {
Expand Down
6 changes: 1 addition & 5 deletions brushlib/operationqueue.h
Expand Up @@ -2,6 +2,7 @@
#define OPERATIONQUEUE_H #define OPERATIONQUEUE_H


#include <stdint.h> #include <stdint.h>
#include "tilemap.h"


typedef struct { typedef struct {
float x; float x;
Expand All @@ -20,11 +21,6 @@ typedef struct {
float colorize; float colorize;
} OperationDataDrawDab; } OperationDataDrawDab;


typedef struct {
int x;
int y;
} TileIndex;

typedef struct _OperationQueue OperationQueue; typedef struct _OperationQueue OperationQueue;


OperationQueue *operation_queue_new(); OperationQueue *operation_queue_new();
Expand Down
87 changes: 87 additions & 0 deletions brushlib/tilemap.c
@@ -0,0 +1,87 @@
/* brushlib - The MyPaint Brush Library
* Copyright (C) 2012 Jon Nordby <jononor@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include <stdlib.h>
#include <assert.h>

#include "tilemap.h"

TileMap *
tile_map_new(int size, size_t item_size, TileMapItemFreeFunc item_free_func)
{
TileMap *self = (TileMap *)malloc(sizeof(TileMap));

self->size = size;
self->item_size = item_size;
self->item_free_func = item_free_func;
const int map_size = 2*self->size*2*self->size;
self->map = malloc(map_size*self->item_size);
for(int i = 0; i < map_size; i++) {
self->map[i] = NULL;
}

return self;
}

void
tile_map_free(TileMap *self, gboolean free_items)
{
const int map_size = 2*self->size*2*self->size;
if (free_items) {
for(int i = 0; i < map_size; i++) {
self->item_free_func(self->map[i]);
}
}
free(self->map);

free(self);
}

/* Get the data in the tile map for a given tile @index.
* Must be reentrant and lock-free on different @index */
void **
tile_map_get(TileMap *self, TileIndex index)
{
const int rowstride = self->size*2;
const int offset = ((self->size + index.y) * rowstride) + self->size + index.x;
assert(offset < 2*self->size*2*self->size);
assert(offset >= 0);
return self->map + offset;
}

/* Copy
* The size of @other must be equal or larger to that of @self */
void
tile_map_copy_to(TileMap *self, TileMap *other)
{
assert(other->size >= self->size);

for(int y = -self->size; y < self->size; y++) {
for(int x = -self->size; x < self->size; x++) {
TileIndex index = {x, y};
*tile_map_get(other, index) = *tile_map_get(self, index);
}
}
}

/* Must be reentrant and lock-free on different @index */
gboolean
tile_map_contains(TileMap *self, TileIndex index)
{
return (index.x >= -self->size && index.x < self->size
&& index.y >= -self->size && index.y < self->size);
}

58 changes: 58 additions & 0 deletions brushlib/tilemap.h
@@ -0,0 +1,58 @@
/* brushlib - The MyPaint Brush Library
* Copyright (C) 2012 Jon Nordby <jononor@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef TILEMAP_H
#define TILEMAP_H

#include <mypaint-glib-compat.h>

G_BEGIN_DECLS

typedef struct {
int x;
int y;
} TileIndex;

typedef void (*TileMapItemFreeFunc) (void *item_data);

// A size of 10 means the map spans x=[-10,9], y=[-10,9]
// The tile with TileIndex (x,y) is stored in the map at offset
// offset=((self->size + y) * rowstride) + (self->size + index.x)
typedef struct {
void **map;
int size;
size_t item_size;
TileMapItemFreeFunc item_free_func;
} TileMap;

TileMap *
tile_map_new(int size, size_t item_size, TileMapItemFreeFunc item_free_func);

void
tile_map_free(TileMap *self, gboolean free_items);

gboolean
tile_map_contains(TileMap *self, TileIndex index);

void **
tile_map_get(TileMap *self, TileIndex index);

void
tile_map_copy_to(TileMap *self, TileMap *other);

G_END_DECLS

#endif // TILEMAP_H
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ab83301

Please sign in to comment.