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

Side by Side Diff: media/gpu/d3d11_video_decode_accelerator_win.cc

Issue 2565123002: Unify code to query D3D device object from ANGLE (Closed)
Patch Set: add export Created 4 years 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
« no previous file with comments | « no previous file | media/gpu/dxva_video_decode_accelerator_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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 // This is defined here to ensure the D3D11, D3D9, and DXVA includes through 5 // This is defined here to ensure the D3D11, D3D9, and DXVA includes through
6 // this header have their GUIDs intialized. 6 // this header have their GUIDs intialized.
7 #define INITGUID 7 #define INITGUID
8 #include "media/gpu/d3d11_video_decode_accelerator_win.h" 8 #include "media/gpu/d3d11_video_decode_accelerator_win.h"
9 #undef INITGUID 9 #undef INITGUID
10 10
11 #include <d3d11.h> 11 #include <d3d11.h>
12 12
13 #include "base/bits.h" 13 #include "base/bits.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/memory/shared_memory.h" 15 #include "base/memory/shared_memory.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
18 #include "base/win/scoped_comptr.h" 18 #include "base/win/scoped_comptr.h"
19 #include "media/gpu/d3d11_h264_accelerator.h" 19 #include "media/gpu/d3d11_h264_accelerator.h"
20 #include "media/gpu/h264_decoder.h" 20 #include "media/gpu/h264_decoder.h"
21 #include "media/gpu/h264_dpb.h" 21 #include "media/gpu/h264_dpb.h"
22 #include "third_party/angle/include/EGL/egl.h"
23 #include "third_party/angle/include/EGL/eglext.h"
24 #include "ui/gfx/color_space.h" 22 #include "ui/gfx/color_space.h"
23 #include "ui/gl/gl_angle_util_win.h"
25 #include "ui/gl/gl_bindings.h" 24 #include "ui/gl/gl_bindings.h"
26 #include "ui/gl/gl_context.h"
27 #include "ui/gl/gl_surface_egl.h"
28 25
29 namespace media { 26 namespace media {
30 27
31 #define RETURN_ON_FAILURE(result, log, ret) \ 28 #define RETURN_ON_FAILURE(result, log, ret) \
32 do { \ 29 do { \
33 if (!(result)) { \ 30 if (!(result)) { \
34 DLOG(ERROR) << log; \ 31 DLOG(ERROR) << log; \
35 return ret; \ 32 return ret; \
36 } \ 33 } \
37 } while (0) 34 } while (0)
38 35
39 // Helper function to query the ANGLE device object. The template argument T
40 // identifies the device interface being queried. IDirect3DDevice9Ex for d3d9
41 // and ID3D11Device for dx11.
42 template <class T>
43 base::win::ScopedComPtr<T> QueryDeviceObjectFromANGLE(int object_type) {
44 base::win::ScopedComPtr<T> device_object;
45
46 EGLDisplay egl_display = nullptr;
47 intptr_t egl_device = 0;
48 intptr_t device = 0;
49
50 {
51 TRACE_EVENT0("gpu", "QueryDeviceObjectFromANGLE. GetHardwareDisplay");
52 egl_display = gl::GLSurfaceEGL::GetHardwareDisplay();
53 }
54
55 RETURN_ON_FAILURE(gl::GLSurfaceEGL::HasEGLExtension("EGL_EXT_device_query"),
56 "EGL_EXT_device_query missing", device_object);
57
58 PFNEGLQUERYDISPLAYATTRIBEXTPROC QueryDisplayAttribEXT = nullptr;
59
60 {
61 TRACE_EVENT0("gpu", "QueryDeviceObjectFromANGLE. eglGetProcAddress");
62
63 QueryDisplayAttribEXT = reinterpret_cast<PFNEGLQUERYDISPLAYATTRIBEXTPROC>(
64 eglGetProcAddress("eglQueryDisplayAttribEXT"));
65
66 RETURN_ON_FAILURE(
67 QueryDisplayAttribEXT,
68 "Failed to get the eglQueryDisplayAttribEXT function from ANGLE",
69 device_object);
70 }
71
72 PFNEGLQUERYDEVICEATTRIBEXTPROC QueryDeviceAttribEXT = nullptr;
73
74 {
75 TRACE_EVENT0("gpu", "QueryDeviceObjectFromANGLE. eglGetProcAddress");
76
77 QueryDeviceAttribEXT = reinterpret_cast<PFNEGLQUERYDEVICEATTRIBEXTPROC>(
78 eglGetProcAddress("eglQueryDeviceAttribEXT"));
79
80 RETURN_ON_FAILURE(
81 QueryDeviceAttribEXT,
82 "Failed to get the eglQueryDeviceAttribEXT function from ANGLE",
83 device_object);
84 }
85
86 {
87 TRACE_EVENT0("gpu", "QueryDeviceObjectFromANGLE. QueryDisplayAttribEXT");
88
89 RETURN_ON_FAILURE(
90 QueryDisplayAttribEXT(egl_display, EGL_DEVICE_EXT, &egl_device),
91 "The eglQueryDisplayAttribEXT function failed to get the EGL device",
92 device_object);
93 }
94
95 RETURN_ON_FAILURE(egl_device, "Failed to get the EGL device", device_object);
96
97 {
98 TRACE_EVENT0("gpu", "QueryDeviceObjectFromANGLE. QueryDisplayAttribEXT");
99
100 RETURN_ON_FAILURE(
101 QueryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(egl_device),
102 object_type, &device),
103 "The eglQueryDeviceAttribEXT function failed to get the device",
104 device_object);
105
106 RETURN_ON_FAILURE(device, "Failed to get the ANGLE device", device_object);
107 }
108
109 device_object = reinterpret_cast<T*>(device);
110 return device_object;
111 }
112 36
113 D3D11VideoDecodeAccelerator::D3D11VideoDecodeAccelerator( 37 D3D11VideoDecodeAccelerator::D3D11VideoDecodeAccelerator(
114 const GetGLContextCallback& get_gl_context_cb, 38 const GetGLContextCallback& get_gl_context_cb,
115 const MakeGLContextCurrentCallback& make_context_current_cb) 39 const MakeGLContextCurrentCallback& make_context_current_cb)
116 : get_gl_context_cb_(get_gl_context_cb), 40 : get_gl_context_cb_(get_gl_context_cb),
117 make_context_current_cb_(make_context_current_cb) {} 41 make_context_current_cb_(make_context_current_cb) {}
118 42
119 D3D11VideoDecodeAccelerator::~D3D11VideoDecodeAccelerator() {} 43 D3D11VideoDecodeAccelerator::~D3D11VideoDecodeAccelerator() {}
120 44
121 bool D3D11VideoDecodeAccelerator::Initialize(const Config& config, 45 bool D3D11VideoDecodeAccelerator::Initialize(const Config& config,
122 Client* client) { 46 Client* client) {
123 client_ = client; 47 client_ = client;
124 make_context_current_cb_.Run(); 48 make_context_current_cb_.Run();
125 49
126 device_ = QueryDeviceObjectFromANGLE<ID3D11Device>(EGL_D3D11_DEVICE_ANGLE); 50 device_ = gl::QueryD3D11DeviceObjectFromANGLE();
127 device_->GetImmediateContext(device_context_.Receive()); 51 device_->GetImmediateContext(device_context_.Receive());
128 52
129 HRESULT hr = device_context_.QueryInterface(video_context_.Receive()); 53 HRESULT hr = device_context_.QueryInterface(video_context_.Receive());
130 CHECK(SUCCEEDED(hr)); 54 CHECK(SUCCEEDED(hr));
131 55
132 hr = device_.QueryInterface(video_device_.Receive()); 56 hr = device_.QueryInterface(video_device_.Receive());
133 CHECK(SUCCEEDED(hr)); 57 CHECK(SUCCEEDED(hr));
134 58
135 bool is_h264 = 59 bool is_h264 =
136 config.profile >= H264PROFILE_MIN && config.profile <= H264PROFILE_MAX; 60 config.profile >= H264PROFILE_MIN && config.profile <= H264PROFILE_MAX;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 } 242 }
319 243
320 void D3D11VideoDecodeAccelerator::OutputResult(D3D11PictureBuffer* buffer, 244 void D3D11VideoDecodeAccelerator::OutputResult(D3D11PictureBuffer* buffer,
321 size_t input_buffer_id) { 245 size_t input_buffer_id) {
322 buffer->set_in_client_use(true); 246 buffer->set_in_client_use(true);
323 Picture picture(buffer->picture_buffer().id(), input_buffer_id, 247 Picture picture(buffer->picture_buffer().id(), input_buffer_id,
324 gfx::Rect(0, 0), gfx::ColorSpace(), false); 248 gfx::Rect(0, 0), gfx::ColorSpace(), false);
325 client_->PictureReady(picture); 249 client_->PictureReady(picture);
326 } 250 }
327 } // namespace media 251 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/gpu/dxva_video_decode_accelerator_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698