This source file includes following definitions.
- Resize
- BeginPaint
- EndPaint
#include "content/browser/compositor/software_output_device_ozone.h"
#include "third_party/skia/include/core/SkDevice.h"
#include "ui/compositor/compositor.h"
#include "ui/gfx/ozone/surface_factory_ozone.h"
#include "ui/gfx/ozone/surface_ozone.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/vsync_provider.h"
namespace content {
SoftwareOutputDeviceOzone::SoftwareOutputDeviceOzone(ui::Compositor* compositor)
: compositor_(compositor) {
gfx::SurfaceFactoryOzone* factory = gfx::SurfaceFactoryOzone::GetInstance();
if (factory->InitializeHardware() != gfx::SurfaceFactoryOzone::INITIALIZED)
LOG(FATAL) << "Failed to initialize hardware in OZONE";
surface_ozone_ = factory->CreateSurfaceForWidget(compositor_->widget());
if (!surface_ozone_->InitializeCanvas())
LOG(FATAL) << "Failed to initialize canvas";
vsync_provider_ = surface_ozone_->CreateVSyncProvider();
}
SoftwareOutputDeviceOzone::~SoftwareOutputDeviceOzone() {
}
void SoftwareOutputDeviceOzone::Resize(const gfx::Size& viewport_size) {
if (viewport_size_ == viewport_size)
return;
viewport_size_ = viewport_size;
surface_ozone_->ResizeCanvas(viewport_size_);
}
SkCanvas* SoftwareOutputDeviceOzone::BeginPaint(const gfx::Rect& damage_rect) {
DCHECK(gfx::Rect(viewport_size_).Contains(damage_rect));
canvas_ = surface_ozone_->GetCanvas();
canvas_->clipRect(gfx::RectToSkRect(damage_rect), SkRegion::kReplace_Op);
canvas_->save();
return SoftwareOutputDevice::BeginPaint(damage_rect);
}
void SoftwareOutputDeviceOzone::EndPaint(cc::SoftwareFrameData* frame_data) {
SoftwareOutputDevice::EndPaint(frame_data);
canvas_->restore();
if (damage_rect_.IsEmpty())
return;
bool scheduled = surface_ozone_->PresentCanvas();
DCHECK(scheduled) << "Failed to present canvas";
}
}