diff options
author | ccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-16 05:12:59 +0000 |
---|---|---|
committer | ccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-16 05:12:59 +0000 |
commit | b7c82d74fc966922b046b53ea4ef1428cf616208 (patch) | |
tree | 512ba643745f7113686742d70e07119c36e6d036 /content/browser/compositor/software_output_device_win.cc | |
parent | 5f56d196352243a42d86fe9324f608d0dc1105b7 (diff) | |
download | chromium_src-b7c82d74fc966922b046b53ea4ef1428cf616208.zip chromium_src-b7c82d74fc966922b046b53ea4ef1428cf616208.tar.gz chromium_src-b7c82d74fc966922b046b53ea4ef1428cf616208.tar.bz2 |
Add the UI compositor to the Mac build
Move the bulk of the files in content/browser/aura to
content/browser/compositor, since they're not aura-specific.
Build all of those files in the Mac build, and add ui/compositor
to the dependencies of the Mac build. These files will soon only
be excluded from the Android build.
BUG=314190
Review URL: https://codereview.chromium.org/137893007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245131 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/compositor/software_output_device_win.cc')
-rw-r--r-- | content/browser/compositor/software_output_device_win.cc | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/content/browser/compositor/software_output_device_win.cc b/content/browser/compositor/software_output_device_win.cc new file mode 100644 index 0000000..72f2474 --- /dev/null +++ b/content/browser/compositor/software_output_device_win.cc @@ -0,0 +1,103 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/compositor/software_output_device_win.h" + +#include "content/public/browser/browser_thread.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkDevice.h" +#include "ui/compositor/compositor.h" +#include "ui/gfx/canvas.h" +#include "ui/gfx/canvas_skia_paint.h" +#include "ui/gfx/gdi_util.h" +#include "ui/gfx/skia_util.h" + +namespace content { + +SoftwareOutputDeviceWin::SoftwareOutputDeviceWin(ui::Compositor* compositor) + : hwnd_(compositor->widget()), + is_hwnd_composited_(false) { + // TODO(skaslev) Remove this when crbug.com/180702 is fixed. + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + LONG style = GetWindowLong(hwnd_, GWL_EXSTYLE); + is_hwnd_composited_ = !!(style & WS_EX_COMPOSITED); +} + +SoftwareOutputDeviceWin::~SoftwareOutputDeviceWin() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); +} + +void SoftwareOutputDeviceWin::Resize(gfx::Size viewport_size) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + if (viewport_size_ == viewport_size) + return; + + viewport_size_ = viewport_size; + contents_.reset(new gfx::Canvas(viewport_size, 1.0f, true)); + memset(&bitmap_info_, 0, sizeof(bitmap_info_)); + gfx::CreateBitmapHeader(viewport_size_.width(), viewport_size_.height(), + &bitmap_info_.bmiHeader); +} + +SkCanvas* SoftwareOutputDeviceWin::BeginPaint(const gfx::Rect& damage_rect) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(contents_); + + damage_rect_ = damage_rect; + return contents_ ? contents_->sk_canvas() : NULL; +} + +void SoftwareOutputDeviceWin::EndPaint(cc::SoftwareFrameData* frame_data) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(contents_); + DCHECK(frame_data); + + if (!contents_) + return; + + SoftwareOutputDevice::EndPaint(frame_data); + + gfx::Rect rect = damage_rect_; + rect.Intersect(gfx::Rect(viewport_size_)); + if (rect.IsEmpty()) + return; + + SkCanvas* canvas = contents_->sk_canvas(); + DCHECK(canvas); + if (is_hwnd_composited_) { + RECT wr; + GetWindowRect(hwnd_, &wr); + SIZE size = {wr.right - wr.left, wr.bottom - wr.top}; + POINT position = {wr.left, wr.top}; + POINT zero = {0, 0}; + BLENDFUNCTION blend = {AC_SRC_OVER, 0x00, 0xFF, AC_SRC_ALPHA}; + + DWORD style = GetWindowLong(hwnd_, GWL_EXSTYLE); + style &= ~WS_EX_COMPOSITED; + style |= WS_EX_LAYERED; + SetWindowLong(hwnd_, GWL_EXSTYLE, style); + + HDC dib_dc = skia::BeginPlatformPaint(canvas); + ::UpdateLayeredWindow(hwnd_, NULL, &position, &size, dib_dc, &zero, + RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); + skia::EndPlatformPaint(canvas); + } else { + HDC hdc = ::GetDC(hwnd_); + RECT src_rect = rect.ToRECT(); + skia::DrawToNativeContext(canvas, hdc, rect.x(), rect.y(), &src_rect); + ::ReleaseDC(hwnd_, hdc); + } +} + +void SoftwareOutputDeviceWin::CopyToBitmap( + const gfx::Rect& rect, SkBitmap* output) { + DCHECK(contents_); + SkBaseDevice* device = contents_->sk_canvas()->getDevice(); + const SkBitmap& bitmap = device->accessBitmap(false); + bitmap.extractSubset(output, gfx::RectToSkIRect(rect)); +} + +} // namespace content |