OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_SURFACE_ACCELERATED_SURFACE_TRANSFORMER_WIN_H_ | 5 #ifndef UI_SURFACE_ACCELERATED_SURFACE_TRANSFORMER_WIN_H_ |
6 #define UI_SURFACE_ACCELERATED_SURFACE_TRANSFORMER_WIN_H_ | 6 #define UI_SURFACE_ACCELERATED_SURFACE_TRANSFORMER_WIN_H_ |
7 | 7 |
8 #include <d3d9.h> | 8 #include <d3d9.h> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 IDirect3DTexture9* src_texture, | 49 IDirect3DTexture9* src_texture, |
50 IDirect3DSurface9* dst_surface, | 50 IDirect3DSurface9* dst_surface, |
51 const gfx::Size& dst_size); | 51 const gfx::Size& dst_size); |
52 | 52 |
53 // Resize a surface using repeated bilinear interpolation. | 53 // Resize a surface using repeated bilinear interpolation. |
54 bool ResizeBilinear( | 54 bool ResizeBilinear( |
55 IDirect3DSurface9* src_surface, | 55 IDirect3DSurface9* src_surface, |
56 const gfx::Rect& src_subrect, | 56 const gfx::Rect& src_subrect, |
57 IDirect3DSurface9* dst_surface); | 57 IDirect3DSurface9* dst_surface); |
58 | 58 |
59 // Color format conversion from RGB to planar YV12 (also known as YUV420). | |
60 // | |
61 // YV12 is effectively a twelve bit per pixel format consisting of a full- | |
62 // size y (luminance) plane and half-width, half-height u and v (blue and | |
63 // red chrominance) planes. This method will allocate three lockable surfaces, | |
64 // one for each plane, and return them via the arguments |dst_y|, |dst_u|, | |
65 // and |dst_v|. These surface will be created with an ARGB D3DFORMAT, but | |
66 // should be interpreted as the appropriate single-byte format when locking. | |
67 // | |
68 // The dimensions of the outputs (when interpreted as single-component data) | |
69 // are as follows: | |
70 // |dst_y| : width and height exactly |dst_size| | |
71 // |dst_u| : width and height are each half of |dst_size|, rounded up. | |
72 // |dst_v| : width and height are each half of |dst_size|, rounded up. | |
73 // | |
74 // If |src_texture|'s dimensions do not match |dst_size|, the source will be | |
75 // bilinearly interpolated during conversion. | |
76 // | |
77 // Returns true if successful. Caller must be certain to free the buffers | |
78 // even if this function returns false. | |
79 bool TransformRGBToYV12( | |
80 IDirect3DTexture9* src_texture, | |
81 const gfx::Size& dst_size, | |
82 IDirect3DSurface9** dst_y, | |
83 IDirect3DSurface9** dst_u, | |
84 IDirect3DSurface9** dst_v); | |
85 | |
59 private: | 86 private: |
87 friend class AcceleratedSurfaceTransformerTest; | |
88 | |
60 enum ShaderCombo { | 89 enum ShaderCombo { |
61 SIMPLE_TEXTURE, | 90 ONE_TEXTURE_FLIP_Y, |
91 RGB_TO_YV12_FAST__PASS_1_OF_2, | |
92 RGB_TO_YV12_FAST__PASS_2_OF_2, | |
93 RGB_TO_YV12_SLOW__PASS_1_OF_3, | |
94 RGB_TO_YV12_SLOW__PASS_2_OF_3, | |
95 RGB_TO_YV12_SLOW__PASS_3_OF_3, | |
62 NUM_SHADERS | 96 NUM_SHADERS |
63 }; | 97 }; |
64 | 98 |
99 // Efficient RGB->YV12 in two passes, but requires a device capable of writing | |
100 // multiple render targets at the same time. | |
101 // | |
102 // Returns true if successful. | |
103 bool TransformRGBToYV12_MRT( | |
104 IDirect3DTexture9* src_surface, | |
105 const gfx::Size& dst_size, | |
106 const gfx::Size& packed_y_size, | |
107 const gfx::Size& packed_uv_size, | |
108 IDirect3DSurface9* dst_y, | |
109 IDirect3DSurface9* dst_u, | |
110 IDirect3DSurface9* dst_v); | |
111 | |
112 // Slower, less efficient RGB->YV12; does not require the device to have | |
113 // multiple render target capability. Runs at about half speed of the fast | |
114 // path. | |
115 // | |
116 // Returns true if successful. | |
117 bool TransformRGBToYV12_WithoutMRT( | |
118 IDirect3DTexture9* src_surface, | |
119 const gfx::Size& dst_size, | |
120 const gfx::Size& packed_y_size, | |
121 const gfx::Size& packed_uv_size, | |
122 IDirect3DSurface9* dst_y, | |
123 IDirect3DSurface9* dst_u, | |
124 IDirect3DSurface9* dst_v); | |
125 | |
126 // Helper to allocate appropriately size YUV buffers, accounting for various | |
127 // roundings. The sizes of the buffers (in terms of ARGB pixels) are returned | |
128 // as |packed_y_size| and |packed_uv_size|. | |
129 // | |
130 // Returns true if successful. Caller must be certain to free the buffers | |
131 // even if this function returns false. | |
132 bool AllocYUVBuffers( | |
133 const gfx::Size& dst_size, | |
134 gfx::Size* packed_y_size, | |
135 gfx::Size* packed_uv_size, | |
136 IDirect3DSurface9** dst_y, | |
137 IDirect3DSurface9** dst_u, | |
138 IDirect3DSurface9** dst_v); | |
139 | |
65 // Set the active vertex and pixel shader combination. | 140 // Set the active vertex and pixel shader combination. |
141 // | |
142 // Returns true if successful. | |
66 bool SetShaderCombo(ShaderCombo combo); | 143 bool SetShaderCombo(ShaderCombo combo); |
67 | 144 |
68 // Intitializes a vertex and pixel shader combination from compiled bytecode. | 145 // Intitializes a vertex and pixel shader combination from compiled bytecode. |
69 bool InitShaderCombo(const BYTE vertex_shader_instructions[], | 146 // |
70 const BYTE pixel_shader_instructions[], | 147 // Returns true if successful. |
71 ShaderCombo shader_combo_name); | 148 bool InitShaderCombo(ShaderCombo shader_combo_name, |
149 const BYTE vertex_shader_instructions[], | |
150 const BYTE pixel_shader_instructions[]); | |
72 | 151 |
152 bool DoInit(IDirect3DDevice9* device); | |
153 | |
154 void DrawScreenAlignedQuad(const gfx::Size& dst_size); | |
155 | |
156 bool device_supports_multiple_render_targets(); | |
miu
2012/12/27 21:40:17
nit: const method, since this is just a simple get
ncarter (slow)
2013/01/07 22:49:10
Done.
| |
73 IDirect3DDevice9* device(); | 157 IDirect3DDevice9* device(); |
74 | 158 |
75 base::win::ScopedComPtr<IDirect3DDevice9> device_; | 159 base::win::ScopedComPtr<IDirect3DDevice9> device_; |
76 base::win::ScopedComPtr<IDirect3DVertexShader9> vertex_shaders_[NUM_SHADERS]; | 160 base::win::ScopedComPtr<IDirect3DVertexShader9> vertex_shaders_[NUM_SHADERS]; |
77 base::win::ScopedComPtr<IDirect3DPixelShader9> pixel_shaders_[NUM_SHADERS]; | 161 base::win::ScopedComPtr<IDirect3DPixelShader9> pixel_shaders_[NUM_SHADERS]; |
162 bool device_supports_multiple_render_targets_; | |
78 DISALLOW_COPY_AND_ASSIGN(AcceleratedSurfaceTransformer); | 163 DISALLOW_COPY_AND_ASSIGN(AcceleratedSurfaceTransformer); |
79 }; | 164 }; |
80 | 165 |
81 #endif // UI_SURFACE_ACCELERATED_SURFACE_TRANSFORMER_WIN_H_ | 166 #endif // UI_SURFACE_ACCELERATED_SURFACE_TRANSFORMER_WIN_H_ |
OLD | NEW |