1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/ozone/demo/software_renderer.h"
7 #include "third_party/skia/include/core/SkCanvas.h"
8 #include "third_party/skia/include/core/SkSurface.h"
9 #include "ui/ozone/public/surface_factory_ozone.h"
10 #include "ui/ozone/public/surface_ozone_canvas.h"
14 SoftwareRenderer::SoftwareRenderer(gfx::AcceleratedWidget widget
,
15 const gfx::Size
& size
)
16 : RendererBase(widget
, size
) {
19 SoftwareRenderer::~SoftwareRenderer() {
22 bool SoftwareRenderer::Initialize() {
24 ui::SurfaceFactoryOzone::GetInstance()->CreateCanvasForWidget(widget_
);
25 if (!software_surface_
) {
26 LOG(ERROR
) << "Failed to create software surface";
30 software_surface_
->ResizeCanvas(size_
);
34 void SoftwareRenderer::RenderFrame() {
35 float fraction
= NextFraction();
37 skia::RefPtr
<SkSurface
> surface
= software_surface_
->GetSurface();
40 SkColorSetARGB(0xff, 0, 0xff * fraction
, 0xff * (1 - fraction
));
42 surface
->getCanvas()->clear(color
);
44 software_surface_
->PresentCanvas(gfx::Rect(size_
));