2015-01-01 17:51:56 +01:00
|
|
|
// Copyright (c) 2014 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 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.
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/osr/software_output_device_osr.h"
|
2015-01-01 17:51:56 +01:00
|
|
|
|
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/osr/render_widget_host_view_osr.h"
|
2015-01-01 17:51:56 +01:00
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
#include "third_party/skia/src/core/SkDevice.h"
|
2015-01-01 17:51:56 +01:00
|
|
|
#include "ui/compositor/compositor.h"
|
|
|
|
#include "ui/gfx/skia_util.h"
|
|
|
|
|
|
|
|
CefSoftwareOutputDeviceOSR::CefSoftwareOutputDeviceOSR(
|
|
|
|
ui::Compositor* compositor,
|
|
|
|
bool transparent,
|
|
|
|
const OnPaintCallback& callback)
|
2017-05-17 11:29:28 +02:00
|
|
|
: transparent_(transparent), callback_(callback), active_(false) {
|
2015-01-01 17:51:56 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
DCHECK(!callback_.is_null());
|
|
|
|
}
|
|
|
|
|
|
|
|
CefSoftwareOutputDeviceOSR::~CefSoftwareOutputDeviceOSR() {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefSoftwareOutputDeviceOSR::Resize(const gfx::Size& viewport_pixel_size,
|
|
|
|
float scale_factor) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
if (viewport_pixel_size_ == viewport_pixel_size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
viewport_pixel_size_ = viewport_pixel_size;
|
|
|
|
|
|
|
|
canvas_.reset(NULL);
|
|
|
|
bitmap_.reset(new SkBitmap);
|
|
|
|
bitmap_->allocN32Pixels(viewport_pixel_size.width(),
|
2017-05-17 11:29:28 +02:00
|
|
|
viewport_pixel_size.height(), !transparent_);
|
2015-01-01 17:51:56 +01:00
|
|
|
if (bitmap_->drawsNothing()) {
|
|
|
|
NOTREACHED();
|
|
|
|
bitmap_.reset(NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (transparent_)
|
|
|
|
bitmap_->eraseARGB(0, 0, 0, 0);
|
|
|
|
|
|
|
|
canvas_.reset(new SkCanvas(*bitmap_.get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
SkCanvas* CefSoftwareOutputDeviceOSR::BeginPaint(const gfx::Rect& damage_rect) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
DCHECK(canvas_.get());
|
|
|
|
DCHECK(bitmap_.get());
|
|
|
|
|
|
|
|
damage_rect_ = damage_rect;
|
|
|
|
|
|
|
|
return canvas_.get();
|
|
|
|
}
|
|
|
|
|
2015-08-14 16:41:08 +02:00
|
|
|
void CefSoftwareOutputDeviceOSR::EndPaint() {
|
2015-01-01 17:51:56 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
DCHECK(canvas_.get());
|
|
|
|
DCHECK(bitmap_.get());
|
|
|
|
|
|
|
|
if (!bitmap_.get())
|
|
|
|
return;
|
|
|
|
|
2017-10-20 19:45:20 +02:00
|
|
|
viz::SoftwareOutputDevice::EndPaint();
|
2015-01-01 17:51:56 +01:00
|
|
|
|
|
|
|
if (active_)
|
|
|
|
OnPaint(damage_rect_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefSoftwareOutputDeviceOSR::SetActive(bool active) {
|
|
|
|
if (active == active_)
|
|
|
|
return;
|
|
|
|
active_ = active;
|
|
|
|
|
|
|
|
// Call OnPaint immediately if deactivated while a damage rect is pending.
|
|
|
|
if (!active_ && !pending_damage_rect_.IsEmpty())
|
|
|
|
OnPaint(pending_damage_rect_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefSoftwareOutputDeviceOSR::Invalidate(const gfx::Rect& damage_rect) {
|
|
|
|
if (pending_damage_rect_.IsEmpty())
|
|
|
|
pending_damage_rect_ = damage_rect;
|
|
|
|
else
|
|
|
|
pending_damage_rect_.Union(damage_rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefSoftwareOutputDeviceOSR::OnPaint(const gfx::Rect& damage_rect) {
|
|
|
|
gfx::Rect rect = damage_rect;
|
|
|
|
if (!pending_damage_rect_.IsEmpty()) {
|
|
|
|
rect.Union(pending_damage_rect_);
|
|
|
|
pending_damage_rect_.SetRect(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
rect.Intersect(gfx::Rect(viewport_pixel_size_));
|
|
|
|
if (rect.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
callback_.Run(rect, bitmap_->width(), bitmap_->height(),
|
|
|
|
bitmap_->getPixels());
|
|
|
|
}
|