Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-pixbuf-cache.h File Reference
#include <gtk/gtk.h>
#include <evince-document.h>
#include <evince-view.h>
+ Include dependency graph for ev-pixbuf-cache.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _EvViewSelection
 

Macros

#define EV_TYPE_PIXBUF_CACHE   (ev_pixbuf_cache_get_type ())
 
#define EV_PIXBUF_CACHE(obj)   (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_PIXBUF_CACHE, EvPixbufCache))
 
#define EV_IS_PIXBUF_CACHE(obj)   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EV_TYPE_PIXBUF_CACHE))
 

Typedefs

typedef struct _EvViewSelection EvViewSelection
 
typedef struct _EvPixbufCache EvPixbufCache
 
typedef struct _EvPixbufCacheClass EvPixbufCacheClass
 

Functions

GType ev_pixbuf_cache_get_type (void) G_GNUC_CONST
 
EvPixbufCacheev_pixbuf_cache_new (GtkWidget *view, EvDocumentModel *model, gsize max_size)
 
void ev_pixbuf_cache_set_max_size (EvPixbufCache *pixbuf_cache, gsize max_size)
 
void ev_pixbuf_cache_set_page_range (EvPixbufCache *pixbuf_cache, gint start_page, gint end_page, GList *selection_list)
 
cairo_surface_t * ev_pixbuf_cache_get_surface (EvPixbufCache *pixbuf_cache, gint page)
 
void ev_pixbuf_cache_clear (EvPixbufCache *pixbuf_cache)
 
void ev_pixbuf_cache_style_changed (EvPixbufCache *pixbuf_cache)
 
void ev_pixbuf_cache_reload_page (EvPixbufCache *pixbuf_cache, cairo_region_t *region, gint page, gint rotation, gdouble scale)
 
void ev_pixbuf_cache_set_inverted_colors (EvPixbufCache *pixbuf_cache, gboolean inverted_colors)
 
cairo_surface_t * ev_pixbuf_cache_get_selection_surface (EvPixbufCache *pixbuf_cache, gint page, gfloat scale)
 
cairo_region_t * ev_pixbuf_cache_get_selection_region (EvPixbufCache *pixbuf_cache, gint page, gfloat scale)
 
void ev_pixbuf_cache_set_selection_list (EvPixbufCache *pixbuf_cache, GList *selection_list)
 
GList * ev_pixbuf_cache_get_selection_list (EvPixbufCache *pixbuf_cache)
 

Macro Definition Documentation

#define EV_IS_PIXBUF_CACHE (   obj)    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EV_TYPE_PIXBUF_CACHE))

Definition at line 40 of file ev-pixbuf-cache.h.

#define EV_PIXBUF_CACHE (   obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_PIXBUF_CACHE, EvPixbufCache))

Definition at line 39 of file ev-pixbuf-cache.h.

#define EV_TYPE_PIXBUF_CACHE   (ev_pixbuf_cache_get_type ())

Definition at line 38 of file ev-pixbuf-cache.h.

Typedef Documentation

typedef struct _EvPixbufCache EvPixbufCache

Definition at line 56 of file ev-pixbuf-cache.h.

Definition at line 57 of file ev-pixbuf-cache.h.

Definition at line 47 of file ev-pixbuf-cache.h.

Function Documentation

void ev_pixbuf_cache_clear ( EvPixbufCache pixbuf_cache)

Definition at line 981 of file ev-pixbuf-cache.c.

982 {
983  int i;
984 
985  if (!pixbuf_cache->job_list)
986  return;
987 
988  for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
989  dispose_cache_job_info (pixbuf_cache->prev_job + i, pixbuf_cache);
990  dispose_cache_job_info (pixbuf_cache->next_job + i, pixbuf_cache);
991  }
992 
993  for (i = 0; i < PAGE_CACHE_LEN (pixbuf_cache); i++) {
994  dispose_cache_job_info (pixbuf_cache->job_list + i, pixbuf_cache);
995  }
996 }

+ Here is the caller graph for this function:

GList* ev_pixbuf_cache_get_selection_list ( EvPixbufCache pixbuf_cache)

Definition at line 1296 of file ev-pixbuf-cache.c.

1297 {
1298  EvViewSelection *selection;
1299  GList *retval = NULL;
1300  int page;
1301  int i;
1302 
1303  g_return_val_if_fail (EV_IS_PIXBUF_CACHE (pixbuf_cache), NULL);
1304 
1305  if (pixbuf_cache->start_page == -1 || pixbuf_cache->end_page == -1)
1306  return NULL;
1307 
1308  /* We check each area to see what needs updating, and what needs freeing; */
1309  page = pixbuf_cache->start_page - pixbuf_cache->preload_cache_size;
1310  for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
1311  if (page < 0) {
1312  page ++;
1313  continue;
1314  }
1315 
1316  if (pixbuf_cache->prev_job[i].selection_points.x1 != -1) {
1317  selection = g_slice_new0 (EvViewSelection);
1318  selection->page = page;
1319  selection->rect = pixbuf_cache->prev_job[i].selection_points;
1320  if (pixbuf_cache->prev_job[i].selection_region)
1321  selection->covered_region = cairo_region_reference (pixbuf_cache->prev_job[i].selection_region);
1322  retval = g_list_prepend (retval, selection);
1323  }
1324 
1325  page ++;
1326  }
1327 
1328  page = pixbuf_cache->start_page;
1329  for (i = 0; i < PAGE_CACHE_LEN (pixbuf_cache); i++) {
1330  if (pixbuf_cache->job_list[i].selection_points.x1 != -1) {
1331  selection = g_slice_new0 (EvViewSelection);
1332  selection->page = page;
1333  selection->rect = pixbuf_cache->job_list[i].selection_points;
1334  if (pixbuf_cache->job_list[i].selection_region)
1335  selection->covered_region = cairo_region_reference (pixbuf_cache->job_list[i].selection_region);
1336  retval = g_list_prepend (retval, selection);
1337  }
1338 
1339  page ++;
1340  }
1341 
1342  for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
1343  if (page >= ev_document_get_n_pages (pixbuf_cache->document))
1344  break;
1345 
1346  if (pixbuf_cache->next_job[i].selection_points.x1 != -1) {
1347  selection = g_slice_new0 (EvViewSelection);
1348  selection->page = page;
1349  selection->rect = pixbuf_cache->next_job[i].selection_points;
1350  if (pixbuf_cache->next_job[i].selection_region)
1351  selection->covered_region = cairo_region_reference (pixbuf_cache->next_job[i].selection_region);
1352  retval = g_list_prepend (retval, selection);
1353  }
1354 
1355  page ++;
1356  }
1357 
1358  return g_list_reverse (retval);
1359 }

+ Here is the caller graph for this function:

cairo_region_t* ev_pixbuf_cache_get_selection_region ( EvPixbufCache pixbuf_cache,
gint  page,
gfloat  scale 
)

Definition at line 1116 of file ev-pixbuf-cache.c.

1119 {
1120  CacheJobInfo *job_info;
1121 
1122  /* the document does not implement the selection interface */
1123  if (!EV_IS_SELECTION (pixbuf_cache->document))
1124  return NULL;
1125 
1126  job_info = find_job_cache (pixbuf_cache, page);
1127  if (job_info == NULL)
1128  return NULL;
1129 
1130  /* No selection on this page */
1131  if (!job_info->points_set)
1132  return NULL;
1133 
1134  /* If we have a running job, we just return what we have under the
1135  * assumption that it'll be updated later and we can scale it as need
1136  * be */
1137  if (job_info->job && EV_JOB_RENDER (job_info->job)->include_selection)
1138  return job_info->selection_region && !cairo_region_is_empty(job_info->selection_region) ?
1139  job_info->selection_region : NULL;
1140 
1141  /* Now, lets see if we need to resize the region. If we do, we clear the
1142  * old one. */
1143  clear_selection_region_if_needed (pixbuf_cache, job_info, page, scale);
1144 
1145  /* Finally, we see if the two scales are the same, and get a new region
1146  * if needed.
1147  */
1148  if (ev_rect_cmp (&(job_info->target_points), &(job_info->selection_region_points))) {
1149  EvRenderContext *rc;
1150  EvPage *ev_page;
1151  gint width, height;
1152 
1154  ev_page = ev_document_get_page (pixbuf_cache->document, page);
1155 
1157  page, scale, 0,
1158  &width, &height);
1159 
1160  rc = ev_render_context_new (ev_page, 0, 0.);
1161  ev_render_context_set_target_size (rc, width, height);
1162  g_object_unref (ev_page);
1163 
1164  if (job_info->selection_region)
1165  cairo_region_destroy (job_info->selection_region);
1166  job_info->selection_region =
1168  rc, job_info->selection_style,
1169  &(job_info->target_points));
1170  job_info->selection_region_points = job_info->target_points;
1171  job_info->selection_region_scale = scale;
1172  g_object_unref (rc);
1174  }
1175  return job_info->selection_region && !cairo_region_is_empty(job_info->selection_region) ?
1176  job_info->selection_region : NULL;
1177 }

+ Here is the caller graph for this function:

cairo_surface_t* ev_pixbuf_cache_get_selection_surface ( EvPixbufCache pixbuf_cache,
gint  page,
gfloat  scale 
)

Definition at line 1039 of file ev-pixbuf-cache.c.

1042 {
1043  CacheJobInfo *job_info;
1044 
1045  /* the document does not implement the selection interface */
1046  if (!EV_IS_SELECTION (pixbuf_cache->document))
1047  return NULL;
1048 
1049  job_info = find_job_cache (pixbuf_cache, page);
1050  if (job_info == NULL)
1051  return NULL;
1052 
1053  /* No selection on this page */
1054  if (!job_info->points_set)
1055  return NULL;
1056 
1057  /* If we have a running job, we just return what we have under the
1058  * assumption that it'll be updated later and we can scale it as need
1059  * be */
1060  if (job_info->job && EV_JOB_RENDER (job_info->job)->include_selection)
1061  return job_info->selection;
1062 
1063  /* Now, lets see if we need to resize the image. If we do, we clear the
1064  * old one. */
1065  clear_selection_surface_if_needed (pixbuf_cache, job_info, page, scale);
1066 
1067  /* Finally, we see if the two scales are the same, and get a new pixbuf
1068  * if needed. We do this synchronously for now. At some point, we
1069  * _should_ be able to get rid of the doc_mutex, so the synchronicity
1070  * doesn't kill us. Rendering a few glyphs should really be fast.
1071  */
1072  if (ev_rect_cmp (&(job_info->target_points), &(job_info->selection_points))) {
1073  EvRectangle *old_points;
1074  GdkColor text, base;
1075  EvRenderContext *rc;
1076  EvPage *ev_page;
1077  gint width, height;
1078 
1079  /* we need to get a new selection pixbuf */
1081  if (job_info->selection_points.x1 < 0) {
1082  g_assert (job_info->selection == NULL);
1083  old_points = NULL;
1084  } else {
1085  old_points = &(job_info->selection_points);
1086  }
1087 
1088  ev_page = ev_document_get_page (pixbuf_cache->document, page);
1090  page,
1091  scale * job_info->device_scale,
1092  0, &width, &height);
1093 
1094  rc = ev_render_context_new (ev_page, 0, scale * job_info->device_scale);
1095  ev_render_context_set_target_size (rc, width, height);
1096  g_object_unref (ev_page);
1097 
1098  get_selection_colors (EV_VIEW (pixbuf_cache->view), &text, &base);
1100  rc, &(job_info->selection),
1101  &(job_info->target_points),
1102  old_points,
1103  job_info->selection_style,
1104  &text, &base);
1105  if (job_info->selection)
1106  set_device_scale_on_surface (job_info->selection, job_info->device_scale);
1107  job_info->selection_points = job_info->target_points;
1108  job_info->selection_scale = scale * job_info->device_scale;
1109  g_object_unref (rc);
1111  }
1112  return job_info->selection;
1113 }

+ Here is the caller graph for this function:

cairo_surface_t* ev_pixbuf_cache_get_surface ( EvPixbufCache pixbuf_cache,
gint  page 
)

Definition at line 906 of file ev-pixbuf-cache.c.

908 {
909  CacheJobInfo *job_info;
910 
911  job_info = find_job_cache (pixbuf_cache, page);
912  if (job_info == NULL)
913  return NULL;
914 
915  if (job_info->page_ready)
916  return job_info->surface;
917 
918  /* We don't need to wait for the idle to handle the callback */
919  if (job_info->job &&
920  EV_JOB_RENDER (job_info->job)->page_ready) {
921  copy_job_to_job_info (EV_JOB_RENDER (job_info->job), job_info, pixbuf_cache);
922  g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region);
923  }
924 
925  return job_info->surface;
926 }

+ Here is the caller graph for this function:

GType ev_pixbuf_cache_get_type ( void  )
EvPixbufCache* ev_pixbuf_cache_new ( GtkWidget *  view,
EvDocumentModel model,
gsize  max_size 
)

Definition at line 230 of file ev-pixbuf-cache.c.

233 {
234  EvPixbufCache *pixbuf_cache;
235 
236  pixbuf_cache = (EvPixbufCache *) g_object_new (EV_TYPE_PIXBUF_CACHE, NULL);
237  /* This is a backlink, so we don't ref this */
238  pixbuf_cache->view = view;
239  pixbuf_cache->model = g_object_ref (model);
240  pixbuf_cache->document = ev_document_model_get_document (model);
241  pixbuf_cache->max_size = max_size;
242 
243  return pixbuf_cache;
244 }

+ Here is the caller graph for this function:

void ev_pixbuf_cache_reload_page ( EvPixbufCache pixbuf_cache,
cairo_region_t *  region,
gint  page,
gint  rotation,
gdouble  scale 
)

Definition at line 1362 of file ev-pixbuf-cache.c.

1367 {
1368  CacheJobInfo *job_info;
1369  gint width, height;
1370 
1371  job_info = find_job_cache (pixbuf_cache, page);
1372  if (job_info == NULL)
1373  return;
1374 
1376  page, scale, rotation,
1377  &width, &height);
1378  add_job (pixbuf_cache, job_info, region,
1379  width, height, page, rotation, scale,
1381 }

+ Here is the caller graph for this function:

void ev_pixbuf_cache_set_inverted_colors ( EvPixbufCache pixbuf_cache,
gboolean  inverted_colors 
)

Definition at line 874 of file ev-pixbuf-cache.c.

876 {
877  gint i;
878 
879  if (pixbuf_cache->inverted_colors == inverted_colors)
880  return;
881 
882  pixbuf_cache->inverted_colors = inverted_colors;
883 
884  for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
885  CacheJobInfo *job_info;
886 
887  job_info = pixbuf_cache->prev_job + i;
888  if (job_info && job_info->surface)
890 
891  job_info = pixbuf_cache->next_job + i;
892  if (job_info && job_info->surface)
894  }
895 
896  for (i = 0; i < PAGE_CACHE_LEN (pixbuf_cache); i++) {
897  CacheJobInfo *job_info;
898 
899  job_info = pixbuf_cache->job_list + i;
900  if (job_info && job_info->surface)
902  }
903 }

+ Here is the caller graph for this function:

void ev_pixbuf_cache_set_max_size ( EvPixbufCache pixbuf_cache,
gsize  max_size 
)

Definition at line 247 of file ev-pixbuf-cache.c.

249 {
250  if (pixbuf_cache->max_size == max_size)
251  return;
252 
253  if (pixbuf_cache->max_size > max_size)
254  ev_pixbuf_cache_clear (pixbuf_cache);
255  pixbuf_cache->max_size = max_size;
256 }

+ Here is the caller graph for this function:

void ev_pixbuf_cache_set_page_range ( EvPixbufCache pixbuf_cache,
gint  start_page,
gint  end_page,
GList *  selection_list 
)

Definition at line 841 of file ev-pixbuf-cache.c.

845 {
846  gdouble scale = ev_document_model_get_scale (pixbuf_cache->model);
847  gint rotation = ev_document_model_get_rotation (pixbuf_cache->model);
848 
849  g_return_if_fail (EV_IS_PIXBUF_CACHE (pixbuf_cache));
850 
851  g_return_if_fail (start_page >= 0 && start_page < ev_document_get_n_pages (pixbuf_cache->document));
852  g_return_if_fail (end_page >= 0 && end_page < ev_document_get_n_pages (pixbuf_cache->document));
853  g_return_if_fail (end_page >= start_page);
854 
855  pixbuf_cache->scroll_direction = ev_pixbuf_cache_get_scroll_direction (pixbuf_cache, start_page, end_page);
856 
857  /* First, resize the page_range as needed. We cull old pages
858  * mercilessly. */
859  ev_pixbuf_cache_update_range (pixbuf_cache, start_page, end_page, rotation, scale);
860 
861  /* Then, we update the current jobs to see if any of them are the wrong
862  * size, we remove them if we need to. */
863  ev_pixbuf_cache_clear_job_sizes (pixbuf_cache, scale);
864 
865  /* Next, we update the target selection for our pages */
866  ev_pixbuf_cache_set_selection_list (pixbuf_cache, selection_list);
867 
868  /* Finally, we add the new jobs for all the sizes that don't have a
869  * pixbuf */
870  ev_pixbuf_cache_add_jobs_if_needed (pixbuf_cache, rotation, scale);
871 }

+ Here is the caller graph for this function:

void ev_pixbuf_cache_set_selection_list ( EvPixbufCache pixbuf_cache,
GList *  selection_list 
)

Definition at line 1210 of file ev-pixbuf-cache.c.

1212 {
1213  EvViewSelection *selection;
1214  GList *list = selection_list;
1215  int page;
1216  int i;
1217 
1218  g_return_if_fail (EV_IS_PIXBUF_CACHE (pixbuf_cache));
1219 
1220  if (!EV_IS_SELECTION (pixbuf_cache->document))
1221  return;
1222 
1223  if (pixbuf_cache->start_page == -1 || pixbuf_cache->end_page == -1)
1224  return;
1225 
1226  /* We check each area to see what needs updating, and what needs freeing; */
1227  page = pixbuf_cache->start_page - pixbuf_cache->preload_cache_size;
1228  for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
1229  if (page < 0) {
1230  page ++;
1231  continue;
1232  }
1233 
1234  selection = NULL;
1235  while (list) {
1236  if (((EvViewSelection *)list->data)->page == page) {
1237  selection = list->data;
1238  break;
1239  } else if (((EvViewSelection *)list->data)->page > page)
1240  break;
1241  list = list->next;
1242  }
1243 
1244  if (selection)
1245  update_job_selection (pixbuf_cache->prev_job + i, selection);
1246  else
1247  clear_job_selection (pixbuf_cache->prev_job + i);
1248  page ++;
1249  }
1250 
1251  page = pixbuf_cache->start_page;
1252  for (i = 0; i < PAGE_CACHE_LEN (pixbuf_cache); i++) {
1253  selection = NULL;
1254  while (list) {
1255  if (((EvViewSelection *)list->data)->page == page) {
1256  selection = list->data;
1257  break;
1258  } else if (((EvViewSelection *)list->data)->page > page)
1259  break;
1260  list = list->next;
1261  }
1262 
1263  if (selection)
1264  update_job_selection (pixbuf_cache->job_list + i, selection);
1265  else
1266  clear_job_selection (pixbuf_cache->job_list + i);
1267  page ++;
1268  }
1269 
1270  for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
1271  if (page >= ev_document_get_n_pages (pixbuf_cache->document))
1272  break;
1273 
1274  selection = NULL;
1275  while (list) {
1276  if (((EvViewSelection *)list->data)->page == page) {
1277  selection = list->data;
1278  break;
1279  } else if (((EvViewSelection *)list->data)->page > page)
1280  break;
1281  list = list->next;
1282  }
1283 
1284  if (selection)
1285  update_job_selection (pixbuf_cache->next_job + i, selection);
1286  else
1287  clear_job_selection (pixbuf_cache->next_job + i);
1288  page ++;
1289  }
1290 }

+ Here is the caller graph for this function:

void ev_pixbuf_cache_style_changed ( EvPixbufCache pixbuf_cache)

Definition at line 1000 of file ev-pixbuf-cache.c.

1001 {
1002  gint i;
1003 
1004  if (!pixbuf_cache->job_list)
1005  return;
1006 
1007  /* FIXME: doesn't update running jobs. */
1008  for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
1009  CacheJobInfo *job_info;
1010 
1011  job_info = pixbuf_cache->prev_job + i;
1012  if (job_info->selection) {
1013  cairo_surface_destroy (job_info->selection);
1014  job_info->selection = NULL;
1015  job_info->selection_points.x1 = -1;
1016  }
1017 
1018  job_info = pixbuf_cache->next_job + i;
1019  if (job_info->selection) {
1020  cairo_surface_destroy (job_info->selection);
1021  job_info->selection = NULL;
1022  job_info->selection_points.x1 = -1;
1023  }
1024  }
1025 
1026  for (i = 0; i < PAGE_CACHE_LEN (pixbuf_cache); i++) {
1027  CacheJobInfo *job_info;
1028 
1029  job_info = pixbuf_cache->job_list + i;
1030  if (job_info->selection) {
1031  cairo_surface_destroy (job_info->selection);
1032  job_info->selection = NULL;
1033  job_info->selection_points.x1 = -1;
1034  }
1035  }
1036 }

+ Here is the caller graph for this function: