Watch out, some surfaces aren't lockable. I don't know the d3dx9 api too well, but are you sure that you have a lockable surface here? In some situations IDirect3DDevice9::UpdateSurface or IDirect3DDevice9::StretchRect may be a faster way to achieve what this code does(without colorkeying though).
Hi, The function just fails with D3DXERR_INVALIDDATA if the surface is not lockable, just as D3DXLoadSurfaceFromMemory will when it's implemented. Of course UpdateSurface could be used, but as you said it doesn't support color keying (nor palettes I guess) or filtering and it only works in very specific cases (i.e. same dimensions, no color keying, no filtering), applications are more likely to do things like that on their own probably. D3DX has been created for the general case mostly, so optimizations like this would just make the code more complicated ;)
Tony