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

Side by Side Diff: gpu/ipc/service/direct_composition_surface_win.cc

Issue 2766423003: Allow creating opaque swapchains in DirectCompositionSurfaceWin (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « gpu/ipc/service/direct_composition_surface_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #include "gpu/ipc/service/direct_composition_surface_win.h" 5 #include "gpu/ipc/service/direct_composition_surface_win.h"
6 6
7 #include "base/optional.h" 7 #include "base/optional.h"
8 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
9 #include "gpu/ipc/service/gpu_channel_manager.h" 9 #include "gpu/ipc/service/gpu_channel_manager.h"
10 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" 10 #include "gpu/ipc/service/gpu_channel_manager_delegate.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 void DirectCompositionSurfaceWin::ReleaseCurrentSurface() { 161 void DirectCompositionSurfaceWin::ReleaseCurrentSurface() {
162 ReleaseDrawTexture(true); 162 ReleaseDrawTexture(true);
163 dcomp_surface_.Release(); 163 dcomp_surface_.Release();
164 swap_chain_.Release(); 164 swap_chain_.Release();
165 } 165 }
166 166
167 void DirectCompositionSurfaceWin::InitializeSurface() { 167 void DirectCompositionSurfaceWin::InitializeSurface() {
168 DCHECK(!dcomp_surface_); 168 DCHECK(!dcomp_surface_);
169 DCHECK(!swap_chain_); 169 DCHECK(!swap_chain_);
170 if (enable_dc_layers_) { 170 if (enable_dc_layers_) {
171 // Always treat as premultiplied, because an underlay could cause it to
172 // become transparent.
171 HRESULT hr = dcomp_device_->CreateSurface( 173 HRESULT hr = dcomp_device_->CreateSurface(
172 size_.width(), size_.height(), DXGI_FORMAT_B8G8R8A8_UNORM, 174 size_.width(), size_.height(), DXGI_FORMAT_B8G8R8A8_UNORM,
173 DXGI_ALPHA_MODE_PREMULTIPLIED, dcomp_surface_.Receive()); 175 DXGI_ALPHA_MODE_PREMULTIPLIED, dcomp_surface_.Receive());
174 has_been_rendered_to_ = false; 176 has_been_rendered_to_ = false;
175 CHECK(SUCCEEDED(hr)); 177 CHECK(SUCCEEDED(hr));
176 } else { 178 } else {
179 DXGI_ALPHA_MODE alpha_mode =
180 has_alpha_ ? DXGI_ALPHA_MODE_PREMULTIPLIED : DXGI_ALPHA_MODE_IGNORE;
177 base::win::ScopedComPtr<IDXGIDevice> dxgi_device; 181 base::win::ScopedComPtr<IDXGIDevice> dxgi_device;
178 d3d11_device_.QueryInterface(dxgi_device.Receive()); 182 d3d11_device_.QueryInterface(dxgi_device.Receive());
179 base::win::ScopedComPtr<IDXGIAdapter> dxgi_adapter; 183 base::win::ScopedComPtr<IDXGIAdapter> dxgi_adapter;
180 dxgi_device->GetAdapter(dxgi_adapter.Receive()); 184 dxgi_device->GetAdapter(dxgi_adapter.Receive());
181 base::win::ScopedComPtr<IDXGIFactory2> dxgi_factory; 185 base::win::ScopedComPtr<IDXGIFactory2> dxgi_factory;
182 dxgi_adapter->GetParent(IID_PPV_ARGS(dxgi_factory.Receive())); 186 dxgi_adapter->GetParent(IID_PPV_ARGS(dxgi_factory.Receive()));
183 187
184 DXGI_SWAP_CHAIN_DESC1 desc = {}; 188 DXGI_SWAP_CHAIN_DESC1 desc = {};
185 desc.Width = size_.width(); 189 desc.Width = size_.width();
186 desc.Height = size_.height(); 190 desc.Height = size_.height();
187 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; 191 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
188 desc.Stereo = FALSE; 192 desc.Stereo = FALSE;
189 desc.SampleDesc.Count = 1; 193 desc.SampleDesc.Count = 1;
190 desc.BufferCount = 2; 194 desc.BufferCount = 2;
191 desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 195 desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
192 desc.Scaling = DXGI_SCALING_STRETCH; 196 desc.Scaling = DXGI_SCALING_STRETCH;
193 desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; 197 desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
194 desc.AlphaMode = DXGI_ALPHA_MODE_PREMULTIPLIED; 198 desc.AlphaMode = alpha_mode;
195 desc.Flags = 0; 199 desc.Flags = 0;
196 HRESULT hr = dxgi_factory->CreateSwapChainForComposition( 200 HRESULT hr = dxgi_factory->CreateSwapChainForComposition(
197 d3d11_device_.get(), &desc, nullptr, swap_chain_.Receive()); 201 d3d11_device_.get(), &desc, nullptr, swap_chain_.Receive());
198 has_been_rendered_to_ = false; 202 has_been_rendered_to_ = false;
199 first_swap_ = true; 203 first_swap_ = true;
200 CHECK(SUCCEEDED(hr)); 204 CHECK(SUCCEEDED(hr));
201 } 205 }
202 } 206 }
203 207
204 void DirectCompositionSurfaceWin::ReleaseDrawTexture(bool will_discard) { 208 void DirectCompositionSurfaceWin::ReleaseDrawTexture(bool will_discard) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 return false; 273 return false;
270 } 274 }
271 275
272 void* DirectCompositionSurfaceWin::GetHandle() { 276 void* DirectCompositionSurfaceWin::GetHandle() {
273 return real_surface_ ? real_surface_ : default_surface_; 277 return real_surface_ ? real_surface_ : default_surface_;
274 } 278 }
275 279
276 bool DirectCompositionSurfaceWin::Resize(const gfx::Size& size, 280 bool DirectCompositionSurfaceWin::Resize(const gfx::Size& size,
277 float scale_factor, 281 float scale_factor,
278 bool has_alpha) { 282 bool has_alpha) {
279 if (size == GetSize()) 283 if (size == GetSize() || has_alpha != has_alpha_)
sunnyps 2017/03/28 22:33:37 Shouldn't this be " && has_alpha == has_alpha_"?
280 return true; 284 return true;
281 285
282 // Force a resize and redraw (but not a move, activate, etc.). 286 // Force a resize and redraw (but not a move, activate, etc.).
283 if (!SetWindowPos(window_, nullptr, 0, 0, size.width(), size.height(), 287 if (!SetWindowPos(window_, nullptr, 0, 0, size.width(), size.height(),
284 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOCOPYBITS | 288 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOCOPYBITS |
285 SWP_NOOWNERZORDER | SWP_NOZORDER)) { 289 SWP_NOOWNERZORDER | SWP_NOZORDER)) {
286 return false; 290 return false;
287 } 291 }
288 size_ = size; 292 size_ = size;
293 has_alpha_ = has_alpha;
289 ScopedReleaseCurrent release_current(this); 294 ScopedReleaseCurrent release_current(this);
290 // New surface will be initialized in SetDrawRectangle. 295 // New surface will be initialized in SetDrawRectangle.
291 ReleaseCurrentSurface(); 296 ReleaseCurrentSurface();
292 297
293 return true; 298 return true;
294 } 299 }
295 300
296 gfx::SwapResult DirectCompositionSurfaceWin::SwapBuffers() { 301 gfx::SwapResult DirectCompositionSurfaceWin::SwapBuffers() {
297 { 302 {
298 ScopedReleaseCurrent release_current(this); 303 ScopedReleaseCurrent release_current(this);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 transform(transform), 455 transform(transform),
451 image(image), 456 image(image),
452 bounds_rect(bounds_rect), 457 bounds_rect(bounds_rect),
453 crop_rect(crop_rect) {} 458 crop_rect(crop_rect) {}
454 459
455 DirectCompositionSurfaceWin::Overlay::Overlay(const Overlay& overlay) = default; 460 DirectCompositionSurfaceWin::Overlay::Overlay(const Overlay& overlay) = default;
456 461
457 DirectCompositionSurfaceWin::Overlay::~Overlay() {} 462 DirectCompositionSurfaceWin::Overlay::~Overlay() {}
458 463
459 } // namespace gpu 464 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/ipc/service/direct_composition_surface_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698