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

Side by Side Diff: experimental/iOSSampleApp/SkSampleUIView.mm

Issue 2394843003: Fix iOS surface creation for SampleApp (Closed)
Patch Set: Created 4 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 | « no previous file | include/views/SkWindow.h » ('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 #import "SkSampleUIView.h" 8 #import "SkSampleUIView.h"
9 9
10 //#define SKGL_CONFIG kEAGLColorFormatRGB565 10 //#define SKGL_CONFIG kEAGLColorFormatRGB565
(...skipping 14 matching lines...) Expand all
25 #include "GrContext.h" 25 #include "GrContext.h"
26 #include "SkGpuDevice.h" 26 #include "SkGpuDevice.h"
27 #endif 27 #endif
28 28
29 class SkiOSDeviceManager : public SampleWindow::DeviceManager { 29 class SkiOSDeviceManager : public SampleWindow::DeviceManager {
30 public: 30 public:
31 SkiOSDeviceManager(GLint layerFBO) { 31 SkiOSDeviceManager(GLint layerFBO) {
32 #if SK_SUPPORT_GPU 32 #if SK_SUPPORT_GPU
33 fCurContext = NULL; 33 fCurContext = NULL;
34 fCurIntf = NULL; 34 fCurIntf = NULL;
35 fCurRenderTarget = NULL;
36 fMSAASampleCount = 0; 35 fMSAASampleCount = 0;
37 fLayerFBO = layerFBO; 36 fDeepColor = false;
37 fActualColorBits = 0;
38 #endif 38 #endif
39 fBackend = SkOSWindow::kNone_BackEndType; 39 fBackend = SkOSWindow::kNone_BackEndType;
40 } 40 }
41 41
42 virtual ~SkiOSDeviceManager() { 42 virtual ~SkiOSDeviceManager() {
43 #if SK_SUPPORT_GPU 43 #if SK_SUPPORT_GPU
44 SkSafeUnref(fCurContext); 44 SkSafeUnref(fCurContext);
45 SkSafeUnref(fCurIntf); 45 SkSafeUnref(fCurIntf);
46 SkSafeUnref(fCurRenderTarget);
47 #endif 46 #endif
48 } 47 }
49 48
50 void setUpBackend(SampleWindow* win, int msaaSampleCount, bool deepColor) ov erride { 49 void setUpBackend(SampleWindow* win, int msaaSampleCount, bool deepColor) ov erride {
51 SkASSERT(SkOSWindow::kNone_BackEndType == fBackend); 50 SkASSERT(SkOSWindow::kNone_BackEndType == fBackend);
52 51
53 fBackend = SkOSWindow::kNone_BackEndType; 52 fBackend = SkOSWindow::kNone_BackEndType;
54 53
55 #if SK_SUPPORT_GPU 54 #if SK_SUPPORT_GPU
56 switch (win->getDeviceType()) { 55 switch (win->getDeviceType()) {
57 case SampleWindow::kRaster_DeviceType: 56 case SampleWindow::kRaster_DeviceType:
58 break; 57 break;
59 // these guys use the native backend 58 // these guys use the native backend
60 case SampleWindow::kGPU_DeviceType: 59 case SampleWindow::kGPU_DeviceType:
61 fBackend = SkOSWindow::kNativeGL_BackEndType; 60 fBackend = SkOSWindow::kNativeGL_BackEndType;
62 break; 61 break;
63 default: 62 default:
64 SkASSERT(false); 63 SkASSERT(false);
65 break; 64 break;
66 } 65 }
67 SkOSWindow::AttachmentInfo info; 66 SkOSWindow::AttachmentInfo info;
68 bool result = win->attach(fBackend, msaaSampleCount, false, &info); 67 bool result = win->attach(fBackend, msaaSampleCount, false, &info);
69 if (!result) { 68 if (!result) {
70 SkDebugf("Failed to initialize GL"); 69 SkDebugf("Failed to initialize GL");
71 return; 70 return;
72 } 71 }
73 fMSAASampleCount = msaaSampleCount; 72 fMSAASampleCount = msaaSampleCount;
73 fDeepColor = deepColor;
74 // Assume that we have at least 24-bit output, for backends that don't s upply this data
75 fActualColorBits = SkTMax(info.fColorBits, 24);
74 76
75 SkASSERT(NULL == fCurIntf); 77 SkASSERT(NULL == fCurIntf);
76 switch (win->getDeviceType()) { 78 switch (win->getDeviceType()) {
77 case SampleWindow::kRaster_DeviceType: 79 case SampleWindow::kRaster_DeviceType:
78 fCurIntf = NULL; 80 fCurIntf = NULL;
79 break; 81 break;
80 case SampleWindow::kGPU_DeviceType: 82 case SampleWindow::kGPU_DeviceType:
81 fCurIntf = GrGLCreateNativeInterface(); 83 fCurIntf = GrGLCreateNativeInterface();
82 break; 84 break;
83 default: 85 default:
(...skipping 21 matching lines...) Expand all
105 } 107 }
106 108
107 void tearDownBackend(SampleWindow *win) override { 109 void tearDownBackend(SampleWindow *win) override {
108 #if SK_SUPPORT_GPU 110 #if SK_SUPPORT_GPU
109 SkSafeUnref(fCurContext); 111 SkSafeUnref(fCurContext);
110 fCurContext = NULL; 112 fCurContext = NULL;
111 113
112 SkSafeUnref(fCurIntf); 114 SkSafeUnref(fCurIntf);
113 fCurIntf = NULL; 115 fCurIntf = NULL;
114 116
115 SkSafeUnref(fCurRenderTarget); 117 fGpuSurface = nullptr;
116 fCurRenderTarget = NULL;
117 #endif 118 #endif
118 win->release(); 119 win->release();
119 fBackend = SampleWindow::kNone_BackEndType; 120 fBackend = SampleWindow::kNone_BackEndType;
120 } 121 }
121 122
122 SkSurface* createSurface(SampleWindow::DeviceType dType, SampleWindow* win) override{ 123 sk_sp<SkSurface> makeSurface(SampleWindow::DeviceType dType, SampleWindow* w in) override {
123 #if SK_SUPPORT_GPU 124 #if SK_SUPPORT_GPU
124 if (SampleWindow::IsGpuDeviceType(dType) && fCurContext) { 125 if (SampleWindow::IsGpuDeviceType(dType) && fCurContext) {
125 SkSurfaceProps props(win->getSurfaceProps()); 126 SkSurfaceProps props(win->getSurfaceProps());
126 return SkSurface::MakeRenderTargetDirect(fCurRenderTarget, 127 if (kRGBA_F16_SkColorType == win->info().colorType() || fActualColor Bits > 24) {
127 sk_ref_sp(win->info().color Space()), 128 // If we're rendering to F16, we need an off-screen surface - th e current render
128 &props).release(); 129 // target is most likely the wrong format.
130 //
131 // If we're using a deep (10-bit or higher) surface, we probably need an off-screen
132 // surface. 10-bit, in particular, has strange gamma behavior.
133 return SkSurface::MakeRenderTarget(fCurContext, SkBudgeted::kNo, win->info(),
134 fMSAASampleCount, &props);
135 } else {
136 return fGpuSurface;
137 }
129 } 138 }
130 #endif 139 #endif
131 return nullptr; 140 return nullptr;
132 } 141 }
133 142
134 virtual void publishCanvas(SampleWindow::DeviceType dType, 143 virtual void publishCanvas(SampleWindow::DeviceType dType,
135 SkCanvas* canvas, 144 SkCanvas* canvas,
136 SampleWindow* win) override { 145 SampleWindow* win) override {
137 #if SK_SUPPORT_GPU 146 #if SK_SUPPORT_GPU
138 if (NULL != fCurContext) { 147 if (NULL != fCurContext) {
139 fCurContext->flush(); 148 fCurContext->flush();
140 } 149 }
141 #endif 150 #endif
142 win->present(); 151 win->present();
143 } 152 }
144 153
145 void windowSizeChanged(SampleWindow* win) override { 154 void windowSizeChanged(SampleWindow* win) override {
146 #if SK_SUPPORT_GPU 155 #if SK_SUPPORT_GPU
147 if (NULL != fCurContext) { 156 if (fCurContext) {
148 SkOSWindow::AttachmentInfo info; 157 SampleWindow::AttachmentInfo attachmentInfo;
149 158 win->attach(fBackend, fMSAASampleCount, fDeepColor, &attachmentInfo) ;
150 win->attach(fBackend, fMSAASampleCount, false, &info); 159 fActualColorBits = SkTMax(attachmentInfo.fColorBits, 24);
151 160 fGpuSurface = win->makeGpuBackedSurface(attachmentInfo, fCurIntf, fC urContext);
152 glBindFramebuffer(GL_FRAMEBUFFER, fLayerFBO);
153 GrBackendRenderTargetDesc desc;
154 desc.fWidth = SkScalarRoundToInt(win->width());
155 desc.fHeight = SkScalarRoundToInt(win->height());
156 desc.fConfig = kSkia8888_GrPixelConfig;
157 desc.fRenderTargetHandle = fLayerFBO;
158 desc.fSampleCnt = info.fSampleCount;
159 desc.fStencilBits = info.fStencilBits;
160
161 SkSafeUnref(fCurRenderTarget);
162 fCurRenderTarget = fCurContext->textureProvider()->wrapBackendRender Target(desc);
163 } 161 }
164 #endif 162 #endif
165 } 163 }
166 164
167 GrContext* getGrContext() override { 165 GrContext* getGrContext() override {
168 #if SK_SUPPORT_GPU 166 #if SK_SUPPORT_GPU
169 return fCurContext; 167 return fCurContext;
170 #else 168 #else
171 return NULL; 169 return NULL;
172 #endif 170 #endif
173 } 171 }
174
175 GrRenderTarget* getGrRenderTarget() override {
176 #if SK_SUPPORT_GPU
177 return fCurRenderTarget;
178 #else
179 return NULL;
180 #endif
181 }
182 172
173 int numColorSamples() const override {
174 #if SK_SUPPORT_GPU
175 return fMSAASampleCount;
176 #else
177 return 0;
178 #endif
179 }
180
183 int getColorBits() override { 181 int getColorBits() override {
182 #if SK_SUPPORT_GPU
183 return fActualColorBits;
184 #else
184 return 24; 185 return 24;
186 #endif
185 } 187 }
186 188
187 bool isUsingGL() const { return SkOSWindow::kNone_BackEndType != fBackend; } 189 bool isUsingGL() const { return SkOSWindow::kNone_BackEndType != fBackend; }
188 190
189 private: 191 private:
190 192
191 #if SK_SUPPORT_GPU 193 #if SK_SUPPORT_GPU
192 GrContext* fCurContext; 194 GrContext* fCurContext;
193 const GrGLInterface* fCurIntf; 195 const GrGLInterface* fCurIntf;
194 GrRenderTarget* fCurRenderTarget; 196 sk_sp<SkSurface> fGpuSurface;
195 int fMSAASampleCount; 197 int fMSAASampleCount;
196 GLint fLayerFBO; 198 bool fDeepColor;
199 int fActualColorBits;
197 #endif 200 #endif
198 201
199 SkOSWindow::SkBackEndTypes fBackend; 202 SkOSWindow::SkBackEndTypes fBackend;
200 203
201 typedef SampleWindow::DeviceManager INHERITED; 204 typedef SampleWindow::DeviceManager INHERITED;
202 }; 205 };
203 206
204 //////////////////////////////////////////////////////////////////////////////// 207 ////////////////////////////////////////////////////////////////////////////////
205 @implementation SkSampleUIView 208 @implementation SkSampleUIView
206 209
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 glGetIntegerv(GL_SCISSOR_TEST, &scissorEnable); 415 glGetIntegerv(GL_SCISSOR_TEST, &scissorEnable);
413 glDisable(GL_SCISSOR_TEST); 416 glDisable(GL_SCISSOR_TEST);
414 glClearColor(0,0,0,0); 417 glClearColor(0,0,0,0);
415 glClear(GL_COLOR_BUFFER_BIT); 418 glClear(GL_COLOR_BUFFER_BIT);
416 if (scissorEnable) { 419 if (scissorEnable) {
417 glEnable(GL_SCISSOR_TEST); 420 glEnable(GL_SCISSOR_TEST);
418 } 421 }
419 glViewport(0, 0, fGL.fWidth, fGL.fHeight); 422 glViewport(0, 0, fGL.fWidth, fGL.fHeight);
420 423
421 424
422 SkAutoTUnref<SkSurface> surface(fWind->createSurface()); 425 sk_sp<SkSurface> surface(fWind->makeSurface());
423 SkCanvas* canvas = surface->getCanvas(); 426 SkCanvas* canvas = surface->getCanvas();
424 427
425 // if we're not "retained", then we have to always redraw everything. 428 // if we're not "retained", then we have to always redraw everything.
426 // This call forces us to ignore the fDirtyRgn, and draw everywhere. 429 // This call forces us to ignore the fDirtyRgn, and draw everywhere.
427 // If we are "retained", we can skip this call (as the raster case does) 430 // If we are "retained", we can skip this call (as the raster case does)
428 fWind->forceInvalAll(); 431 fWind->forceInvalAll();
429 432
430 [self drawWithCanvas:canvas]; 433 [self drawWithCanvas:canvas];
431 434
432 // This application only creates a single color renderbuffer which is alread y bound at this point. 435 // This application only creates a single color renderbuffer which is alread y bound at this point.
433 // This call is redundant, but needed if dealing with multiple renderbuffers . 436 // This call is redundant, but needed if dealing with multiple renderbuffers .
434 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer); 437 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer);
435 [fGL.fContext presentRenderbuffer:GL_RENDERBUFFER]; 438 [fGL.fContext presentRenderbuffer:GL_RENDERBUFFER];
436 } 439 }
437 440
438 - (void)drawInRaster { 441 - (void)drawInRaster {
439 SkAutoTUnref<SkSurface> surface(fWind->createSurface()); 442 sk_sp<SkSurface> surface(fWind->makeSurface());
440 SkCanvas* canvas = surface->getCanvas(); 443 SkCanvas* canvas = surface->getCanvas();
441 [self drawWithCanvas:canvas]; 444 [self drawWithCanvas:canvas];
442 CGImageRef cgimage = SkCreateCGImageRef(fWind->getBitmap()); 445 CGImageRef cgimage = SkCreateCGImageRef(fWind->getBitmap());
443 fRasterLayer.contents = (id)cgimage; 446 fRasterLayer.contents = (id)cgimage;
444 CGImageRelease(cgimage); 447 CGImageRelease(cgimage);
445 } 448 }
446 449
447 - (void)forceRedraw { 450 - (void)forceRedraw {
448 if (fDevManager->isUsingGL()) 451 if (fDevManager->isUsingGL())
449 [self drawInGL]; 452 [self drawInGL];
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer); 490 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer);
488 glGetRenderbufferParameteriv(GL_RENDERBUFFER, 491 glGetRenderbufferParameteriv(GL_RENDERBUFFER,
489 GL_RENDERBUFFER_STENCIL_SIZE, 492 GL_RENDERBUFFER_STENCIL_SIZE,
490 &info->fStencilBits); 493 &info->fStencilBits);
491 glGetRenderbufferParameteriv(GL_RENDERBUFFER, 494 glGetRenderbufferParameteriv(GL_RENDERBUFFER,
492 GL_RENDERBUFFER_SAMPLES_APPLE, 495 GL_RENDERBUFFER_SAMPLES_APPLE,
493 &info->fSampleCount); 496 &info->fSampleCount);
494 } 497 }
495 498
496 @end 499 @end
OLDNEW
« no previous file with comments | « no previous file | include/views/SkWindow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698