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

Side by Side Diff: tools/VisualBench.cpp

Issue 1151333004: CL to add setFullscreen and setVsync to SkWindow (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 5 years, 6 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 | « tools/VisualBench.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 *
7 */
8
9 #include "VisualBench.h"
10
11 #include "SkApplication.h"
12 #include "SkCanvas.h"
13 #include "SkCommandLineFlags.h"
14 #include "SkCommonFlags.h"
15 #include "SkForceLinking.h"
16 #include "SkGraphics.h"
17 #include "SkGr.h"
18 #include "SkImageDecoder.h"
19 #include "SkOSFile.h"
20 #include "SkStream.h"
21 #include "Timer.h"
22 #include "gl/GrGLInterface.h"
23
24 __SK_FORCE_IMAGE_DECODER_LINKING;
25
26 VisualBench::VisualBench(void* hwnd, int argc, char** argv)
27 : INHERITED(hwnd)
28 , fCurrentLoops(1)
29 , fCurrentPicture(0)
30 , fCurrentFrame(0) {
31 SkCommandLineFlags::Parse(argc, argv);
32
33 SkTArray<SkString> skps;
34 for (int i = 0; i < FLAGS_skps.count(); i++) {
35 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
36 skps.push_back() = FLAGS_skps[i];
37 } else {
38 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
39 SkString path;
40 while (it.next(&path)) {
41 skps.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str());
42 }
43 }
44 }
45
46 this->setTitle();
47 this->setupBackend();
48
49 // Load picture for playback
50 for (int i = 0; i < skps.count(); i++) {
51 SkFILEStream stream(skps[i].c_str());
52 if (stream.isValid()) {
53 fPictures.push_back(SkPicture::CreateFromStream(&stream));
54 } else {
55 SkDebugf("couldn't load picture at \"path\"\n", skps[i].c_str());
56 }
57 }
58 }
59
60 VisualBench::~VisualBench() {
61 for (int i = 0; i < fPictures.count(); i++) {
62 fPictures[i]->~SkPicture();
63 }
64 INHERITED::detach();
65 }
66
67 void VisualBench::setTitle() {
68 SkString title("VisualBench");
69 INHERITED::setTitle(title.c_str());
70 }
71
72 SkSurface* VisualBench::createSurface() {
73 SkSurfaceProps props(INHERITED::getSurfaceProps());
74 return SkSurface::NewRenderTargetDirect(fRenderTarget, &props);
75 }
76
77 bool VisualBench::setupBackend() {
78 this->setColorType(kRGBA_8888_SkColorType);
79 this->setVisibleP(true);
80 this->setClipToBounds(false);
81
82 if (!this->attach(kNativeGL_BackEndType, 0 /*msaa*/, &fAttachmentInfo)) {
83 SkDebugf("Not possible to create backend.\n");
84 INHERITED::detach();
85 return false;
86 }
87
88 this->setFullscreen(true);
89 this->setVsync(false);
90
91 fInterface.reset(GrGLCreateNativeInterface());
92 SkASSERT(fInterface);
93
94 // setup contexts
95 fContext.reset(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInter face.get()));
96 SkASSERT(fContext);
97
98 // setup rendertargets
99 this->setupRenderTarget();
100 return true;
101 }
102
103 void VisualBench::setupRenderTarget() {
104 fRenderTarget.reset(this->renderTarget(fAttachmentInfo, fInterface, fContext ));
105 }
106
107 void VisualBench::draw(SkCanvas* canvas) {
108 fCurrentFrame++;
109 WallTimer timer;
110 timer.start();
111 for (int i = 0; i < fCurrentLoops; i++) {
112 canvas->drawPicture(fPictures[fCurrentPicture]);
113 }
114 // in case we have queued drawing calls
115 fContext->flush();
116 INHERITED::present();
117 timer.end();
118
119 SkDebugf("%s\n", HumanizeMs(timer.fWall).c_str());
120
121 // Invalidate the window to force a redraw. Poor man's animation mechanism.
122 this->inval(NULL);
123 }
124
125 void VisualBench::onSizeChange() {
126 this->setupRenderTarget();
127 }
128
129 bool VisualBench::onHandleChar(SkUnichar unichar) {
130 return true;
131 }
132
133 // Externally declared entry points
134 void application_init() {
135 SkGraphics::Init();
136 SkEvent::Init();
137 }
138
139 void application_term() {
140 SkEvent::Term();
141 SkGraphics::Term();
142 }
143
144 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
145 return new VisualBench(hwnd, argc, argv);
146 }
147
OLDNEW
« no previous file with comments | « tools/VisualBench.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698