Commit 08a21f37 authored by skaslev@chromium.org's avatar skaslev@chromium.org

[Aura] Fix software compositing blits to WS_EX_LAYERED windows.

BUG=241146

Review URL: https://chromiumcodereview.appspot.com/15821012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203984 0039d316-1c4b-4281-b951-d872f2087c98
parent b75e9e2b
...@@ -8,16 +8,20 @@ ...@@ -8,16 +8,20 @@
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkDevice.h" #include "third_party/skia/include/core/SkDevice.h"
#include "ui/compositor/compositor.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/gdi_util.h"
namespace content { namespace content {
SoftwareOutputDeviceWin::SoftwareOutputDeviceWin(ui::Compositor* compositor) SoftwareOutputDeviceWin::SoftwareOutputDeviceWin(ui::Compositor* compositor)
: compositor_(compositor) { : hwnd_(compositor->widget()),
is_hwnd_composited_(false) {
// TODO(skaslev) Remove this when crbug.com/180702 is fixed. // TODO(skaslev) Remove this when crbug.com/180702 is fixed.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
hwnd_ = compositor->widget(); LONG style = GetWindowLong(hwnd_, GWL_EXSTYLE);
is_hwnd_composited_ = !!(style & WS_EX_COMPOSITED);
} }
SoftwareOutputDeviceWin::~SoftwareOutputDeviceWin() { SoftwareOutputDeviceWin::~SoftwareOutputDeviceWin() {
...@@ -27,18 +31,30 @@ SoftwareOutputDeviceWin::~SoftwareOutputDeviceWin() { ...@@ -27,18 +31,30 @@ SoftwareOutputDeviceWin::~SoftwareOutputDeviceWin() {
void SoftwareOutputDeviceWin::Resize(gfx::Size viewport_size) { void SoftwareOutputDeviceWin::Resize(gfx::Size viewport_size) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
cc::SoftwareOutputDevice::Resize(viewport_size); if (viewport_size_ == viewport_size)
return;
viewport_size_ = viewport_size;
contents_.reset(new gfx::Canvas(viewport_size, ui::SCALE_FACTOR_100P, false));
memset(&bitmap_info_, 0, sizeof(bitmap_info_)); memset(&bitmap_info_, 0, sizeof(bitmap_info_));
gfx::CreateBitmapHeader(viewport_size_.width(), viewport_size_.height(), gfx::CreateBitmapHeader(viewport_size_.width(), viewport_size_.height(),
&bitmap_info_.bmiHeader); &bitmap_info_.bmiHeader);
} }
SkCanvas* SoftwareOutputDeviceWin::BeginPaint(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) { void SoftwareOutputDeviceWin::EndPaint(cc::SoftwareFrameData* frame_data) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(device_); DCHECK(contents_);
DCHECK(frame_data == NULL); DCHECK(frame_data == NULL);
if (!device_) if (!contents_)
return; return;
gfx::Rect rect = damage_rect_; gfx::Rect rect = damage_rect_;
...@@ -46,16 +62,38 @@ void SoftwareOutputDeviceWin::EndPaint(cc::SoftwareFrameData* frame_data) { ...@@ -46,16 +62,38 @@ void SoftwareOutputDeviceWin::EndPaint(cc::SoftwareFrameData* frame_data) {
if (rect.IsEmpty()) if (rect.IsEmpty())
return; return;
const SkBitmap& bitmap = device_->accessBitmap(false); SkCanvas* canvas = contents_->sk_canvas();
HDC hdc = ::GetDC(hwnd_); DCHECK(canvas);
gfx::StretchDIBits(hdc, if (is_hwnd_composited_) {
rect.x(), rect.y(), RECT wr;
rect.width(), rect.height(), GetWindowRect(hwnd_, &wr);
rect.x(), rect.y(), SIZE size = {wr.right - wr.left, wr.bottom - wr.top};
rect.width(), rect.height(), POINT position = {wr.left, wr.top};
bitmap.getPixels(), POINT zero = {0, 0};
&bitmap_info_); BLENDFUNCTION blend = {AC_SRC_OVER, 0x00, 0xFF, AC_SRC_ALPHA};
::ReleaseDC(hwnd_, hdc);
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 {
SkDevice* device = canvas->getDevice();
const SkBitmap& bitmap = device->accessBitmap(false);
HDC hdc = ::GetDC(hwnd_);
gfx::StretchDIBits(hdc,
rect.x(), rect.y(),
rect.width(), rect.height(),
rect.x(), rect.y(),
rect.width(), rect.height(),
bitmap.getPixels(),
&bitmap_info_);
::ReleaseDC(hwnd_, hdc);
}
} }
} // namespace content } // namespace content
...@@ -5,10 +5,15 @@ ...@@ -5,10 +5,15 @@
#ifndef CONTENT_BROWSER_RENDERER_HOST_SOFTWARE_OUTPUT_DEVICE_WIN_H_ #ifndef CONTENT_BROWSER_RENDERER_HOST_SOFTWARE_OUTPUT_DEVICE_WIN_H_
#define CONTENT_BROWSER_RENDERER_HOST_SOFTWARE_OUTPUT_DEVICE_WIN_H_ #define CONTENT_BROWSER_RENDERER_HOST_SOFTWARE_OUTPUT_DEVICE_WIN_H_
#include "base/memory/scoped_ptr.h"
#include "cc/output/software_output_device.h" #include "cc/output/software_output_device.h"
#include <windows.h> #include <windows.h>
namespace gfx {
class Canvas;
}
namespace ui { namespace ui {
class Compositor; class Compositor;
} }
...@@ -18,17 +23,17 @@ namespace content { ...@@ -18,17 +23,17 @@ namespace content {
class SoftwareOutputDeviceWin : public cc::SoftwareOutputDevice { class SoftwareOutputDeviceWin : public cc::SoftwareOutputDevice {
public: public:
explicit SoftwareOutputDeviceWin(ui::Compositor* compositor); explicit SoftwareOutputDeviceWin(ui::Compositor* compositor);
virtual ~SoftwareOutputDeviceWin(); virtual ~SoftwareOutputDeviceWin();
virtual void Resize(gfx::Size viewport_size) OVERRIDE; virtual void Resize(gfx::Size viewport_size) OVERRIDE;
virtual SkCanvas* BeginPaint(gfx::Rect damage_rect) OVERRIDE;
virtual void EndPaint(cc::SoftwareFrameData* frame_data) OVERRIDE; virtual void EndPaint(cc::SoftwareFrameData* frame_data) OVERRIDE;
private: private:
ui::Compositor* compositor_;
HWND hwnd_; HWND hwnd_;
BITMAPINFO bitmap_info_; BITMAPINFO bitmap_info_;
scoped_ptr<gfx::Canvas> contents_;
bool is_hwnd_composited_;
}; };
} // namespace content } // namespace content
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment