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

Side by Side Diff: tools/VisualBench/VisualBench.cpp

Issue 1416063002: Force VisualBench to reset GLContext on GrContext reset (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 5 years, 2 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/VisualBench.h ('k') | tools/VisualBench/VisualStreamTimingModule.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 * 6 *
7 */ 7 */
8 8
9 #include "VisualBench.h" 9 #include "VisualBench.h"
10 10
(...skipping 22 matching lines...) Expand all
33 fModule.reset(new VisualLightweightBenchModule(this)); 33 fModule.reset(new VisualLightweightBenchModule(this));
34 if (FLAGS_interactive) { 34 if (FLAGS_interactive) {
35 fModule.reset(new VisualInteractiveModule(this)); 35 fModule.reset(new VisualInteractiveModule(this));
36 } 36 }
37 37
38 this->setTitle(); 38 this->setTitle();
39 this->setupBackend(); 39 this->setupBackend();
40 } 40 }
41 41
42 VisualBench::~VisualBench() { 42 VisualBench::~VisualBench() {
43 INHERITED::detach(); 43 this->tearDownContext();
44 } 44 }
45 45
46 void VisualBench::setTitle() { 46 void VisualBench::setTitle() {
47 SkString title("VisualBench"); 47 SkString title("VisualBench");
48 INHERITED::setTitle(title.c_str()); 48 INHERITED::setTitle(title.c_str());
49 } 49 }
50 50
51 SkSurface* VisualBench::createSurface() { 51 SkSurface* VisualBench::createSurface() {
52 if (!fSurface) { 52 if (!fSurface) {
53 SkSurfaceProps props(INHERITED::getSurfaceProps()); 53 SkSurfaceProps props(INHERITED::getSurfaceProps());
54 fSurface.reset(SkSurface::NewRenderTargetDirect(fRenderTarget, &props)); 54 fSurface.reset(SkSurface::NewRenderTargetDirect(fRenderTarget, &props));
55 } 55 }
56 56
57 // The caller will wrap the SkSurface in an SkAutoTUnref 57 // The caller will wrap the SkSurface in an SkAutoTUnref
58 return SkRef(fSurface.get()); 58 return SkRef(fSurface.get());
59 } 59 }
60 60
61 bool VisualBench::setupBackend() { 61 bool VisualBench::setupBackend() {
62 this->setColorType(kRGBA_8888_SkColorType); 62 this->setColorType(kRGBA_8888_SkColorType);
63 this->setVisibleP(true); 63 this->setVisibleP(true);
64 this->setClipToBounds(false); 64 this->setClipToBounds(false);
65 65
66 if (FLAGS_fullscreen) { 66 if (FLAGS_fullscreen) {
67 if (!this->makeFullscreen()) { 67 if (!this->makeFullscreen()) {
68 SkDebugf("Could not go fullscreen!"); 68 SkDebugf("Could not go fullscreen!");
69 } 69 }
70 } 70 }
71 if (!this->attach(kNativeGL_BackEndType, FLAGS_msaa, &fAttachmentInfo)) {
72 SkDebugf("Not possible to create backend.\n");
73 INHERITED::detach();
74 return false;
75 }
76 71
77 this->setVsync(false);
78 this->resetContext(); 72 this->resetContext();
79 return true; 73 return true;
80 } 74 }
81 75
82 void VisualBench::resetContext() { 76 void VisualBench::resetContext() {
77 this->tearDownContext();
78 this->setupContext();
79 }
80
81 void VisualBench::setupContext() {
82 if (!this->attach(kNativeGL_BackEndType, FLAGS_msaa, &fAttachmentInfo)) {
83 SkDebugf("Not possible to create backend.\n");
84 INHERITED::detach();
85 SkFAIL("Could not create backend\n");
86 }
87
88 this->setVsync(false);
89
83 fSurface.reset(nullptr); 90 fSurface.reset(nullptr);
84 91
85 fInterface.reset(GrGLCreateNativeInterface()); 92 fInterface.reset(GrGLCreateNativeInterface());
86 93
87 // TODO use the GLContext creation factories and also set this all up in con figs 94 // TODO use the GLContext creation factories and also set this all up in con figs
88 if (!FLAGS_nvpr) { 95 if (!FLAGS_nvpr) {
89 fInterface.reset(GrGLInterfaceRemoveNVPR(fInterface)); 96 fInterface.reset(GrGLInterfaceRemoveNVPR(fInterface));
90 } 97 }
91 SkASSERT(fInterface); 98 SkASSERT(fInterface);
92 99
93 // setup contexts 100 // setup contexts
94 fContext.reset(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInter face.get())); 101 fContext.reset(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInter face.get()));
95 SkASSERT(fContext); 102 SkASSERT(fContext);
96 103
97 // setup rendertargets 104 // setup rendertargets
98 this->setupRenderTarget(); 105 this->setupRenderTarget();
99 } 106 }
100 107
108 void VisualBench::tearDownContext() {
109 if (fContext) {
110 // We abandon the context in case SkWindow has kept a ref to the surface
111 fContext->abandonContext();
bsalomon 2015/10/21 14:52:05 It'd be really nice to refactor SkOSWindow a littl
112 fContext.reset();
113 fSurface.reset();
114 fInterface.reset();
115 this->detach();
116 }
117 }
118
101 void VisualBench::setupRenderTarget() { 119 void VisualBench::setupRenderTarget() {
102 if (fContext) { 120 if (fContext) {
103 fRenderTarget.reset(this->renderTarget(fAttachmentInfo, fInterface, fCon text)); 121 fRenderTarget.reset(this->renderTarget(fAttachmentInfo, fInterface, fCon text));
104 } 122 }
105 } 123 }
106 124
107 void VisualBench::draw(SkCanvas* canvas) { 125 void VisualBench::draw(SkCanvas* canvas) {
108 fModule->draw(canvas); 126 fModule->draw(canvas);
109 127
110 // Invalidate the window to force a redraw. Poor man's animation mechanism. 128 // Invalidate the window to force a redraw. Poor man's animation mechanism.
(...skipping 30 matching lines...) Expand all
141 } 159 }
142 160
143 void application_term() { 161 void application_term() {
144 SkEvent::Term(); 162 SkEvent::Term();
145 } 163 }
146 164
147 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { 165 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
148 return new VisualBench(hwnd, argc, argv); 166 return new VisualBench(hwnd, argc, argv);
149 } 167 }
150 168
OLDNEW
« no previous file with comments | « tools/VisualBench/VisualBench.h ('k') | tools/VisualBench/VisualStreamTimingModule.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698