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

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, 7 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
« tools/VisualBench.h ('K') | « 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"
robertphillips 2015/05/26 21:21:41 Do we need GradientShader.h ?
16 #include "SkGradientShader.h"
17 #include "SkGraphics.h"
18 #include "SkGr.h"
19 #include "SkImageDecoder.h"
20 #include "SkOSFile.h"
21 #include "SkStream.h"
22 #include "Timer.h"
23 #include "gl/GrGLInterface.h"
24
25 __SK_FORCE_IMAGE_DECODER_LINKING;
26
robertphillips 2015/05/26 21:21:41 static on this guy?
27 void application_init() {
28 SkGraphics::Init();
29 SkEvent::Init();
30 }
31
robertphillips 2015/05/26 21:21:41 this guy too ?
32 void application_term() {
33 SkEvent::Term();
34 SkGraphics::Term();
35 }
36
37 VisualBench::VisualBench(void* hwnd, int argc, char** argv)
38 : INHERITED(hwnd)
39 , fCurrentLoops(1)
40 , fCurrentPicture(0)
41 , fCurrentFrame(0) {
42 SkCommandLineFlags::Parse(argc, argv);
43
44 SkTArray<SkString> skps;
45 for (int i = 0; i < FLAGS_skps.count(); i++) {
46 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
47 skps.push_back() = FLAGS_skps[i];
48 } else {
49 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
50 SkString path;
51 while (it.next(&path)) {
52 skps.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str());
53 }
54 }
55 }
56
57 this->setTitle();
58 this->setUpBackend();
59
60 // Load picture for playback
61 for (int i = 0; i < skps.count(); i++) {
62 SkFILEStream stream(skps[i].c_str());
63 if (stream.isValid()) {
64 fPictures.push_back(SkPicture::CreateFromStream(&stream));
65 } else {
66 SkDebugf("couldn't load picture at \"path\"\n", skps[i].c_str());
67 }
68 }
69 }
70
71 VisualBench::~VisualBench() {
72 for (int i = 0; i < fPictures.count(); i++) {
73 fPictures[i]->~SkPicture();
74 }
75 INHERITED::detach();
76 }
77
78 void VisualBench::setTitle() {
79 SkString title("VisualBench");
80 INHERITED::setTitle(title.c_str());
81 }
82
83 SkSurface* VisualBench::createSurface() {
84 SkSurfaceProps props(INHERITED::getSurfaceProps());
85 return SkSurface::NewRenderTargetDirect(fRenderTarget, &props);
86 }
87
88 bool VisualBench::setUpBackend() {
89 this->setColorType(kRGBA_8888_SkColorType);
90 this->setVisibleP(true);
91 this->setClipToBounds(false);
92
93 if (!this->attach(kNativeGL_BackEndType, 0 /*msaa*/, &fAttachmentInfo)) {
94 SkDebugf("Not possible to create backend.\n");
95 INHERITED::detach();
96 return false;
97 }
98
99 this->setFullscreen(true);
100 this->setVsync(false);
101
102 fInterface.reset(GrGLCreateNativeInterface());
103 SkASSERT(fInterface);
104
105 // setup contexts
106 fContext.reset(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInter face.get()));
107 SkASSERT(fContext);
108
109 // setup rendertargets
110 this->setUpRenderTarget();
111 return true;
112 }
113
114 void VisualBench::setUpRenderTarget() {
115 fRenderTarget.reset(this->renderTarget(fAttachmentInfo, fInterface, fContext ));
116 }
117
118 void VisualBench::draw(SkCanvas* canvas) {
119 fCurrentFrame++;
120 WallTimer timer;
121 timer.start();
122 for (int i = 0; i < fCurrentLoops; i++) {
123 canvas->drawPicture(fPictures[0]);
124 }
125 // in case we have queued drawing calls
126 fContext->flush();
127 INHERITED::present();
128 timer.end();
129
130 SkDebugf("%s\n", HumanizeMs(timer.fWall).c_str());
131
132 // Invalidate the window to force a redraw. Poor man's animation mechanism.
133 this->inval(NULL);
134 }
135
136 void VisualBench::onSizeChange() {
137 this->setUpRenderTarget();
138 }
139
140 bool VisualBench::onHandleChar(SkUnichar unichar) {
141 return true;
142 }
143
robertphillips 2015/05/26 21:21:41 static ?
joshualitt 2015/05/27 14:09:34 this is actually called from another file
144 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
145 return new VisualBench(hwnd, argc, argv);
146 }
147
OLDNEW
« tools/VisualBench.h ('K') | « tools/VisualBench.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698