Exemplo n.º 1
0
// cairo_public void
// cairo_os2_surface_set_manual_window_refresh (cairo_surface_t *surface,
//                                              cairo_bool_t     manual_refresh);
static int l_cairo_os2_surface_set_manual_window_refresh(lua_State* L)
{
    cairo_surface_t *surface = get_cairo_surface_t (L, 1);
    cairo_bool_t manual_refresh = (cairo_bool_t) luaL_checkinteger(L, 2);
    cairo_os2_surface_set_manual_window_refresh (surface, manual_refresh);
    return 0;
}
Exemplo n.º 2
0
void CairoDrawThread(void *pParam)
{
  HWND hwndClientWindow = (HWND) pParam;
  HPS hpsClientWindow;
  SWP swpTemp;

  // Query HPS of HWND
  hpsClientWindow = WinGetPS(hwndClientWindow);
  WinQueryWindowPos(hwndClientWindow, &swpTemp);

  // Set FPU state which might have been changed by some Win* calls!
  // (Workaround for a PM bug)
  DisableFPUException();

  // Initialize cairo support
  cairo_os2_init();

  // Create cairo surface
  pCairoSurface = cairo_os2_surface_create(hpsClientWindow,
                                           swpTemp.cx,
                                           swpTemp.cy);

  // Tell the surface the HWND too, so if the application decides
  // that it wants to draw itself, then it will be able to turn
  // on blit_as_changes.
  cairo_os2_surface_set_hwnd(pCairoSurface, hwndClientWindow);

  // Make sure that the changes will be shown only
  // when we tell so
  cairo_os2_surface_set_manual_window_refresh(pCairoSurface,
                                              TRUE);


  // Create Cairo drawing handle for the surface
  pCairoHandle = cairo_create(pCairoSurface);

  // Do the main drawing loop as long as needed!
  bShutdownDrawing = 0;
  CairoDrawLoop(hwndClientWindow,
                swpTemp.cx, swpTemp.cy,
                pCairoSurface,
                pCairoHandle);

  // Clean up!
  cairo_destroy(pCairoHandle);
  cairo_surface_destroy(pCairoSurface);

  cairo_os2_fini();

  WinReleasePS(hpsClientWindow);

  _endthread();
}
Exemplo n.º 3
0
gfxOS2Surface::gfxOS2Surface(const gfxIntSize& aSize,
                             gfxImageFormat aImageFormat)
    : mWnd(0), mSize(aSize)
{
#ifdef DEBUG_thebes_2
    printf("gfxOS2Surface[%#x]::gfxOS2Surface(Size=%dx%d, %d)\n", (unsigned int)this,
           aSize.width, aSize.height, aImageFormat);
#endif
    // in this case we don't have a window, so we create a memory presentation
    // space to construct the cairo surface on

    // create a PS, partly taken from nsOffscreenSurface::Init(), i.e. nsDrawingSurfaceOS2.cpp
    DEVOPENSTRUC dop = { 0, 0, 0, 0, 0 };
    SIZEL sizel = { 0, 0 }; // use same page size as device
    mDC = DevOpenDC(0, OD_MEMORY, (PSZ)"*", 5, (PDEVOPENDATA)&dop, NULLHANDLE);
    NS_ASSERTION(mDC != DEV_ERROR, "Could not create memory DC");

    mPS = GpiCreatePS(0, mDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
    NS_ASSERTION(mPS != GPI_ERROR, "Could not create PS on memory DC!");

    // now create a bitmap of the right size
    BITMAPINFOHEADER2 hdr = { 0 };
    hdr.cbFix = sizeof(BITMAPINFOHEADER2);
    hdr.cx = mSize.width;
    hdr.cy = mSize.height;
    hdr.cPlanes = 1;

    // find bit depth
    LONG lBitCount = 0;
    DevQueryCaps(mDC, CAPS_COLOR_BITCOUNT, 1, &lBitCount);
    hdr.cBitCount = (USHORT)lBitCount;

    mBitmap = GpiCreateBitmap(mPS, &hdr, 0, 0, 0);
    NS_ASSERTION(mBitmap != GPI_ERROR, "Could not create bitmap in memory!");
    // set final stats & select bitmap into PS
    GpiSetBitmap(mPS, mBitmap);

    // now we can finally create the cairo surface on the in-memory PS
    cairo_surface_t *surf = cairo_os2_surface_create(mPS, mSize.width, mSize.height);
#ifdef DEBUG_thebes_2
    printf("  type(%#x)=%d (ID=%#x, h/w=%d/%d)\n", (unsigned int)surf,
           cairo_surface_get_type(surf), (unsigned int)mPS, mSize.width, mSize.height);
#endif
    // Normally, OS/2 cairo surfaces have to be forced to redraw completely
    // by calling cairo_surface_mark_dirty(surf), but Mozilla paints them in
    // full, so that is not necessary here.

    // manual refresh is done from nsWindow::OnPaint
    cairo_os2_surface_set_manual_window_refresh(surf, 1);

    Init(surf);
}
Exemplo n.º 4
0
static cairo_test_status_t
preamble (cairo_test_context_t *ctx)
{
    cairo_surface_t *surface;

    /* get the error surface */
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, INT_MAX, INT_MAX);

#if CAIRO_HAS_GL_SURFACE
    cairo_gl_surface_set_size (surface, 0, 0);
    cairo_gl_surface_swapbuffers (surface);
#endif

#if CAIRO_HAS_OS2_SURFACE
    cairo_os2_surface_set_hwnd (surface, 0);
    cairo_os2_surface_set_size (surface, 0, 0);
    cairo_os2_surface_set_manual_window_refresh (surface, FALSE);
#endif

#if CAIRO_HAS_PDF_SURFACE
    cairo_pdf_surface_restrict_to_version (surface, CAIRO_PDF_VERSION_1_4);
    cairo_pdf_surface_set_size (surface, 0, 0);
#endif

#if CAIRO_HAS_PS_SURFACE
    cairo_ps_surface_set_eps (surface, FALSE);
    cairo_ps_surface_set_size (surface, 0, 0);
    cairo_ps_surface_restrict_to_level (surface, CAIRO_PS_LEVEL_2);
    cairo_ps_surface_dsc_comment (surface, NULL);
    cairo_ps_surface_dsc_begin_setup (surface);
    cairo_ps_surface_dsc_begin_page_setup (surface);
#endif

#if CAIRO_HAS_XCB_SURFACE
    cairo_xcb_surface_set_size (surface, 0, 0);
#endif

#if CAIRO_HAS_XLIB_SURFACE
    cairo_xlib_surface_set_size (surface, 0, 0);
    cairo_xlib_surface_set_drawable (surface, 0, 0, 0);
#endif

    cairo_surface_set_mime_data (surface, NULL, NULL, 0, NULL, 0);
    cairo_surface_set_device_offset (surface, 0, 0);
    cairo_surface_set_fallback_resolution (surface, 0, 0);

    cairo_surface_destroy (surface);

    return CAIRO_TEST_SUCCESS;
}
Exemplo n.º 5
0
/* And the real drawing loop: */
void CairoDrawLoop(HWND             hwndClientWindow,
                   int              iWidth,
                   int              iHeight,
                   cairo_surface_t *pCairoSurface,
                   cairo_t         *pCairoHandle)
{
  double dRandMax;
  unsigned int uiLoopCounter = 0;
  NewsItem_p pCurrItem;

  // Initialize random number generator
  srand(clock());
  dRandMax = RAND_MAX;

  cairo_os2_surface_set_manual_window_refresh(pCairoSurface,
                                              1);

  // Clear background with black
  cairo_set_source_rgb (pCairoHandle, 0, 0 ,0);
  cairo_rectangle (pCairoHandle,
                   0, 0,
                   iWidth, iHeight);
  cairo_fill(pCairoHandle);

  // Calculate screen aspect ratio
  if (iWidth<iHeight)
  {
    iUniSize = iWidth;
    dYAspect = iHeight;
    dYAspect /= iWidth;
    dXAspect = 1;
  }
  else
  {
    iUniSize = iHeight;
    dXAspect = iWidth;
    dXAspect /= iHeight;
    dYAspect = 1;
  }

  // --------------------------------
  // Show info that we're downloading the feed

  cairo_save(pCairoHandle);
  cairo_scale(pCairoHandle, iUniSize, iUniSize);


  ShowInfo("Downloading",
           achRSSURL,
           hwndClientWindow,
           pCairoSurface, pCairoHandle);

  cairo_restore(pCairoHandle);

  WinInvalidateRect(hwndClientWindow, NULL, TRUE);

  // --------------------------------
  // Download the URL and parse it with libXML
  pNewsListHead = NULL;
  DownloadXML(achRSSURL, &pNewsListHead);
  pCurrItem = pNewsListHead;
  // --------------------------------

  // Do the main drawing loop as long as needed!
  while (!bShutdownDrawing)
  {
    if (bPauseDrawing)
    {
      // Do not draw anything if we're paused!
      DosSleep(250);
    }
    else
    {
      // Otherwise draw something!

      if (!pNewsListHead)
      {
        if (uiLoopCounter==0)
        {
          // Save cairo canvas state
          cairo_save(pCairoHandle);
  
          // Scale canvas so we'll have a
          // normalized coordinate system of (0;0) -> (1;1)
          cairo_scale(pCairoHandle, iUniSize, iUniSize);
  
          // Clear background with black
          cairo_set_source_rgb(pCairoHandle, 0, 0 ,0);
          cairo_rectangle(pCairoHandle,
                          0, 0,
                          dXAspect, dYAspect);
          cairo_fill(pCairoHandle);
  

          ShowInfo("Error downloading",
                   achRSSURL,
                   hwndClientWindow,
                   pCairoSurface, pCairoHandle);

          // Restore canvas state to original one
          cairo_restore(pCairoHandle);
          WinInvalidateRect(hwndClientWindow, NULL, TRUE);
        } else
        if (uiLoopCounter==10)
        {
          // Save cairo canvas state
          cairo_save(pCairoHandle);
  
          // Scale canvas so we'll have a
          // normalized coordinate system of (0;0) -> (1;1)
          cairo_scale(pCairoHandle, iUniSize, iUniSize);
  
          // Clear background with black
          cairo_set_source_rgb(pCairoHandle, 0, 0 ,0);
          cairo_rectangle(pCairoHandle,
                          0, 0,
                          dXAspect, dYAspect);
          cairo_fill(pCairoHandle);
  

          // Restore canvas state to original one
          cairo_restore(pCairoHandle);
          WinInvalidateRect(hwndClientWindow, NULL, TRUE);
        }

        if (uiLoopCounter<20)
          uiLoopCounter++;
        else
          uiLoopCounter = 0;

      } else
      {
        if (uiLoopCounter % 150 == 0)
        {
          // Save cairo canvas state
          cairo_save(pCairoHandle);

          // Scale canvas so we'll have a
          // normalized coordinate system of (0;0) -> (1;1)
          cairo_scale(pCairoHandle, iUniSize, iUniSize);

          // Clear background with black
          cairo_set_source_rgb(pCairoHandle, 0, 0 ,0);
          cairo_rectangle(pCairoHandle,
                          0, 0,
                          dXAspect, dYAspect);
          cairo_fill(pCairoHandle);

          if (pCurrItem)
            VisualizeXML(pCurrItem,
                         pCairoHandle);

          // Restore canvas state to original one
          cairo_restore(pCairoHandle);
          WinInvalidateRect(hwndClientWindow, NULL, TRUE);

          // Go for next news item then.
          if (pCurrItem)
          {
            pCurrItem = pCurrItem->pNext;
            if (!pCurrItem)
              pCurrItem = pNewsListHead;
          }
        }

        uiLoopCounter++;
      }
    }


    DosSleep(30); // Wait some
  }
  // Got shutdown event, so stopped drawing. That's all.

  // Clean up
  FreeNewsData(&pNewsListHead);
}