local memory for overlay support

I am giving support for overlay in my display driver. As I have no
additional memory that I could use for overlays, is it possible that I can
use local video memory (System Memory) for creating overlays. Actually I
have seen in DDK sample driver code that it always uses nonlocal video
memory for overlays. Currently Performance is not the issue, I know that it
will lower the performance, but could it possible. I am giving overlay
support to enable DVD Player to run on my Display Driver.

Regards,

Asif

Ok, let’s first see if I understand what you want to do:
You want to allocate a chunk of host memory (such as EngAllocMemory or
KeAllocatePoolWithTag) and use this memory to store the image for the
overlay.

I don’t see a problem with this, as such. I would have thought that
allocating video memory would be preferrable from a performance standpoint,
as you don’t have to copy the memory three times then.

The problem comes when trying to combine the image from the overlay and the
main channel. The overlay is normally “colour-keyed”, which means that when
the main channel contains a certain colour, you should replace it with the
contents of the overlay. If it’s any other colour, it should be the main
channels content. I don’t know if there’s a function in your graphics chip
that can “copy these pixels to the destination if the destination is this
colour”. If you do that by software, it will most likely be PAINFULLY slow.
Of course, for video-playback, the main channel’s overlay area will most
likely be rectangular and constant, so you could track any changes to the
main plane area and just see if anyone puts anything else in the area (such
as tool-bars and menus or overlapping with other apps), using rectangular
clipping to make the copy straight-forward. Then it will only be slow when
something has changed in that area, which is most likely NOT when the user
is watching the DVD itself…

I hope this helps.

[To our nomenclature, “Local memory” means memory that is connected to the
graphics chip, and “Host memory” is the computers “main memory”. I’m not
sure if this is what everyone else in the world of graphics call the
different types of memory… ]


Mats

-------- Notice --------
The information in this message is confidential and may be legally
privileged. It is intended solely for the addressee. Access to this
message by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying or distribution of the message, or any
action taken by you in reliance on it, is prohibited and may be unlawful.
If you have received this message in error, please delete it and contact
the sender immediately. Thank you.

xxxxx@lists.osr.com wrote on 01/31/2005 01:14:34 PM:

I am giving support for overlay in my display driver. As I have no
additional memory that I could use for overlays, is it possible that I
can
use local video memory (System Memory) for creating overlays. Actually I
have seen in DDK sample driver code that it always uses nonlocal video
memory for overlays. Currently Performance is not the issue, I know that
it
will lower the performance, but could it possible. I am giving overlay
support to enable DVD Player to run on my Display Driver.

Regards,

Asif


Questions? First check the Kernel Driver FAQ at http://www.
osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@3dlabs.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

ForwardSourceID:NT0000BE2A

If the graphics hardware has 3D capability, especially if it
supports texturing from host memory, you can try to handle the
overlay as a texture. But six years ago, if I remember
correctly, the S3 chips had a separate video channel that you
could use to superimpose a video overlay onto your screen. Any
chance your hw engineers would consider such a functionality ?

Alberto.

----- Original Message -----
From: “Mats PETERSSON”
To: “Windows System Software Devs Interest List”

Sent: Monday, January 31, 2005 8:39 AM
Subject: Re: [ntdev] local memory for overlay support

>
>
>
>
>
> Ok, let’s first see if I understand what you want to do:
> You want to allocate a chunk of host memory (such as
> EngAllocMemory or
> KeAllocatePoolWithTag) and use this memory to store the image
> for the
> overlay.
>
> I don’t see a problem with this, as such. I would have thought
> that
> allocating video memory would be preferrable from a
> performance standpoint,
> as you don’t have to copy the memory three times then.
>
> The problem comes when trying to combine the image from the
> overlay and the
> main channel. The overlay is normally “colour-keyed”, which
> means that when
> the main channel contains a certain colour, you should replace
> it with the
> contents of the overlay. If it’s any other colour, it should
> be the main
> channels content. I don’t know if there’s a function in your
> graphics chip
> that can “copy these pixels to the destination if the
> destination is this
> colour”. If you do that by software, it will most likely be
> PAINFULLY slow.
> Of course, for video-playback, the main channel’s overlay area
> will most
> likely be rectangular and constant, so you could track any
> changes to the
> main plane area and just see if anyone puts anything else in
> the area (such
> as tool-bars and menus or overlapping with other apps), using
> rectangular
> clipping to make the copy straight-forward. Then it will only
> be slow when
> something has changed in that area, which is most likely NOT
> when the user
> is watching the DVD itself…
>
> I hope this helps.
>
> [To our nomenclature, “Local memory” means memory that is
> connected to the
> graphics chip, and “Host memory” is the computers “main
> memory”. I’m not
> sure if this is what everyone else in the world of graphics
> call the
> different types of memory…]
>
> –
> Mats
>
> -------- Notice --------
> The information in this message is confidential and may be
> legally
> privileged. It is intended solely for the addressee. Access
> to this
> message by anyone else is unauthorized. If you are not the
> intended
> recipient, any disclosure, copying or distribution of the
> message, or any
> action taken by you in reliance on it, is prohibited and may
> be unlawful.
> If you have received this message in error, please delete it
> and contact
> the sender immediately. Thank you.
>
>
> xxxxx@lists.osr.com wrote on 01/31/2005 01:14:34
> PM:
>
>>
>> I am giving support for overlay in my display driver. As I
>> have no
>> additional memory that I could use for overlays, is it
>> possible that I
> can
>> use local video memory (System Memory) for creating overlays.
>> Actually I
>> have seen in DDK sample driver code that it always uses
>> nonlocal video
>> memory for overlays. Currently Performance is not the issue,
>> I know that
> it
>> will lower the performance, but could it possible. I am
>> giving overlay
>> support to enable DVD Player to run on my Display Driver.
>>
>> Regards,
>>
>> Asif
>>
>> —
>> Questions? First check the Kernel Driver FAQ at http://www.
>> osronline.com/article.cfm?id=256
>>
>> You are currently subscribed to ntdev as:
>> xxxxx@3dlabs.com
>> To unsubscribe send a blank email to
>> xxxxx@lists.osr.com
>
>> ForwardSourceID:NT0000BE2A
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@ieee.org
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com

A-O-A,
Thanks for all these responses. I have written a display driver and
currently writing code for giving Overlay support. I have allocated Host
Memory for OVerlay Surface. Actually my objective is to play WinDVD on my
display. Well finally my DdUpdateOVerlay functions is being called with Show
Flag. Actually I am doing overlay copying to the primary surface in
software. But I don’t know when to copy it. I mean I don’t know about the
function called by the DirectDriver for telling the driver to copy(paste)
the OVerlay on the screen. What I have done is, I am copying it in DdFlip
function. Whenever WinDVD is played, DdUpdateOverlay is called for two times
and then DdLock and DdFlip functions are being called continously unless you
change the position of the DVD. IN that case DdUpdateOVerlay is called. So I
think DdFlip is the right function. I have also exported DdBlt function, but
it is not being called. Can any one give idea about that.

Also I don’t have the procedure of pasting overlay to target surface using
sourceColorKeying. Please help me in this regard.

Regards,

Asif

Subject: Re: local memory for overlay support
From: Mats PETERSSON
Date: Mon, 31 Jan 2005 13:39:27 +0000
X-Message-Number: 10

Ok, let’s first see if I understand what you want to do:
You want to allocate a chunk of host memory (such as EngAllocMemory or
KeAllocatePoolWithTag) and use this memory to store the image for the
overlay.

I don’t see a problem with this, as such. I would have thought that
allocating video memory would be preferrable from a performance standpoint,
as you don’t have to copy the memory three times then.

The problem comes when trying to combine the image from the overlay and the
main channel. The overlay is normally “colour-keyed”, which means that when
the main channel contains a certain colour, you should replace it with the
contents of the overlay. If it’s any other colour, it should be the main
channels content. I don’t know if there’s a function in your graphics chip
that can “copy these pixels to the destination if the destination is this
colour”. If you do that by software, it will most likely be PAINFULLY slow.
Of course, for video-playback, the main channel’s overlay area will most
likely be rectangular and constant, so you could track any changes to the
main plane area and just see if anyone puts anything else in the area (such
as tool-bars and menus or overlapping with other apps), using rectangular
clipping to make the copy straight-forward. Then it will only be slow when
something has changed in that area, which is most likely NOT when the user
is watching the DVD itself…

I hope this helps.

[To our nomenclature, “Local memory” means memory that is connected to the
graphics chip, and “Host memory” is the computers “main memory”. I’m not
sure if this is what everyone else in the world of graphics call the
different types of memory…]


Mats

Asif,

Yes, I think that makes sense. Technically, you should just flip the
surface at that point, and then do the “displaying” in the vsync, but I
suspect you can’t do that with your hardware. Our hardware has
double-buffering, so we change the register at any point, but it doesn’t
actually change the output on screen until the next vsync.

When it comes to sourceColorKeying, you really will need to think about
what this means: You’re supposed to compare the main plane for colour, and
when the colour is a match, you draw the pixel for the overlay, otherwise
the main plane. This is very difficult to do in software (well, it’s TIME
CONSUMING, it’s not rocket science if you don’t mind it being a bit slow).

As I suggested last time, you could use a ‘cheat’ method where you keep
track of rectangles on the main plane. Say we have a 1024 x 768 screen, and
currently we have a rectangle of (200, 200) - (400, 600) that is our DVD
display. At this time, the whole area is coloured with the KEY. As long as
nothing draws in this section of the screenn, you don’t need to do anything
other than update the whole area when DdFlip is called.

Now, some software decides to draw a square at (300, 300) - (400, 400). So
your code in BitBlt (or whatever draws the square) will say “Aha, it’s
within my overlay section, lets figure out what regions are still correct
colour”. So, you will end up with a new list of rectangles: 200, 200 - 300,
600; 300, 200 - 300, 400; 300, 400 - 400, 600 (or something like that).
Now, you can blit this list of rectangles to the screen. If you get a shape
that isn’t a rectangle, split it into big rectanles first, then take any
small odd-shaped bits and mark them as “software handled”, and use a
compare and copy type routine, where you compare the pixel with the
keycolour and copy the correct pixel accordingly. This should be possible
to do with a pretty small loop, perhaps even using advanced MMX or SSE
instructions if necessary.


Mats

xxxxx@lists.osr.com wrote on 02/04/2005 02:25:32 PM:

A-O-A,
Thanks for all these responses. I have written a display driver and
currently writing code for giving Overlay support. I have allocated Host
Memory for OVerlay Surface. Actually my objective is to play WinDVD on my
display. Well finally my DdUpdateOVerlay functions is being called with
Show
Flag. Actually I am doing overlay copying to the primary surface in
software. But I don’t know when to copy it. I mean I don’t know about the
function called by the DirectDriver for telling the driver to copy(paste)
the OVerlay on the screen. What I have done is, I am copying it in DdFlip
function. Whenever WinDVD is played, DdUpdateOverlay is called for two
times
and then DdLock and DdFlip functions are being called continously unless
you
change the position of the DVD. IN that case DdUpdateOVerlay is called.
So I
think DdFlip is the right function. I have also exported DdBlt function,
but
it is not being called. Can any one give idea about that.

Also I don’t have the procedure of pasting overlay to target surface
using
sourceColorKeying. Please help me in this regard.

Regards,

Asif

Subject: Re: local memory for overlay support
From: Mats PETERSSON
> Date: Mon, 31 Jan 2005 13:39:27 +0000
> X-Message-Number: 10
>
>
>
> Ok, let’s first see if I understand what you want to do:
> You want to allocate a chunk of host memory (such as EngAllocMemory or
> KeAllocatePoolWithTag) and use this memory to store the image for the
> overlay.
>
> I don’t see a problem with this, as such. I would have thought that
> allocating video memory would be preferrable from a performance
standpoint,
> as you don’t have to copy the memory three times then.
>
> The problem comes when trying to combine the image from the overlay and
the
> main channel. The overlay is normally “colour-keyed”, which means that
when
> the main channel contains a certain colour, you should replace it with
the
> contents of the overlay. If it’s any other colour, it should be the main
> channels content. I don’t know if there’s a function in your graphics
chip
> that can “copy these pixels to the destination if the destination is this
> colour”. If you do that by software, it will most likely be PAINFULLY
slow.
> Of course, for video-playback, the main channel’s overlay area will most
> likely be rectangular and constant, so you could track any changes to the
> main plane area and just see if anyone puts anything else in the area
(such
> as tool-bars and menus or overlapping with other apps), using rectangular
> clipping to make the copy straight-forward. Then it will only be slow
when
> something has changed in that area, which is most likely NOT when the
user
> is watching the DVD itself…
>
> I hope this helps.
>
> [To our nomenclature, “Local memory” means memory that is connected to
the
> graphics chip, and “Host memory” is the computers “main memory”. I’m not
> sure if this is what everyone else in the world of graphics call the
> different types of memory…]
>
> –
> Mats
>
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at http://www.
> osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@3dlabs.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

> ForwardSourceID:NT0000C266

Thanks Mats for all these message. I appreciate your knowledge in this
field.

Currently I am facing the following problems:

  1. I am copying and pasting the overlay to the primary surface in the
    diaplay driver (I mean in the software). I am simply blitting the overlay
    using memcpy to the primary surface. When I see the final frame, it shows
    the video frames but very crude. I mean, I know that I have to do
    stretchBlt, but the problem is, the frames are so crude, I doubt it doesn’t
    have the color information. I just want to know, whether I have to do some
    thing more other than Blitting. I mean should I have to do something for the
    colors as well.

  2. I have created two DirectDraw heaps and set their attributes in
    DrvGetDirectDrawInfo. I have declared one heap for overlay use and the
    second one as offscreenplane. The problem is, when DdUpdateOverlay is
    called, the Source surface is the surface for which I have set the
    OffScreenPlane attributes and not the other surface which was actually
    declared to be used as overlay. Also It is not being refered in any call
    made by DirectDraw. If you have any idea, please help me.

  3. on http://www.hauppauge.com/pages/faq/support_faq_vgainfo.html, it is
    written:

If you use a graphics card that does not have this support (Overlay Surface
support), you can use Primary Surface type of Overlay. Primary Surface still
requires Direct Draw and Direct X support, but the overlay will be processed
in the primary video buffer since the card does not have an Overlay buffer.

the question is how could we use Primary Surface type of Overlay. I hope you
can explain these better.

Again thanks for all your previous help.

Regards,

Asif

> the question is how could we use Primary Surface type of Overlay. I hope you

Windows Media Player works fine with overlay disabled. Well, a bit more CPU
load, but nevertheless.

So, if I were you, I drop your attempts to do the software emulation of
overlay, if you have no RAMDAC hardware for it.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com