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

Side by Side Diff: samplecode/SampleApp.cpp

Issue 2178353005: Remove use of MakeRenderTargetDirect from view system (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix Mac Created 4 years, 4 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 | « samplecode/SampleApp.h ('k') | src/views/SkWindow.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 2011 Google Inc. 2 * Copyright 2011 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 #include "SampleApp.h" 8 #include "SampleApp.h"
9 9
10 #include "OverView.h" 10 #include "OverView.h"
(...skipping 18 matching lines...) Expand all
29 #include "SkTemplates.h" 29 #include "SkTemplates.h"
30 #include "SkTSort.h" 30 #include "SkTSort.h"
31 #include "SkTime.h" 31 #include "SkTime.h"
32 #include "SkTypeface.h" 32 #include "SkTypeface.h"
33 #include "SkWindow.h" 33 #include "SkWindow.h"
34 #include "sk_tool_utils.h" 34 #include "sk_tool_utils.h"
35 35
36 #if SK_SUPPORT_GPU 36 #if SK_SUPPORT_GPU
37 # include "gl/GrGLInterface.h" 37 # include "gl/GrGLInterface.h"
38 # include "gl/GrGLUtil.h" 38 # include "gl/GrGLUtil.h"
39 # include "GrDrawContext.h"
39 # include "GrRenderTarget.h" 40 # include "GrRenderTarget.h"
40 # include "GrContext.h" 41 # include "GrContext.h"
41 # include "SkGr.h" 42 # include "SkGr.h"
42 # if SK_ANGLE 43 # if SK_ANGLE
43 # include "gl/angle/GLTestContext_angle.h" 44 # include "gl/angle/GLTestContext_angle.h"
44 # endif 45 # endif
45 #else 46 #else
46 class GrContext; 47 class GrContext;
47 #endif 48 #endif
48 49
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 181
181 /////////////////////////////////////////////////////////////////////////////// 182 ///////////////////////////////////////////////////////////////////////////////
182 183
183 class SampleWindow::DefaultDeviceManager : public SampleWindow::DeviceManager { 184 class SampleWindow::DefaultDeviceManager : public SampleWindow::DeviceManager {
184 public: 185 public:
185 186
186 DefaultDeviceManager() { 187 DefaultDeviceManager() {
187 #if SK_SUPPORT_GPU 188 #if SK_SUPPORT_GPU
188 fCurContext = nullptr; 189 fCurContext = nullptr;
189 fCurIntf = nullptr; 190 fCurIntf = nullptr;
190 fCurRenderTarget = nullptr;
191 fMSAASampleCount = 0; 191 fMSAASampleCount = 0;
192 fDeepColor = false; 192 fDeepColor = false;
193 fActualColorBits = 0; 193 fActualColorBits = 0;
194 #endif 194 #endif
195 fBackend = kNone_BackEndType; 195 fBackend = kNone_BackEndType;
196 } 196 }
197 197
198 virtual ~DefaultDeviceManager() { 198 virtual ~DefaultDeviceManager() {
199 #if SK_SUPPORT_GPU 199 #if SK_SUPPORT_GPU
200 SkSafeUnref(fCurContext); 200 SkSafeUnref(fCurContext);
201 SkSafeUnref(fCurIntf); 201 SkSafeUnref(fCurIntf);
202 SkSafeUnref(fCurRenderTarget);
203 #endif 202 #endif
204 } 203 }
205 204
206 void setUpBackend(SampleWindow* win, int msaaSampleCount, bool deepColor) ov erride { 205 void setUpBackend(SampleWindow* win, int msaaSampleCount, bool deepColor) ov erride {
207 SkASSERT(kNone_BackEndType == fBackend); 206 SkASSERT(kNone_BackEndType == fBackend);
208 207
209 fBackend = kNone_BackEndType; 208 fBackend = kNone_BackEndType;
210 209
211 #if SK_SUPPORT_GPU 210 #if SK_SUPPORT_GPU
212 switch (win->getDeviceType()) { 211 switch (win->getDeviceType()) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 // We need some context and interface to see results 264 // We need some context and interface to see results
266 SkSafeUnref(fCurContext); 265 SkSafeUnref(fCurContext);
267 SkSafeUnref(fCurIntf); 266 SkSafeUnref(fCurIntf);
268 fCurContext = nullptr; 267 fCurContext = nullptr;
269 fCurIntf = nullptr; 268 fCurIntf = nullptr;
270 SkDebugf("Failed to setup 3D"); 269 SkDebugf("Failed to setup 3D");
271 270
272 win->release(); 271 win->release();
273 } 272 }
274 #endif // SK_SUPPORT_GPU 273 #endif // SK_SUPPORT_GPU
275 // call windowSizeChanged to create the render target 274 // call windowSizeChanged to create the gpu-backed Surface
276 this->windowSizeChanged(win); 275 this->windowSizeChanged(win);
277 } 276 }
278 277
279 void tearDownBackend(SampleWindow *win) override { 278 void tearDownBackend(SampleWindow *win) override {
280 #if SK_SUPPORT_GPU 279 #if SK_SUPPORT_GPU
281 if (fCurContext) { 280 if (fCurContext) {
282 // in case we have outstanding refs to this guy (lua?) 281 // in case we have outstanding refs to this guy (lua?)
283 fCurContext->abandonContext(); 282 fCurContext->abandonContext();
284 fCurContext->unref(); 283 fCurContext->unref();
285 fCurContext = nullptr; 284 fCurContext = nullptr;
286 } 285 }
287 286
288 SkSafeUnref(fCurIntf); 287 SkSafeUnref(fCurIntf);
289 fCurIntf = nullptr; 288 fCurIntf = nullptr;
290 289
291 SkSafeUnref(fCurRenderTarget); 290 fGpuSurface = nullptr;
292 fCurRenderTarget = nullptr;
293 #endif 291 #endif
294 win->release(); 292 win->release();
295 fBackend = kNone_BackEndType; 293 fBackend = kNone_BackEndType;
296 } 294 }
297 295
298 SkSurface* createSurface(SampleWindow::DeviceType dType, SampleWindow* win) override { 296 sk_sp<SkSurface> makeSurface(SampleWindow::DeviceType dType, SampleWindow* w in) override {
299 #if SK_SUPPORT_GPU 297 #if SK_SUPPORT_GPU
300 if (IsGpuDeviceType(dType) && fCurContext) { 298 if (IsGpuDeviceType(dType) && fCurContext) {
301 SkSurfaceProps props(win->getSurfaceProps()); 299 SkSurfaceProps props(win->getSurfaceProps());
302 if (kRGBA_F16_SkColorType == win->info().colorType() || fActualColor Bits > 24) { 300 if (kRGBA_F16_SkColorType == win->info().colorType() || fActualColor Bits > 24) {
303 // If we're rendering to F16, we need an off-screen surface - th e current render 301 // If we're rendering to F16, we need an off-screen surface - th e current render
304 // target is most likely the wrong format. 302 // target is most likely the wrong format.
305 // 303 //
306 // If we're using a deep (10-bit or higher) surface, we probably need an off-screen 304 // If we're using a deep (10-bit or higher) surface, we probably need an off-screen
307 // surface. 10-bit, in particular, has strange gamma behavior. 305 // surface. 10-bit, in particular, has strange gamma behavior.
308 return SkSurface::MakeRenderTarget(fCurContext, SkBudgeted::kNo, win->info(), 306 return SkSurface::MakeRenderTarget(fCurContext, SkBudgeted::kNo, win->info(),
309 fMSAASampleCount, &props).rel ease(); 307 fMSAASampleCount, &props);
310 } else { 308 } else {
311 return SkSurface::MakeRenderTargetDirect(fCurRenderTarget, 309 return fGpuSurface;
312 sk_ref_sp(win->info().c olorSpace()),
313 &props).release();
314 } 310 }
315 } 311 }
316 #endif 312 #endif
317 return nullptr; 313 return nullptr;
318 } 314 }
319 315
320 void publishCanvas(SampleWindow::DeviceType dType, 316 void publishCanvas(SampleWindow::DeviceType dType,
321 SkCanvas* canvas, SampleWindow* win) override { 317 SkCanvas* canvas, SampleWindow* win) override {
322 #if SK_SUPPORT_GPU 318 #if SK_SUPPORT_GPU
323 if (fCurContext) { 319 if (fCurContext) {
324 // in case we have queued drawing calls 320 // in case we have queued drawing calls
325 fCurContext->flush(); 321 fCurContext->flush();
326 } 322 }
327 323
328 if (!IsGpuDeviceType(dType) || 324 if (!IsGpuDeviceType(dType) ||
329 kRGBA_F16_SkColorType == win->info().colorType() || 325 kRGBA_F16_SkColorType == win->info().colorType() ||
330 fActualColorBits > 24) { 326 fActualColorBits > 24) {
331 // We made/have an off-screen surface. Get the contents as an SkImag e: 327 // We made/have an off-screen surface. Get the contents as an SkImag e:
332 SkBitmap bm; 328 SkBitmap bm;
333 bm.allocPixels(win->info()); 329 bm.allocPixels(win->info());
334 canvas->readPixels(&bm, 0, 0); 330 canvas->readPixels(&bm, 0, 0);
335 SkPixmap pm; 331 SkPixmap pm;
336 bm.peekPixels(&pm); 332 bm.peekPixels(&pm);
337 sk_sp<SkImage> image(SkImage::MakeTextureFromPixmap(fCurContext, pm, 333 sk_sp<SkImage> image(SkImage::MakeTextureFromPixmap(fCurContext, pm,
338 SkBudgeted::kNo) ); 334 SkBudgeted::kNo) );
339 GrTexture* texture = as_IB(image)->peekTexture(); 335
336 SkCanvas* canvas = fGpuSurface->getCanvas();
337
338 // Temporary code until applyGamma is replaced
339 GrDrawContext* dc = canvas->internal_private_accessTopLayerDrawConte xt();
340 GrRenderTarget* rt = dc->accessRenderTarget();
341 GrTexture* texture = image->getTexture();
340 SkASSERT(texture); 342 SkASSERT(texture);
341 343
342 // With ten-bit output, we need to manually apply the gamma of the o utput device 344 // With ten-bit output, we need to manually apply the gamma of the o utput device
343 // (unless we're in non-gamma correct mode, in which case our data i s already 345 // (unless we're in non-gamma correct mode, in which case our data i s already
344 // fake-sRGB, like we're expected to put in the 10-bit buffer): 346 // fake-sRGB, like we're expected to put in the 10-bit buffer):
345 bool doGamma = (fActualColorBits == 30) && SkImageInfoIsGammaCorrect (win->info()); 347 bool doGamma = (fActualColorBits == 30) && SkImageInfoIsGammaCorrect (win->info());
346 fCurContext->applyGamma(fCurRenderTarget, texture, doGamma ? 1.0f / 2.2f : 1.0f); 348 fCurContext->applyGamma(rt, texture, doGamma ? 1.0f / 2.2f : 1.0f);
347 } 349 }
348 #endif 350 #endif
349 351
350 win->present(); 352 win->present();
351 } 353 }
352 354
353 void windowSizeChanged(SampleWindow* win) override { 355 void windowSizeChanged(SampleWindow* win) override {
354 #if SK_SUPPORT_GPU 356 #if SK_SUPPORT_GPU
355 if (fCurContext) { 357 if (fCurContext) {
356 AttachmentInfo attachmentInfo; 358 AttachmentInfo attachmentInfo;
357 win->attach(fBackend, fMSAASampleCount, fDeepColor, &attachmentInfo) ; 359 win->attach(fBackend, fMSAASampleCount, fDeepColor, &attachmentInfo) ;
358 SkSafeUnref(fCurRenderTarget);
359 fActualColorBits = SkTMax(attachmentInfo.fColorBits, 24); 360 fActualColorBits = SkTMax(attachmentInfo.fColorBits, 24);
360 fCurRenderTarget = win->renderTarget(attachmentInfo, fCurIntf, fCurC ontext); 361 fGpuSurface = win->makeGpuBackedSurface(attachmentInfo, fCurIntf, fC urContext);
361 } 362 }
362 #endif 363 #endif
363 } 364 }
364 365
365 GrContext* getGrContext() override { 366 GrContext* getGrContext() override {
366 #if SK_SUPPORT_GPU 367 #if SK_SUPPORT_GPU
367 return fCurContext; 368 return fCurContext;
368 #else 369 #else
369 return nullptr; 370 return nullptr;
370 #endif 371 #endif
371 } 372 }
372 373
373 GrRenderTarget* getGrRenderTarget() override { 374 int numColorSamples() const override {
374 #if SK_SUPPORT_GPU 375 return fMSAASampleCount;
375 return fCurRenderTarget;
376 #else
377 return nullptr;
378 #endif
379 } 376 }
380 377
381 int getColorBits() override { 378 int getColorBits() override {
382 #if SK_SUPPORT_GPU 379 #if SK_SUPPORT_GPU
383 return fActualColorBits; 380 return fActualColorBits;
384 #else 381 #else
385 return 24; 382 return 24;
386 #endif 383 #endif
387 } 384 }
388 385
389 private: 386 private:
390 387
391 #if SK_SUPPORT_GPU 388 #if SK_SUPPORT_GPU
392 GrContext* fCurContext; 389 GrContext* fCurContext;
393 const GrGLInterface* fCurIntf; 390 const GrGLInterface* fCurIntf;
394 GrRenderTarget* fCurRenderTarget; 391 sk_sp<SkSurface> fGpuSurface;
395 int fMSAASampleCount; 392 int fMSAASampleCount;
396 bool fDeepColor; 393 bool fDeepColor;
397 int fActualColorBits; 394 int fActualColorBits;
398 #endif 395 #endif
399 396
400 SkOSWindow::SkBackEndTypes fBackend; 397 SkOSWindow::SkBackEndTypes fBackend;
401 398
402 typedef SampleWindow::DeviceManager INHERITED; 399 typedef SampleWindow::DeviceManager INHERITED;
403 }; 400 };
404 401
(...skipping 1673 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel)); 2075 title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel));
2079 } 2076 }
2080 2077
2081 if (fMeasureFPS) { 2078 if (fMeasureFPS) {
2082 title.appendf(" %8.4f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT); 2079 title.appendf(" %8.4f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT);
2083 } 2080 }
2084 2081
2085 #if SK_SUPPORT_GPU 2082 #if SK_SUPPORT_GPU
2086 if (IsGpuDeviceType(fDeviceType) && 2083 if (IsGpuDeviceType(fDeviceType) &&
2087 fDevManager && 2084 fDevManager &&
2088 fDevManager->getGrRenderTarget() && 2085 fDevManager->numColorSamples() > 0) {
2089 fDevManager->getGrRenderTarget()->numColorSamples() > 0) {
2090 title.appendf(" [MSAA: %d]", 2086 title.appendf(" [MSAA: %d]",
2091 fDevManager->getGrRenderTarget()->numColorSamples()); 2087 fDevManager->numColorSamples());
2092 } 2088 }
2093 #endif 2089 #endif
2094 2090
2095 title.appendf(" %s", find_config_name(this->info())); 2091 title.appendf(" %s", find_config_name(this->info()));
2096 2092
2097 if (fDevManager && fDevManager->getColorBits() > 24) { 2093 if (fDevManager && fDevManager->getColorBits() > 24) {
2098 title.appendf(" %d bpc", fDevManager->getColorBits()); 2094 title.appendf(" %d bpc", fDevManager->getColorBits());
2099 } 2095 }
2100 2096
2101 this->setTitle(title.c_str()); 2097 this->setTitle(title.c_str());
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
2279 #ifdef SK_BUILD_FOR_MAC 2275 #ifdef SK_BUILD_FOR_MAC
2280 setenv("ANDROID_ROOT", "/android/device/data", 0); 2276 setenv("ANDROID_ROOT", "/android/device/data", 0);
2281 #endif 2277 #endif
2282 SkGraphics::Init(); 2278 SkGraphics::Init();
2283 SkEvent::Init(); 2279 SkEvent::Init();
2284 } 2280 }
2285 2281
2286 void application_term() { 2282 void application_term() {
2287 SkEvent::Term(); 2283 SkEvent::Term();
2288 } 2284 }
OLDNEW
« no previous file with comments | « samplecode/SampleApp.h ('k') | src/views/SkWindow.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698