Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
  4.  * All Rights Reserved.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice (including the
  15.  * next paragraph) shall be included in all copies or substantial portions
  16.  * of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21.  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  22.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  *
  26.  **************************************************************************/
  27.  
  28. #ifndef STW_FRAMEBUFFER_H
  29. #define STW_FRAMEBUFFER_H
  30.  
  31. #include <windows.h>
  32.  
  33. #include "os/os_thread.h"
  34.  
  35. struct pipe_resource;
  36. struct st_framebuffer_iface;
  37. struct stw_pixelformat_info;
  38.  
  39. /**
  40.  * Windows framebuffer.
  41.  */
  42. struct stw_framebuffer
  43. {
  44.    /**
  45.     * This mutex has two purposes:
  46.     * - protect the access to the mutable data members below
  47.     * - prevent the framebuffer from being deleted while being accessed.
  48.     *
  49.     * It is OK to lock this mutex while holding the stw_device::fb_mutex lock,
  50.     * but the opposite must never happen.
  51.     */
  52.    pipe_mutex mutex;
  53.    
  54.    /*
  55.     * Immutable members.
  56.     *
  57.     * Note that even access to immutable members implies acquiring the mutex
  58.     * above, to prevent the framebuffer from being destroyed.
  59.     */
  60.    
  61.    HWND hWnd;
  62.  
  63.    int iPixelFormat;
  64.    const struct stw_pixelformat_info *pfi;
  65.  
  66.    /* A pixel format that can be used by GDI */
  67.    int iDisplayablePixelFormat;
  68.    boolean bPbuffer;
  69.  
  70.    struct st_framebuffer_iface *stfb;
  71.  
  72.    /*
  73.     * Mutable members.
  74.     */
  75.  
  76.    unsigned refcnt;
  77.  
  78.    
  79.    /* FIXME: Make this work for multiple contexts bound to the same framebuffer */
  80.    boolean must_resize;
  81.  
  82.    boolean minimized;  /**< Is the window currently minimized? */
  83.  
  84.    unsigned width;
  85.    unsigned height;
  86.    
  87.    /**
  88.     * Client area rectangle, relative to the window upper-left corner.
  89.     *
  90.     * @sa GLCBPRESENTBUFFERSDATA::rect.
  91.     */
  92.    RECT client_rect;
  93.  
  94.    HANDLE hSharedSurface;
  95.    struct stw_shared_surface *shared_surface;
  96.  
  97.    /**
  98.     * This is protected by stw_device::fb_mutex, not the mutex above.
  99.     *
  100.     * Deletions must be done by first acquiring stw_device::fb_mutex, and then
  101.     * acquiring the stw_framebuffer::mutex of the framebuffer to be deleted.
  102.     * This ensures that nobody else is reading/writing to the.
  103.     *
  104.     * It is not necessary to aquire the mutex above to navigate the linked list
  105.     * given that deletions are done with stw_device::fb_mutex held, so no other
  106.     * thread can delete.
  107.     */
  108.    struct stw_framebuffer *next;
  109. };
  110.  
  111.  
  112. /**
  113.  * Create a new framebuffer object which will correspond to the given HDC.
  114.  *
  115.  * This function will acquire stw_framebuffer::mutex. stw_framebuffer_release
  116.  * must be called when done
  117.  */
  118. struct stw_framebuffer *
  119. stw_framebuffer_create(
  120.    HDC hdc,
  121.    int iPixelFormat );
  122.  
  123. void
  124. stw_framebuffer_reference(
  125.    struct stw_framebuffer **ptr,
  126.    struct stw_framebuffer *fb);
  127.  
  128. /**
  129.  * Search a framebuffer with a matching HWND.
  130.  *
  131.  * This function will acquire stw_framebuffer::mutex. stw_framebuffer_release
  132.  * must be called when done
  133.  */
  134. struct stw_framebuffer *
  135. stw_framebuffer_from_hwnd(
  136.    HWND hwnd );
  137.  
  138. /**
  139.  * Search a framebuffer with a matching HDC.
  140.  *
  141.  * This function will acquire stw_framebuffer::mutex. stw_framebuffer_release
  142.  * must be called when done
  143.  */
  144. struct stw_framebuffer *
  145. stw_framebuffer_from_hdc(
  146.    HDC hdc );
  147.  
  148. BOOL
  149. stw_framebuffer_present_locked(HDC hdc,
  150.                                struct stw_framebuffer *fb,
  151.                                struct pipe_resource *res);
  152.  
  153. void
  154. stw_framebuffer_update(
  155.    struct stw_framebuffer *fb);
  156.  
  157. /**
  158.  * Release stw_framebuffer::mutex lock. This framebuffer must not be accessed
  159.  * after calling this function, as it may have been deleted by another thread
  160.  * in the meanwhile.
  161.  */
  162. void
  163. stw_framebuffer_release(
  164.    struct stw_framebuffer *fb);
  165.  
  166. /**
  167.  * Cleanup any existing framebuffers when exiting application.
  168.  */
  169. void
  170. stw_framebuffer_cleanup(void);
  171.  
  172. #endif /* STW_FRAMEBUFFER_H */
  173.