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

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

Powered by Google App Engine
This is Rietveld 408576698