home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / liblayer / src / cl_drwbl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.1 KB  |  212 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. #include "xp_mem.h"             /* For XP_NEW_ZAP */
  20. #include "xpassert.h"           /* For XP_ASSERT, et al */
  21. #include "cl_priv.h"
  22.  
  23. CL_Drawable *
  24. CL_NewDrawable(uint width, uint height, uint32 flags,
  25.                CL_DrawableVTable *vtable,
  26.                void *client_data)
  27. {
  28.     CL_Drawable *cl_drawable = XP_NEW_ZAP(CL_Drawable);
  29.     if (! client_data)
  30.         return NULL;
  31.     
  32.     cl_drawable->width   = width;
  33.     cl_drawable->height  = height;
  34.     cl_drawable->flags   = flags;
  35.     
  36.     if (vtable)
  37.         cl_drawable->vtable = *vtable;
  38.  
  39.     cl_drawable->client_data = client_data;
  40.  
  41.     return cl_drawable;
  42. }
  43.  
  44. /* Most of the following functions could be successfully turned into
  45.    macros, so perhaps this level of abstraction is excessive */
  46.  
  47. void
  48. CL_DestroyDrawable(CL_Drawable *drawable)
  49. {
  50.     if (drawable->vtable.destroy_func)
  51.         (*drawable->vtable.destroy_func)(drawable);
  52.     XP_FREE(drawable);
  53. }
  54.  
  55. void *CL_GetDrawableClientData(CL_Drawable *drawable)
  56. {
  57.     return drawable->client_data;
  58. }
  59.  
  60. void
  61. cl_SetDrawableOrigin(CL_Drawable *drawable, int32 x_offset, int32 y_offset)
  62. {
  63.     drawable->x_offset = x_offset;
  64.     drawable->y_offset = y_offset;
  65.     if (drawable->vtable.set_origin_func)
  66.         (*drawable->vtable.set_origin_func)(drawable,
  67.                                             x_offset, y_offset);
  68. }
  69.  
  70. void
  71. cl_GetDrawableOrigin(CL_Drawable *drawable, int32 *x_offset, int32 *y_offset)
  72. {
  73.     if (drawable->vtable.get_origin_func)
  74.         (*drawable->vtable.get_origin_func)(drawable,
  75.                                             x_offset, y_offset);
  76.     else {
  77.         *x_offset = drawable->x_offset;
  78.         *y_offset = drawable->y_offset;
  79.     }
  80. }
  81.  
  82. void
  83. cl_InitDrawable(CL_Drawable *drawable)
  84. {
  85.     if (drawable->vtable.init_func)
  86.         (*drawable->vtable.init_func)(drawable);
  87. }
  88.  
  89. void 
  90. cl_RelinquishDrawable(CL_Drawable *drawable)
  91. {
  92.     if (drawable->vtable.relinquish_func)
  93.         (*drawable->vtable.relinquish_func)(drawable);
  94. }
  95.  
  96. void
  97. cl_SetDrawableClip(CL_Drawable *drawable, FE_Region clip_region)
  98. {
  99.     drawable->clip_region = clip_region;
  100.     if (drawable->vtable.set_clip_func)
  101.         (*drawable->vtable.set_clip_func)(drawable, clip_region);
  102. }
  103.  
  104. void    
  105. cl_RestoreDrawableClip(CL_Drawable *drawable)
  106. {
  107.     drawable->clip_region = NULL;
  108.     if (drawable->vtable.restore_clip_func)
  109.         (*drawable->vtable.restore_clip_func)(drawable);
  110. }
  111.  
  112. CL_Drawable *
  113. cl_LockDrawableForRead(CL_Drawable *drawable)
  114. {
  115.     if (drawable->vtable.lock_func) {
  116.         if (! (*drawable->vtable.lock_func)(drawable,
  117.                                             CL_LOCK_DRAWABLE_FOR_READ))
  118.             return NULL;
  119.     }
  120.     return drawable;
  121. }
  122.  
  123. CL_Drawable *
  124. cl_LockDrawableForReadWrite(CL_Drawable *drawable)
  125. {
  126.     if (drawable->vtable.lock_func) {
  127.         if (! (*drawable->vtable.lock_func)(drawable,
  128.                                             CL_LOCK_DRAWABLE_FOR_READ_WRITE))
  129.             return NULL;
  130.     }
  131.     return drawable;
  132. }
  133.  
  134. CL_Drawable *
  135. cl_LockDrawableForWrite(CL_Drawable *drawable)
  136. {
  137.     if (drawable->vtable.lock_func) {
  138.         if (! (*drawable->vtable.lock_func)(drawable,
  139.                                           CL_LOCK_DRAWABLE_FOR_WRITE))
  140.             return NULL;
  141.     }
  142.     return drawable;
  143. }
  144.  
  145. void    
  146. cl_UnlockDrawable(CL_Drawable *drawable)
  147. {
  148.     if (drawable->vtable.lock_func) {
  149.         (*drawable->vtable.lock_func)(drawable,
  150.                                       CL_UNLOCK_DRAWABLE);
  151.     }
  152. }
  153.  
  154. void
  155. cl_CopyPixels(CL_Drawable *src, CL_Drawable *dest, FE_Region region)
  156. {
  157.     XP_ASSERT(src);
  158.     XP_ASSERT(dest);
  159.     
  160.     if (!src || !dest)
  161.         return;
  162.     
  163.     XP_ASSERT(dest->vtable.copy_pixels_func);
  164.     if (src->vtable.copy_pixels_func) 
  165.         (*src->vtable.copy_pixels_func)(src, dest,
  166.                                         region);
  167. }
  168.  
  169. void
  170. cl_SetDrawableDimensions(CL_Drawable *drawable, uint32 width, uint32 height)
  171. {
  172.     if (!drawable)
  173.         return;
  174.     if (drawable->vtable.set_dimensions_func) 
  175.         (*drawable->vtable.set_dimensions_func)(drawable,
  176.                                                 width, height);
  177. }
  178.  
  179. /* This function indicates whether or not a given rectangle is painted
  180.    with a single, uniform color and, if so, returns the color.  NULL
  181.    is returned if the area contains more than one color.  This
  182.    function must only be called during drawing. */
  183. CL_Color *
  184. CL_GetDrawableBgColor(CL_Drawable *drawable, XP_Rect *win_rect)
  185. {
  186.     CL_Layer *layer;
  187.     CL_Compositor *compositor = drawable->compositor;
  188.  
  189.     /* A background color is only valid during the draw of a given layer */
  190.     XP_ASSERT(compositor->composite_in_progress);
  191.     if (!compositor->composite_in_progress)
  192.         return NULL;
  193.  
  194.     /* Loop in front-to-back order over uniformly colored layers */
  195.     layer = compositor->uniformly_colored_layer_stack;
  196.     while (layer) {
  197.         XP_Rect *layer_win_rect = &layer->win_clipped_bbox;
  198.         XP_Rect overlap;
  199.  
  200.         XP_IntersectRect(layer_win_rect, win_rect, &overlap);
  201.         if (!XP_IsEmptyRect(&overlap)) {
  202.             if (XP_RectContainsRect(layer_win_rect, win_rect)) {
  203.                 return layer->uniform_color;
  204.             } else {
  205.                 return NULL;
  206.             }
  207.         }
  208.         layer = layer->uniformly_colored_layer_below;
  209.     }
  210.     return NULL;
  211. }
  212.