Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1248)

Side by Side Diff: ui/ozone/demo/software_renderer.cc

Issue 1285183008: Ozone integration. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add missing license header Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/ozone/demo/software_renderer.h ('k') | ui/ozone/demo/surfaceless_gl_renderer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ui/ozone/demo/software_renderer.h"
6
7 #include "third_party/skia/include/core/SkCanvas.h"
8 #include "third_party/skia/include/core/SkSurface.h"
9 #include "ui/gfx/vsync_provider.h"
10 #include "ui/ozone/public/ozone_platform.h"
11 #include "ui/ozone/public/surface_factory_ozone.h"
12 #include "ui/ozone/public/surface_ozone_canvas.h"
13
14 namespace ui {
15 namespace {
16
17 const int kFrameDelayMilliseconds = 16;
18
19 } // namespace
20
21 SoftwareRenderer::SoftwareRenderer(gfx::AcceleratedWidget widget,
22 const gfx::Size& size)
23 : RendererBase(widget, size),
24 vsync_period_(base::TimeDelta::FromMilliseconds(kFrameDelayMilliseconds)),
25 weak_ptr_factory_(this) {
26 }
27
28 SoftwareRenderer::~SoftwareRenderer() {
29 }
30
31 bool SoftwareRenderer::Initialize() {
32 software_surface_ = ui::OzonePlatform::GetInstance()
33 ->GetSurfaceFactoryOzone()
34 ->CreateCanvasForWidget(widget_);
35 if (!software_surface_) {
36 LOG(ERROR) << "Failed to create software surface";
37 return false;
38 }
39
40 software_surface_->ResizeCanvas(size_);
41 vsync_provider_ = software_surface_->CreateVSyncProvider();
42 RenderFrame();
43 return true;
44 }
45
46 void SoftwareRenderer::RenderFrame() {
47 float fraction = NextFraction();
48
49 skia::RefPtr<SkSurface> surface = software_surface_->GetSurface();
50
51 SkColor color =
52 SkColorSetARGB(0xff, 0, 0xff * fraction, 0xff * (1 - fraction));
53
54 surface->getCanvas()->clear(color);
55
56 software_surface_->PresentCanvas(gfx::Rect(size_));
57
58 if (vsync_provider_) {
59 vsync_provider_->GetVSyncParameters(
60 base::Bind(&SoftwareRenderer::UpdateVSyncParameters,
61 weak_ptr_factory_.GetWeakPtr()));
62 }
63
64 timer_.Start(FROM_HERE, vsync_period_, this, &SoftwareRenderer::RenderFrame);
65 }
66
67 void SoftwareRenderer::UpdateVSyncParameters(const base::TimeTicks timebase,
68 const base::TimeDelta interval) {
69 vsync_period_ = interval;
70 }
71
72 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/demo/software_renderer.h ('k') | ui/ozone/demo/surfaceless_gl_renderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698