Example #1
0
HBITMAP CreateDeviceBitmap(PDev *pdev, SIZEL size, ULONG format, QXLPHYSICAL *phys_mem,
                           UINT8 **base_mem, UINT32 surface_id, UINT8 allocation_type)
{
    UINT32 surface_format, depth;
    HBITMAP hbitmap;
    INT32 stride;
    SurfaceInfo *surface_info;

    DEBUG_PRINT((pdev, 9, "%s: %p: %d, (%dx%d), %d\n", __FUNCTION__, pdev, surface_id,
                size.cx, size.cy, format));
    surface_info = GetSurfaceInfo(pdev, surface_id);

    if (!(hbitmap = EngCreateDeviceBitmap((DHSURF)surface_info, size, format))) {
        DEBUG_PRINT((pdev, 0, "%s: EngCreateDeviceBitmap failed, pdev 0x%lx, surface_id=%d\n",
                    __FUNCTION__, pdev, surface_id));
        goto out_error1;
    }

    if (!EngAssociateSurface((HSURF)hbitmap, pdev->eng, QXL_SURFACE_HOOKS)) {
        DEBUG_PRINT((pdev, 0, "%s: EngAssociateSurface failed\n", __FUNCTION__));
        goto out_error2;
    }
    surface_info->u.pdev = pdev;
    surface_info->hbitmap = hbitmap;
    surface_info->copy = NULL;
    surface_info->size = size;
    surface_info->bitmap_format = format;
    if ((*base_mem = CreateSurfaceHelper(pdev, surface_id, size.cx, size.cy, format,
                                         allocation_type, &stride, &surface_format,
                                         phys_mem)) == NULL) {
        DEBUG_PRINT((pdev, 0, "%s: failed, pdev 0x%lx, surface_id=%d\n",
                    __FUNCTION__, pdev, surface_id));
        goto out_error2;
    }
    surface_info->stride = stride;
    if (allocation_type != DEVICE_BITMAP_ALLOCATION_TYPE_SURF0) {
        SendSurfaceCreateCommand(pdev, surface_id, size, surface_format, -stride, *phys_mem, 0);
    }

    return hbitmap;
out_error2:
    EngDeleteSurface((HSURF)hbitmap);
out_error1:
    return 0;
}
Example #2
0
HBITMAP DrvCreateDeviceBitmap(
DHPDEV  dhpdev,
SIZEL   sizl,
ULONG   iFormat)
{
    PDEV*   ppdev;
    OH*     poh;
    DSURF*  pdsurf;
    HBITMAP hbmDevice;
    FLONG   flHooks;

    ppdev = (PDEV*) dhpdev;

    // If we're in full-screen mode, we hardly have any off-screen memory
    // in which to allocate a DFB.  LATER: We could still allocate an
    // OH node and put the bitmap on the DIB DFB list for later promotion.

    if (!ppdev->bEnabled)
        return(0);

    // We only support device bitmaps when we're in a fully accelerated
    // mode:

    if (ppdev->iBitmapFormat != BMF_8BPP)
        return(0);

    // We only support device bitmaps that are the same colour depth
    // as our display.
    //
    // Actually, those are the only kind GDI will ever call us with,
    // but we may as well check.  Note that this implies you'll never
    // get a crack at 1bpp bitmaps.

    if (iFormat != ppdev->iBitmapFormat)
        return(0);

    poh = pohAllocate(ppdev, sizl.cx, sizl.cy, 0);
    if (poh != NULL)
    {
        pdsurf = EngAllocMem(0, sizeof(DSURF), ALLOC_TAG);
        if (pdsurf != NULL)
        {
            hbmDevice = EngCreateDeviceBitmap((DHSURF) pdsurf, sizl, iFormat);
            if (hbmDevice != NULL)
            {
                flHooks = ppdev->flHooks;

                #if SYNCHRONIZEACCESS_WORKS
                {
                    // Setting the SYNCHRONIZEACCESS flag tells GDI that we
                    // want all drawing to the bitmaps to be synchronized (GDI
                    // is multi-threaded and by default does not synchronize
                    // device bitmap drawing -- it would be a Bad Thing for us
                    // to have multiple threads using the accelerator at the
                    // same time):

                    flHooks |= HOOK_SYNCHRONIZEACCESS;
                }
                #endif // SYNCHRONIZEACCESS_WORKS

                if (EngAssociateSurface((HSURF) hbmDevice, ppdev->hdevEng,
                                        flHooks))
                {
                    pdsurf->dt    = DT_SCREEN;
                    pdsurf->poh   = poh;
                    pdsurf->sizl  = sizl;
                    pdsurf->ppdev = ppdev;
                    poh->pdsurf   = pdsurf;

                    return(hbmDevice);
                }

                EngDeleteSurface((HSURF) hbmDevice);
            }
            EngFreeMem(pdsurf);
        }
        pohFree(ppdev, poh);
    }

    return(0);
}