1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Helper functions that Direct3D 9Ex code a little easier to work with for 6 // the ui/surface code. 7 8 #ifndef UI_SURFACE_D3D9_UTILS_WIN_H_ 9 #define UI_SURFACE_D3D9_UTILS_WIN_H_ 10 11 #include <d3d9.h> 12 13 #include "base/basictypes.h" 14 #include "base/win/scoped_comptr.h" 15 #include "ui/surface/surface_export.h" 16 17 namespace base { 18 class ScopedNativeLibrary; 19 } 20 21 namespace gfx { 22 class Size; 23 } 24 25 namespace ui_surface_d3d9_utils { 26 27 // Visible for testing. Loads the Direct3D9 library. Returns true on success. 28 SURFACE_EXPORT 29 bool LoadD3D9(base::ScopedNativeLibrary* storage); 30 31 // Visible for testing. Creates a Direct3D9 device suitable for use with the 32 // accelerated surface code. Returns true on success. 33 SURFACE_EXPORT 34 bool CreateDevice(const base::ScopedNativeLibrary& d3d_module, 35 uint64 adapter_luid, 36 D3DDEVTYPE device_type, 37 uint32 presentation_interval, 38 IDirect3DDevice9Ex** device); 39 40 // Calls the Vista+ (WDDM1.0) variant of CreateTexture that semantically opens a 41 // texture allocated as shared. In this way textures allocated by another 42 // process can be used by a D3D context in this process. The shared texture is 43 // identified by its surface handle. The resulting texture is written into 44 // |opened_texture|. 45 // 46 // Returns true on success. 47 SURFACE_EXPORT 48 bool OpenSharedTexture(IDirect3DDevice9* device, 49 int64 surface_handle, 50 const gfx::Size& size, 51 IDirect3DTexture9** opened_texture); 52 53 // Ensures that |surface| is a lockable surface of a specified |size|. If 54 // |*surface| is non-null and has dimensions that match |size|, it is reused. 55 // Otherwise, a new resource is created and the old one (if any) is freed. 56 // 57 // Returns true on success. 58 SURFACE_EXPORT 59 bool CreateOrReuseLockableSurface( 60 IDirect3DDevice9* device, 61 const gfx::Size& size, 62 base::win::ScopedComPtr<IDirect3DSurface9>* surface); 63 64 // Ensures that |texture| is a render target texture of a specified |size|. If 65 // |*texture| is non-null and has dimensions that match |size|, it is reused. 66 // Otherwise, a new resource is created and the old one (if any) is freed. 67 // 68 // A reference to level 0 of the resulting texture is placed into 69 // |render_target|. 70 // 71 // Returns true on success. 72 SURFACE_EXPORT 73 bool CreateOrReuseRenderTargetTexture( 74 IDirect3DDevice9* device, 75 const gfx::Size& size, 76 base::win::ScopedComPtr<IDirect3DTexture9>* texture, 77 IDirect3DSurface9** render_target); 78 79 SURFACE_EXPORT 80 gfx::Size GetSize(IDirect3DTexture9* texture); 81 82 SURFACE_EXPORT 83 gfx::Size GetSize(IDirect3DSurface9* surface); 84 85 } // namespace ui_surface_d3d9_utils 86 87 #endif // UI_SURFACE_D3D9_UTILS_WIN_H_ 88