Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: ui/surface/accelerated_surface_transformer_win.h

Issue 11280318: YUV conversion on the GPU. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: "Yet more line endings." Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/surface/DEPS ('k') | ui/surface/accelerated_surface_transformer_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/gtest_prod_util.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
12 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
13 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
14 #include "base/win/scoped_comptr.h" 15 #include "base/win/scoped_comptr.h"
15 #include "ui/gfx/native_widget_types.h" 16 #include "ui/gfx/native_widget_types.h"
16 #include "ui/gfx/size.h" 17 #include "ui/gfx/size.h"
17 #include "ui/surface/surface_export.h" 18 #include "ui/surface/surface_export.h"
18 19
19 namespace gfx { 20 namespace gfx {
(...skipping 23 matching lines...) Expand all
43 // work around particular driver bugs, and should only be called at shutdown. 44 // work around particular driver bugs, and should only be called at shutdown.
44 // TODO(ncarter): Update the leak expectations before checkin. 45 // TODO(ncarter): Update the leak expectations before checkin.
45 void DetachAll(); 46 void DetachAll();
46 47
47 // Draw a textured quad to a surface, flipping orientation in the y direction. 48 // Draw a textured quad to a surface, flipping orientation in the y direction.
48 bool CopyInverted( 49 bool CopyInverted(
49 IDirect3DTexture9* src_texture, 50 IDirect3DTexture9* src_texture,
50 IDirect3DSurface9* dst_surface, 51 IDirect3DSurface9* dst_surface,
51 const gfx::Size& dst_size); 52 const gfx::Size& dst_size);
52 53
54 // Draw a textured quad to a surface.
55 bool Copy(
56 IDirect3DTexture9* src_texture,
57 IDirect3DSurface9* dst_surface,
58 const gfx::Size& dst_size);
59
53 // Resize a surface using repeated bilinear interpolation. 60 // Resize a surface using repeated bilinear interpolation.
54 bool ResizeBilinear( 61 bool ResizeBilinear(
55 IDirect3DSurface9* src_surface, 62 IDirect3DSurface9* src_surface,
56 const gfx::Rect& src_subrect, 63 const gfx::Rect& src_subrect,
57 IDirect3DSurface9* dst_surface); 64 IDirect3DSurface9* dst_surface);
58 65
66 // Color format conversion from RGB to planar YV12 (also known as YUV420).
67 //
68 // YV12 is effectively a twelve bit per pixel format consisting of a full-
69 // size y (luminance) plane and half-width, half-height u and v (blue and
70 // red chrominance) planes. This method will allocate three lockable surfaces,
71 // one for each plane, and return them via the arguments |dst_y|, |dst_u|,
72 // and |dst_v|. These surface will be created with an ARGB D3DFORMAT, but
73 // should be interpreted as the appropriate single-byte format when locking.
74 //
75 // The dimensions of the outputs (when interpreted as single-component data)
76 // are as follows:
77 // |dst_y| : width and height exactly |dst_size|
78 // |dst_u| : width and height are each half of |dst_size|, rounded up.
79 // |dst_v| : width and height are each half of |dst_size|, rounded up.
80 //
81 // If |src_texture|'s dimensions do not match |dst_size|, the source will be
82 // bilinearly interpolated during conversion.
83 //
84 // Returns true if successful. Caller must be certain to free the buffers
85 // even if this function returns false.
86 bool TransformRGBToYV12(
87 IDirect3DTexture9* src_texture,
88 const gfx::Size& dst_size,
89 IDirect3DSurface9** dst_y,
90 IDirect3DSurface9** dst_u,
91 IDirect3DSurface9** dst_v);
92
59 private: 93 private:
94 friend class AcceleratedSurfaceTransformerTest;
95 FRIEND_TEST_ALL_PREFIXES(AcceleratedSurfaceTransformerTest, Init);
96
60 enum ShaderCombo { 97 enum ShaderCombo {
61 SIMPLE_TEXTURE, 98 ONE_TEXTURE,
99 RGB_TO_YV12_FAST__PASS_1_OF_2,
100 RGB_TO_YV12_FAST__PASS_2_OF_2,
101 RGB_TO_YV12_SLOW__PASS_1_OF_3,
102 RGB_TO_YV12_SLOW__PASS_2_OF_3,
103 RGB_TO_YV12_SLOW__PASS_3_OF_3,
62 NUM_SHADERS 104 NUM_SHADERS
63 }; 105 };
64 106
107 // Efficient RGB->YV12 in two passes, but requires a device capable of writing
108 // multiple render targets at the same time.
109 //
110 // Returns true if successful.
111 bool TransformRGBToYV12_MRT(
112 IDirect3DTexture9* src_surface,
113 const gfx::Size& dst_size,
114 const gfx::Size& packed_y_size,
115 const gfx::Size& packed_uv_size,
116 IDirect3DSurface9* dst_y,
117 IDirect3DSurface9* dst_u,
118 IDirect3DSurface9* dst_v);
119
120 // Slower, less efficient RGB->YV12; does not require the device to have
121 // multiple render target capability. Runs at about half speed of the fast
122 // path.
123 //
124 // Returns true if successful.
125 bool TransformRGBToYV12_WithoutMRT(
126 IDirect3DTexture9* src_surface,
127 const gfx::Size& dst_size,
128 const gfx::Size& packed_y_size,
129 const gfx::Size& packed_uv_size,
130 IDirect3DSurface9* dst_y,
131 IDirect3DSurface9* dst_u,
132 IDirect3DSurface9* dst_v);
133
134 // Helper to allocate appropriately size YUV buffers, accounting for various
135 // roundings. The sizes of the buffers (in terms of ARGB pixels) are returned
136 // as |packed_y_size| and |packed_uv_size|.
137 //
138 // Returns true if successful. Caller must be certain to free the buffers
139 // even if this function returns false.
140 bool AllocYUVBuffers(
141 const gfx::Size& dst_size,
142 gfx::Size* packed_y_size,
143 gfx::Size* packed_uv_size,
144 IDirect3DSurface9** dst_y,
145 IDirect3DSurface9** dst_u,
146 IDirect3DSurface9** dst_v);
147
148 bool CopyWithTextureScale(
149 IDirect3DTexture9* src_texture,
150 IDirect3DSurface9* dst_surface,
151 const gfx::Size& dst_size,
152 float texture_scale_x,
153 float texture_scale_y);
154
65 // Set the active vertex and pixel shader combination. 155 // Set the active vertex and pixel shader combination.
156 //
157 // Returns true if successful.
66 bool SetShaderCombo(ShaderCombo combo); 158 bool SetShaderCombo(ShaderCombo combo);
67 159
68 // Intitializes a vertex and pixel shader combination from compiled bytecode. 160 // Compiles a vertex and pixel shader combination, if not already compiled.
69 bool InitShaderCombo(const BYTE vertex_shader_instructions[], 161 //
70 const BYTE pixel_shader_instructions[], 162 // Returns true if successful.
71 ShaderCombo shader_combo_name); 163 bool CompileShaderCombo(ShaderCombo shader_combo_name);
164
165 bool DoInit(IDirect3DDevice9* device);
166
167 void DrawScreenAlignedQuad(const gfx::Size& dst_size);
168
169 bool device_supports_multiple_render_targets() const {
170 return device_supports_multiple_render_targets_;
171 }
72 172
73 IDirect3DDevice9* device(); 173 IDirect3DDevice9* device();
74 174
75 base::win::ScopedComPtr<IDirect3DDevice9> device_; 175 base::win::ScopedComPtr<IDirect3DDevice9> device_;
76 base::win::ScopedComPtr<IDirect3DVertexShader9> vertex_shaders_[NUM_SHADERS]; 176 base::win::ScopedComPtr<IDirect3DVertexShader9> vertex_shaders_[NUM_SHADERS];
77 base::win::ScopedComPtr<IDirect3DPixelShader9> pixel_shaders_[NUM_SHADERS]; 177 base::win::ScopedComPtr<IDirect3DPixelShader9> pixel_shaders_[NUM_SHADERS];
178 bool device_supports_multiple_render_targets_;
179 const BYTE* vertex_shader_sources_[NUM_SHADERS];
180 const BYTE* pixel_shader_sources_[NUM_SHADERS];
78 DISALLOW_COPY_AND_ASSIGN(AcceleratedSurfaceTransformer); 181 DISALLOW_COPY_AND_ASSIGN(AcceleratedSurfaceTransformer);
79 }; 182 };
80 183
81 #endif // UI_SURFACE_ACCELERATED_SURFACE_TRANSFORMER_WIN_H_ 184 #endif // UI_SURFACE_ACCELERATED_SURFACE_TRANSFORMER_WIN_H_
OLDNEW
« no previous file with comments | « ui/surface/DEPS ('k') | ui/surface/accelerated_surface_transformer_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698