[Spice-devel] [PATCH 11/12] qxl-wddm-dod: Implement non-forced bitmap allocation
Yuri Benditovich
yuri.benditovich at daynix.com
Sun Mar 12 08:45:08 UTC 2017
Preparation for non-forced allocations.
Move bitmap creation to dedicated procedure which is able
to allocate device memory forced or non-forced.
In forced case it works as before.
In non-forced case in case of allocation failure it will allocate
memory from OS pool for entire bitmap and copy the data to it.
Later, before sending command, it will be allocated from device
memory and copied from intermediate location to new one.
Signed-off-by: Yuri Benditovich <yuri.benditovich at daynix.com>
---
qxldod/QxlDod.cpp | 172 ++++++++++++++++++++++++++++++++++--------------------
qxldod/QxlDod.h | 1 +
2 files changed, 111 insertions(+), 62 deletions(-)
diff --git a/qxldod/QxlDod.cpp b/qxldod/QxlDod.cpp
index 94426dd..efc1fb3 100755
--- a/qxldod/QxlDod.cpp
+++ b/qxldod/QxlDod.cpp
@@ -4456,6 +4456,101 @@ QXLDrawable *QxlDevice::CopyBits(const RECT& rect, const POINT& sourcePoint)
return drawable;
}
+BOOLEAN QxlDevice::AttachNewBitmap(QXLDrawable *drawable, UINT8 *src, UINT8 *src_end, INT pitch, BOOLEAN bForce)
+{
+ LONG width, height;
+ size_t alloc_size;
+ UINT32 line_size;
+ Resource *image_res;
+ InternalImage *internal;
+ QXLDataChunk *chunk;
+ PLIST_ENTRY pDelayedList = NULL;
+ UINT8* dest, *dest_end;
+
+ height = drawable->u.copy.src_area.bottom;
+ width = drawable->u.copy.src_area.right;
+ line_size = width * 4;
+
+ alloc_size = BITMAP_ALLOC_BASE + BITS_BUF_MAX - BITS_BUF_MAX % line_size;
+ alloc_size = MIN(BITMAP_ALLOC_BASE + height * line_size, alloc_size);
+ image_res = (Resource*)AllocMem(MSPACE_TYPE_VRAM, alloc_size, bForce);
+
+ if (image_res)
+ {
+ image_res->refs = 1;
+ image_res->free = FreeBitmapImageEx;
+ image_res->ptr = this;
+
+ internal = (InternalImage *)image_res->res;
+ SetImageId(internal, FALSE, width, height, SPICE_BITMAP_FMT_32BIT, 0);
+ internal->image.descriptor.flags = 0;
+ internal->image.descriptor.type = SPICE_IMAGE_TYPE_BITMAP;
+
+ chunk = (QXLDataChunk *)(&internal->image.bitmap + 1);
+ chunk->data_size = 0;
+ chunk->prev_chunk = 0;
+ chunk->next_chunk = 0;
+ internal->image.bitmap.data = PA(chunk, m_SurfaceMemSlot);
+ internal->image.bitmap.flags = 0;
+ internal->image.descriptor.width = internal->image.bitmap.x = width;
+ internal->image.descriptor.height = internal->image.bitmap.y = height;
+ internal->image.bitmap.format = SPICE_BITMAP_FMT_RGBA;
+ internal->image.bitmap.stride = line_size;
+ internal->image.bitmap.palette = 0;
+
+ dest = chunk->data;
+ dest_end = (UINT8 *)image_res + alloc_size;
+
+ drawable->u.copy.src_bitmap = PA(&internal->image, m_SurfaceMemSlot);
+
+ DrawableAddRes(drawable, image_res);
+ RELEASE_RES(image_res);
+ alloc_size = height * line_size;
+ }
+ else if (!bForce)
+ {
+ alloc_size = height * line_size;
+ // allocate delayed chunck for entire bitmap without limitation
+ QXL_DELAYED_CHUNK *pChunk = (QXL_DELAYED_CHUNK *)new (PagedPool)BYTE[alloc_size + sizeof(QXL_DELAYED_CHUNK)];
+ if (pChunk)
+ {
+ // add it to delayed list
+ InsertTailList(pDelayedList, &pChunk->list);
+ // PutBytesAlign do not need to allocate additional memory
+ pDelayedList = NULL;
+ chunk = &pChunk->chunk;
+ chunk->data_size = 0;
+ chunk->prev_chunk = 0;
+ chunk->next_chunk = 0;
+ // set dest and dest_end
+ dest = chunk->data;
+ dest_end = chunk->data + alloc_size;
+ }
+ else
+ {
+ // can't allocate memory
+ DbgPrint(TRACE_LEVEL_ERROR, ("Cannot allocate delayed bitmap for drawable\n"));
+ return FALSE;
+ }
+ }
+ else
+ {
+ // can't allocate memory (forced), driver abort flow
+ DbgPrint(TRACE_LEVEL_ERROR, ("Cannot get bitmap for drawable (stopping)\n"));
+ return FALSE;
+ }
+
+ for (; src != src_end; src -= pitch, alloc_size -= line_size) {
+ BOOLEAN b = PutBytesAlign(&chunk, &dest, &dest_end, src, line_size, alloc_size, pDelayedList);
+ if (!b)
+ {
+ DbgPrint(TRACE_LEVEL_WARNING, ("%s: aborting copy of lines\n", __FUNCTION__));
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
QXLDrawable *QxlDevice::BltBits (
BLT_INFO* pDst,
CONST BLT_INFO* pSrc,
@@ -4465,11 +4560,6 @@ QXLDrawable *QxlDevice::BltBits (
{
PAGED_CODE();
QXLDrawable *drawable;
- Resource *image_res;
- InternalImage *internal;
- size_t alloc_size;
- QXLDataChunk *chunk;
- UINT32 line_size;
LONG width;
LONG height;
@@ -4495,74 +4585,32 @@ QXLDrawable *QxlDevice::BltBits (
height = pRect->bottom - pRect->top;
width = pRect->right - pRect->left;
- line_size = width * 4;
drawable->u.copy.src_area.bottom = height;
drawable->u.copy.src_area.left = 0;
drawable->u.copy.src_area.top = 0;
drawable->u.copy.src_area.right = width;
- alloc_size = BITMAP_ALLOC_BASE + BITS_BUF_MAX - BITS_BUF_MAX % line_size;
- alloc_size = MIN(BITMAP_ALLOC_BASE + height * line_size, alloc_size);
- image_res = (Resource*)AllocMem(MSPACE_TYPE_VRAM, alloc_size, TRUE);
- if (!image_res)
- {
- ReleaseOutputUnderLock(drawable->release_info.id);
- DbgPrint(TRACE_LEVEL_ERROR, ("Cannot allocate bitmap for drawable\n"));
- return NULL;
- }
-
- image_res->refs = 1;
- image_res->free = FreeBitmapImageEx;
- image_res->ptr = this;
+ CopyRect(&drawable->surfaces_rects[1], pRect);
- internal = (InternalImage *)image_res->res;
- SetImageId(internal, FALSE, width, height, SPICE_BITMAP_FMT_32BIT, 0);
- internal->image.descriptor.flags = 0;
- internal->image.descriptor.type = SPICE_IMAGE_TYPE_BITMAP;
- chunk = (QXLDataChunk *)(&internal->image.bitmap + 1);
- chunk->data_size = 0;
- chunk->prev_chunk = 0;
- chunk->next_chunk = 0;
- internal->image.bitmap.data = PA(chunk, m_SurfaceMemSlot);
- internal->image.bitmap.flags = 0;
- internal->image.descriptor.width = internal->image.bitmap.x = width;
- internal->image.descriptor.height = internal->image.bitmap.y = height;
- internal->image.bitmap.format = SPICE_BITMAP_FMT_RGBA;
- internal->image.bitmap.stride = line_size;
-
- UINT8* src = (UINT8*)pSrc->pBits+
- (pSourcePoint->y) * pSrc->Pitch +
- (pSourcePoint->x * 4);
+ UINT8* src = (UINT8*)pSrc->pBits +
+ (pSourcePoint->y) * pSrc->Pitch +
+ (pSourcePoint->x * 4);
UINT8* src_end = src - pSrc->Pitch;
src += pSrc->Pitch * (height - 1);
- UINT8* dest = chunk->data;
- UINT8* dest_end = (UINT8 *)image_res + alloc_size;
- alloc_size = height * line_size;
- for (; src != src_end; src -= pSrc->Pitch, alloc_size -= line_size) {
- if (!PutBytesAlign(&chunk, &dest, &dest_end, src,
- line_size, alloc_size, NULL))
- {
- // not reachable when forced allocation used
- ReleaseOutputUnderLock(drawable->release_info.id);
- DbgPrint(TRACE_LEVEL_ERROR, ("Cannot allocate additional bitmap for drawable\n"));
- return NULL;
- }
+ if (!AttachNewBitmap(drawable, src, src_end, (INT)pSrc->Pitch, TRUE))
+ {
+ ReleaseOutputUnderLock(drawable->release_info.id);
+ drawable = NULL;
+ }
+ else
+ {
+ DbgPrint(TRACE_LEVEL_INFORMATION, ("%s drawable= %p type = %d, effect = %d Dest right(%d) left(%d) top(%d) bottom(%d) src_bitmap= %p.\n", __FUNCTION__,
+ drawable, drawable->type, drawable->effect, drawable->surfaces_rects[0].right, drawable->surfaces_rects[0].left,
+ drawable->surfaces_rects[0].top, drawable->surfaces_rects[0].bottom,
+ drawable->u.copy.src_bitmap));
}
-
- internal->image.bitmap.palette = 0;
-
- drawable->u.copy.src_bitmap = PA(&internal->image, m_SurfaceMemSlot);
-
- CopyRect(&drawable->surfaces_rects[1], pRect);
- DrawableAddRes(drawable, image_res);
- RELEASE_RES(image_res);
-
- DbgPrint(TRACE_LEVEL_INFORMATION, ("%s drawable= %p type = %d, effect = %d Dest right(%d) left(%d) top(%d) bottom(%d) src_bitmap= %p.\n", __FUNCTION__,
- drawable, drawable->type, drawable->effect, drawable->surfaces_rects[0].right, drawable->surfaces_rects[0].left,
- drawable->surfaces_rects[0].top, drawable->surfaces_rects[0].bottom,
- drawable->u.copy.src_bitmap));
DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__));
diff --git a/qxldod/QxlDod.h b/qxldod/QxlDod.h
index 983bc29..b2f0e0c 100755
--- a/qxldod/QxlDod.h
+++ b/qxldod/QxlDod.h
@@ -609,6 +609,7 @@ private:
void PushCmd(void);
void WaitForCursorRing(void);
void PushCursor(void);
+ BOOLEAN AttachNewBitmap(QXLDrawable *drawable, UINT8 *src, UINT8 *src_end, INT pitch, BOOLEAN forced);
BOOLEAN PutBytesAlign(QXLDataChunk **chunk_ptr, UINT8 **now_ptr,
UINT8 **end_ptr, UINT8 *src, int size,
size_t alloc_size, PLIST_ENTRY pDelayed);
--
2.7.0.windows.1
More information about the Spice-devel
mailing list