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

Side by Side Diff: ui/gfx/surface/accelerated_surface_win.cc

Issue 9582003: Support browser side thumbnailing for GPU composited pages on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 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 | Annotate | Revision Log
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 #include "ui/gfx/surface/accelerated_surface_win.h" 5 #include "ui/gfx/surface/accelerated_surface_win.h"
6 6
7 #include <d3d9.h> 7 #include <d3d9.h>
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 AcceleratedPresenter(); 100 AcceleratedPresenter();
101 ~AcceleratedPresenter(); 101 ~AcceleratedPresenter();
102 102
103 void AsyncPresentAndAcknowledge(gfx::NativeWindow window, 103 void AsyncPresentAndAcknowledge(gfx::NativeWindow window,
104 const gfx::Size& size, 104 const gfx::Size& size,
105 int64 surface_id, 105 int64 surface_id,
106 const base::Closure& completion_task); 106 const base::Closure& completion_task);
107 107
108 bool Present(gfx::NativeWindow window); 108 bool Present(gfx::NativeWindow window);
109 109
110 bool CopyTo(const gfx::Size& size, std::vector<unsigned char>* buf);
111
110 void Suspend(); 112 void Suspend();
111 113
112 private: 114 private:
113 void DoInitialize(); 115 void DoInitialize();
114 void DoResize(const gfx::Size& size); 116 void DoResize(const gfx::Size& size);
115 void DoReset(); 117 void DoReset();
116 void DoPresentAndAcknowledge(gfx::NativeWindow window, 118 void DoPresentAndAcknowledge(gfx::NativeWindow window,
117 const gfx::Size& size, 119 const gfx::Size& size,
118 int64 surface_id, 120 int64 surface_id,
119 const base::Closure& completion_task); 121 const base::Closure& completion_task);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 hr = query_->GetData(NULL, 0, D3DGETDATA_FLUSH); 258 hr = query_->GetData(NULL, 0, D3DGETDATA_FLUSH);
257 259
258 if (hr == S_FALSE) 260 if (hr == S_FALSE)
259 Sleep(0); 261 Sleep(0);
260 } while (hr == S_FALSE); 262 } while (hr == S_FALSE);
261 } 263 }
262 264
263 return true; 265 return true;
264 } 266 }
265 267
268 bool AcceleratedPresenter::CopyTo(const gfx::Size& size,
269 std::vector<unsigned char>* buf) {
270 base::win::ScopedComPtr<IDirect3DSurface9> render_target;
apatrick_chromium 2012/03/07 20:39:37 Make the first line of this function: base::AutoLo
mazda 2012/03/08 13:14:28 Done.
271 HRESULT hr = device_->GetRenderTarget(0, render_target.Receive());
apatrick_chromium 2012/03/07 20:39:37 I just changed this unfortunately but you should b
mazda 2012/03/08 13:14:28 Done.
272 if (FAILED(hr))
273 return false;
274
275 base::win::ScopedComPtr<IDirect3DSurface9> temp_render_target;
276 hr = device_->CreateRenderTarget(
277 size.width(),
278 size.height(),
279 D3DFMT_A8R8G8B8,
280 D3DMULTISAMPLE_NONE,
281 0,
282 TRUE,
283 temp_render_target.Receive(),
284 NULL);
285 if (FAILED(hr))
286 return false;
287
288 // Copy the render target to a temporary render target first because
289 // IDirect3DDevice9::StretchRect does not support copying to the surface in
290 // the system memory.
291 hr = device_->StretchRect(render_target, NULL, temp_render_target, NULL,
apatrick_chromium 2012/03/07 20:39:37 If the downsampling reduces the size by more than
mazda 2012/03/08 13:14:28 Done.
292 D3DTEXF_LINEAR);
293 if (FAILED(hr))
294 return false;
295
296 base::win::ScopedComPtr<IDirect3DSurface9> temp_surface;
297 hr = device_->CreateOffscreenPlainSurface(
298 size.width(),
299 size.height(),
300 D3DFMT_A8R8G8B8,
301 D3DPOOL_SYSTEMMEM,
302 temp_surface.Receive(),
303 NULL);
apatrick_chromium 2012/03/07 20:39:37 HANDLE handle = reinterpret_cast<HANDLE>(&buf[0]);
mazda 2012/03/08 13:14:28 Thanks. This is much simpler and cleaner.
304 if (FAILED(hr))
305 return false;
306
307 // Then copy the data in the temporary render target to a temporary surface
308 // in the system memory that is used for the final copy to |buf|.
309 hr = device_->GetRenderTargetData(temp_render_target, temp_surface);
310 if (FAILED(hr))
311 return false;
312
313 const size_t buf_size = static_cast<size_t>(4 * size.GetArea());
314 if (buf->size() < buf_size) {
315 buf->resize(buf_size);
316 }
317
318 D3DLOCKED_RECT locked_rect;
apatrick_chromium 2012/03/07 20:39:37 ... thereby eliminating the need for lines 318 thr
mazda 2012/03/08 13:14:28 Done.
319 const int kLockFlags = D3DLOCK_READONLY | D3DLOCK_NO_DIRTY_UPDATE |
320 D3DLOCK_NOOVERWRITE;
321 temp_surface->LockRect(&locked_rect, NULL, kLockFlags);
apatrick_chromium 2012/03/07 20:39:37 If these lines remain, I would not assume LockRect
mazda 2012/03/08 13:14:28 I deleted this code block following your comment a
322 const int kBytesPerRow = 4 * size.width();
323 for (int y = 0; y < size.height(); ++y) {
324 unsigned char* p1 =
325 static_cast<unsigned char*>(locked_rect.pBits) + locked_rect.Pitch * y;
326 unsigned char* p2 =
327 static_cast<unsigned char*>(&(*buf)[0]) + kBytesPerRow * y;
328 memcpy(p2, p1, kBytesPerRow);
329 }
330 temp_surface->UnlockRect();
331
332 return true;
333 }
334
266 void AcceleratedPresenter::Suspend() { 335 void AcceleratedPresenter::Suspend() {
267 // Resize the swap chain to 1 x 1 to save memory while the presenter is not 336 // Resize the swap chain to 1 x 1 to save memory while the presenter is not
268 // in use. 337 // in use.
269 pending_size_ = gfx::Size(1, 1); 338 pending_size_ = gfx::Size(1, 1);
270 base::AtomicRefCountInc(&num_pending_resizes_); 339 base::AtomicRefCountInc(&num_pending_resizes_);
271 340
272 g_present_thread_pool.Pointer()->PostTask( 341 g_present_thread_pool.Pointer()->PostTask(
273 thread_affinity_, 342 thread_affinity_,
274 FROM_HERE, 343 FROM_HERE,
275 base::Bind(&AcceleratedPresenter::DoResize, 344 base::Bind(&AcceleratedPresenter::DoResize,
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 presenter_->AsyncPresentAndAcknowledge(window, 574 presenter_->AsyncPresentAndAcknowledge(window,
506 size, 575 size,
507 surface_id, 576 surface_id,
508 completion_task); 577 completion_task);
509 } 578 }
510 579
511 bool AcceleratedSurface::Present(HWND window) { 580 bool AcceleratedSurface::Present(HWND window) {
512 return presenter_->Present(window); 581 return presenter_->Present(window);
513 } 582 }
514 583
584 bool AcceleratedSurface::CopyTo(const gfx::Size& size,
585 std::vector<unsigned char>* buf) {
586 return presenter_->CopyTo(size, buf);
587 }
588
515 void AcceleratedSurface::Suspend() { 589 void AcceleratedSurface::Suspend() {
516 presenter_->Suspend(); 590 presenter_->Suspend();
517 } 591 }
518
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698