home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / liblayer / src / cl_priv.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  12.4 KB  |  282 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /* 
  19.  *  cl_priv.h Private prototypes, definitions, etc.
  20.  */
  21.  
  22.  
  23. #ifndef _CL_PRIV_H_
  24. #define _CL_PRIV_H_
  25.  
  26. /***************** Configuration *******************/
  27. #define CL_GROUP_HASH_TABLE_SIZE 10
  28.  
  29. #define CL_THREAD_SAFE 1
  30.  
  31. /* Adjust frame-rate to CPU capacity */
  32. #define CL_ADAPT_FRAME_RATE
  33.  
  34. /* Auto-adaptive frame-rate parameters, in frames per second */
  35. #define CL_FRAME_RATE_MAX       60
  36. #define CL_FRAME_RATE_MIN        8
  37. #define CL_FRAME_RATE_INITIAL   15
  38.  
  39. #define CL_CPU_LOAD           0.90
  40. #define CL_MIN_TIMEOUT           1 /* No matter what, leave at least this many
  41.                                       milliseconds between the end of
  42.                                       one compositor run and the start
  43.                                       of the next */
  44. #define LOG2_DELAY_LINE_LENGTH   5 /* 2^5 == 32, Adaptation filter maximum length */
  45. #define DELAY_LINE_LENGTH       (1 << LOG2_DELAY_LINE_LENGTH)
  46. #define SLOW_FILTER_DURATION   300 /* Time, in milliseconds, over which filter runs */
  47.  
  48. #include "fe_rgn.h"
  49. #include "xp_rect.h"
  50. #include "plhash.h"
  51. #include "layers.h"
  52. #ifdef CL_THREAD_SAFE
  53. #    include "prmon.h"
  54. #endif
  55.  
  56.  
  57. /******************Definitions and Types************/
  58.  
  59. #ifdef CL_THREAD_SAFE
  60. #    define LOCK_COMPOSITOR(compositor) PR_EnterMonitor(compositor->monitor)
  61. #else
  62. #    define LOCK_COMPOSITOR(compositor)
  63. #endif
  64.  
  65. #ifdef CL_THREAD_SAFE
  66. #    define UNLOCK_COMPOSITOR(compositor) PR_ExitMonitor(compositor->monitor)
  67. #else
  68. #    define UNLOCK_COMPOSITOR(compositor)
  69. #endif
  70.  
  71. /* XXX - bit of a race condition ? */
  72. #define LOCK_LAYERS(layer)                                                     \
  73.    do {if (layer->compositor) LOCK_COMPOSITOR(layer->compositor);} while(0)
  74.  
  75. #define UNLOCK_LAYERS(layer)                                                   \
  76.    do {if (layer->compositor) UNLOCK_COMPOSITOR(layer->compositor);} while (0)
  77.  
  78.  
  79. #define CL_CONTAINMENT_LIST_SIZE 20
  80. #define CL_CONTAINMENT_LIST_INCREMENT 5
  81. #define CL_NEXT_CONTAINMENT_LIST(i) (((i) + 1) % 2)
  82.  
  83. extern int cl_trace_level;
  84.  
  85. #ifdef DEBUG
  86. #    define CL_TRACE(l,t) {if(cl_trace_level > l) {XP_TRACE(t);}}
  87. #else
  88. #    define CL_TRACE(l,t) {}
  89. #endif
  90.  
  91. typedef enum 
  92. {
  93.     CL_REACHED_NOTHING,
  94.     CL_REACHED_BOTTOM_UNDRAWN,
  95.     CL_REACHED_TOP_UNDRAWN
  96. } CL_BackToFrontStatus;
  97.  
  98.  
  99. /* 
  100.  * The CL_Layer "class". It's opaque as far as everyone else
  101.  * is concerned.
  102.  */
  103. struct CL_Layer {
  104.     char *name;               /* For reference via HTML/JavaScript */
  105.     XP_Rect bbox;             /* Bounds of clipping rectangle,
  106.                  in layer's coordinates */
  107.     XP_Rect clipped_bbox;     /* Position and dimensions of visible
  108.                                  portion of layer, in document coordinates */
  109.     int32 x_origin;           /* Origin of layer, in doc coordinates */
  110.     int32 y_origin;
  111.     int32 x_offset;           /* Origin of layer, in parent layer coordinates */
  112.     int32 y_offset;
  113.     int32 z_index;          /* Relative z-ordering among layers */
  114.     CL_LayerVTable vtable;    /* Layer-specific virtual "methods" */
  115.     PRPackedBool visible;     /* Is layer considered visible for compositing ?*/
  116.     PRPackedBool descendant_visible;
  117.     PRPackedBool hidden;      /* Turn off drawing for this layer & children */
  118.     PRPackedBool clip_children; /* Clip drawing of descendent layers */
  119.     PRPackedBool clip_self;   /* Clip drawing of this layer ? */
  120.     PRPackedBool prefer_draw_offscreen; /* Prefer draw directly to a pixmap ? */
  121.     PRPackedBool prefer_draw_onscreen; /* Prefer not to use backing store */
  122.     PRPackedBool scrolling;   /* Should this layer be scrolled with the page */
  123.     PRPackedBool opaque;      /* Does this layer have no transparent areas ? */
  124.     PRPackedBool enumerated;
  125.     PRPackedBool cutout;
  126.     PRPackedBool override_inherit_visibility; /* Child visibility is independent 
  127.                                                  of parent's */
  128.     CL_Color *uniform_color;  /* If non-null, layer is solid, uniform color */
  129.     void *client_data;        /* Custom data field */
  130.     CL_Compositor *compositor;/* Back-pointer from a layer to its compositor */
  131.     CL_Layer *parent;         /* Parent of this layer */
  132.     CL_Layer *sib_above;      /* Sibling layer above this one */
  133.     CL_Layer *sib_below;      /* Sibling layer below this one */
  134.     CL_Layer *top_child;      /* Uppermost child layer */
  135.     CL_Layer *bottom_child;   /* Lowermost child layer  */
  136.     void *mocha_object;       /* FIXME - temporary */
  137.  
  138.     /* Temporary flags used during drawing. Only valid if layer is visible. */
  139.     PRPackedBool offscreen_layer_drawn_above;
  140.     PRPackedBool draw_needed; 
  141.     PRPackedBool descendant_draw_needed;
  142.  
  143.     /* The following variables represent the state of this layer during
  144.        the previous composite cycle. */
  145.     PRPackedBool prev_visible;
  146.     XP_Rect prev_clipped_bbox;
  147.     int32 prev_x_origin;
  148.     int32 prev_y_origin;
  149.  
  150.     XP_Rect win_clipped_bbox; /* Temporary rectangle used during drawing,
  151.                                  contains clipped_bbox in window coordinates,
  152.                                  clipped by window rectangle. */
  153.     FE_Region draw_region;  /* Temporary region used during drawing.
  154.                                Holds the region of the layer to be
  155.                                drawn as calculated during the front-to-back
  156.                                pass. */
  157.     CL_Layer *uniformly_colored_layer_below; /* Only set for opaque,
  158.                                                 solid-colored layers */
  159. };
  160.  
  161. /*
  162.  * These lists are used for mouse enter/leave event handling. Each list
  163.  * holds a path starting from a layer up to the root of the layer tree.
  164.  * This list is held for the last mouse event grabber. If the mouse moves
  165.  * and there's a new mouse event grabber, we create such a list for the
  166.  * new grabber. The determination of which layers get mouse enter and leave
  167.  * events is done by tracing down the two lists from the root down. A
  168.  * better explanation of this can be found in the source.
  169.  */
  170. typedef struct CL_EventContainmentList {
  171.     CL_Layer **layer_list;
  172.     int32 list_size;
  173.     int32 list_head;
  174. } CL_EventContainmentList;
  175.  
  176. /* 
  177.  * The CL_Compositor "class". It's opaque as far as everyone else
  178.  * is concerned.
  179.  */
  180. struct CL_Compositor {
  181.     uint32 gen_id;                   /* Generation id of the compositor */
  182.     CL_Drawable *primary_drawable;   /* Destination window/offscreen-pixmap */
  183.     CL_Drawable *backing_store;      /* Offscreen pixmap */
  184.     void *composite_timeout;         /* Timer used to schedule compositor  */    
  185.     int32 x_offset, y_offset;        /* Window origin in document coordinates */
  186.     XP_Rect window_size;             /* The rectangle we're compositing  */
  187.     FE_Region window_region;         /* The corresponding region         */
  188.     FE_Region update_region;         /* Region to be drawn at next composite */
  189.     FE_Region backing_store_region;  /* Valid area in backing store */
  190.     FE_Region cutout_region;         /* Temporary region used during
  191.                     drawing.  Holds the region of
  192.                     the window which is considered
  193.                     to be out of bounds for the
  194.                     compositor, e.g.  a native
  195.                     window object, such as an
  196.                     applet */
  197.     CL_Layer *root;                  /* The root of the layer tree */
  198.     PRPackedBool recompute_update_region; /* Has any descendant layer
  199.                                              had its visibility, bbox,
  200.                                              or position modified ? */
  201.     PRPackedBool enabled;            /* Should the compositor draw */
  202.     PRPackedBool back_to_front_only; /* No front-to-back compositing */
  203.     PRPackedBool offscreen_enabled;  /* If PR_FALSE, no offscreen compositing */
  204.     PRPackedBool offscreen_inhibited;/* If PR_TRUE, no offscreen compositing */
  205.     PRPackedBool offscreen_initialized;/* PR_TRUE, if cl_InitDrawable() called */
  206.     
  207.     /* Adaptive frame-rate state variables */
  208.     float frame_period;              /* in milliseconds */
  209.     int32 delay_line[DELAY_LINE_LENGTH]; /* Samples of lateness at intervals */
  210.     unsigned int delay_line_index;   /* Index into delay_line */
  211.     int64 nominal_deadline64;        /* Next time compositor should draw */
  212.  
  213.     PRHashTable *group_table;        /* Hash table of groups */
  214.     CL_Layer *mouse_event_grabber;   /* This layer gets all mouse events */
  215.     CL_Layer *key_event_grabber;     /* This layer gets all key events */
  216.     int32 last_mouse_x;              /* The last position of the mouse */
  217.     int32 last_mouse_y;
  218.     int32 last_mouse_button;         /* The last mouse button pressed */
  219.     CL_Layer *last_mouse_event_grabber; /* The last layer to grab a mouse event */
  220.     CL_EventContainmentList event_containment_lists[2];  
  221.                                     /* Lists used to trace event containment */
  222.     int32 last_containment_list;    /* Which list was used last */
  223.  
  224.     CL_KeyboardFocusPolicy focus_policy; /* Policy for default keyboard focus */
  225.     PRBool composite_in_progress;
  226.     CL_Layer *uniformly_colored_layer_stack; /* Topmost uniformly-colored layer */
  227. #ifdef CL_THREAD_SAFE
  228.     PRMonitor *monitor;              /* Ensures thread-safety */
  229. #endif
  230.     uint32 nothing_to_do_count;      /* how many times we had nothing to do */
  231. };
  232.  
  233. /* This represents the target of compositor drawing (either a window
  234.    or an off-screen pixmap).  If the drawable is a window, it may have
  235.    a backing store. */
  236. struct CL_Drawable
  237. {
  238.     CL_Compositor *compositor;
  239.     CL_DrawableVTable vtable;   /* Drawable-specific virtual "methods" */
  240.     void *client_data;          /* Handle to platform-private data */
  241.     FE_Region clip_region;      /* All drawing is clipped by this region,
  242.                                    specified in window coordinates */
  243.     uint32 flags;               /* CL_OFFSCREEN, CL_BACKING_STORE, etc. */
  244.     int32 x_offset;             /* Coordinate system origin in document coord */
  245.     int32 y_offset;
  246.     uint16 width;               /* Width and height, in pixels */
  247.     uint16 height;
  248. };
  249.  
  250. extern void cl_LayerAdded(CL_Compositor *compositor, CL_Layer *layer);
  251. extern void cl_LayerRemoved(CL_Compositor *compositor, CL_Layer *layer);
  252. extern void cl_LayerMoved(CL_Compositor *compositor, CL_Layer *layer);
  253. extern void cl_LayerDestroyed(CL_Compositor *compositor, CL_Layer *layer);
  254. extern void cl_ParentChanged(CL_Layer *layer);
  255. extern void cl_UpdateLayer(CL_Layer *layer, PRBool composite_now);
  256. extern void cl_SetCompositorRecursive(CL_Layer *layer, 
  257.                                       CL_Compositor *compositor);
  258.  
  259. extern void cl_InitDrawable(CL_Drawable *drawable);
  260. extern void cl_RelinquishDrawable(CL_Drawable *drawable);
  261. extern void cl_SetDrawableOrigin(CL_Drawable *drawable,
  262.                                  int32 x_offset, int32 y_offset);
  263. extern void cl_GetDrawableOrigin(CL_Drawable *drawable,
  264.                                  int32* x_offset, int32* y_offset);
  265. extern void cl_SetDrawableClip(CL_Drawable *drawable, FE_Region clip_region);
  266. extern void cl_RestoreDrawableClip(CL_Drawable *drawable);
  267. extern CL_Drawable *cl_LockDrawableForReadWrite(CL_Drawable *drawable);
  268. extern CL_Drawable *cl_LockDrawableForWrite(CL_Drawable *drawable);
  269. extern CL_Drawable *cl_LockDrawableForRead(CL_Drawable *drawable);
  270. extern void cl_UnlockDrawable(CL_Drawable *drawable);
  271. extern void cl_CopyPixels(CL_Drawable *src, CL_Drawable *dest, FE_Region region);
  272. extern void cl_SetDrawableDimensions(CL_Drawable *drawable,
  273.                                      uint32 width, uint32 height);
  274.  
  275. extern void cl_XorRegion(FE_Region src1, FE_Region src2, FE_Region dst);
  276. extern void cl_sanitize_bbox(XP_Rect *bbox);
  277. extern void cl_start_compositor_timeouts(CL_Compositor *compositor);
  278.  
  279.  
  280. #endif /* _CL_PRIV_H_ */
  281.  
  282.