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

Side by Side Diff: gm/srcmode.cpp

Issue 355193006: stop calling SkCanvas::getDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 108 }
109 canvas->restore(); 109 canvas->restore();
110 canvas->translate(W * 5 / 4, 0); 110 canvas->translate(W * 5 / 4, 0);
111 } 111 }
112 } 112 }
113 canvas->restore(); 113 canvas->restore();
114 canvas->translate(0, (H * 5 / 4) * SK_ARRAY_COUNT(procs)); 114 canvas->translate(0, (H * 5 / 4) * SK_ARRAY_COUNT(procs));
115 } 115 }
116 } 116 }
117 117
118 static SkSurface* compat_surface(SkCanvas* canvas, const SkISize& size, 118 static SkSurface* compat_surface(SkCanvas* canvas, const SkISize& size, bool skipGPU) {
119 bool skipGPU) {
120 SkImageInfo info = SkImageInfo::MakeN32Premul(size); 119 SkImageInfo info = SkImageInfo::MakeN32Premul(size);
120
121 bool callNewSurface = true;
121 #if SK_SUPPORT_GPU 122 #if SK_SUPPORT_GPU
122 SkBaseDevice* dev = canvas->getDevice(); 123 if (canvas->getGrContext() && skipGPU) {
123 if (!skipGPU && dev->accessRenderTarget()) { 124 callNewSurface = false;
124 SkGpuDevice* gd = (SkGpuDevice*)dev;
125 GrContext* ctx = gd->context();
126 return SkSurface::NewRenderTarget(ctx, info, 0);
127 } 125 }
128 #endif 126 #endif
129 return SkSurface::NewRaster(info); 127 SkSurface* surface = callNewSurface ? canvas->newSurface(info) : NULL;
128 if (NULL == surface) {
129 // picture canvas will return null, so fall-back to raster
130 surface = SkSurface::NewRaster(info);
131 }
132 return surface;
130 } 133 }
131 134
132 virtual void onDraw(SkCanvas* canvas) { 135 virtual void onDraw(SkCanvas* canvas) {
133 SkAutoTUnref<SkSurface> surf(compat_surface(canvas, this->getISize(), 136 SkAutoTUnref<SkSurface> surf(compat_surface(canvas, this->getISize(),
134 this->isCanvasDeferred())); 137 this->isCanvasDeferred()));
135 surf->getCanvas()->drawColor(SK_ColorWHITE); 138 surf->getCanvas()->drawColor(SK_ColorWHITE);
136 this->drawContent(surf->getCanvas()); 139 this->drawContent(surf->getCanvas());
137 surf->draw(canvas, 0, 0, NULL); 140 surf->draw(canvas, 0, 0, NULL);
138 } 141 }
139 142
140 private: 143 private:
141 typedef skiagm::GM INHERITED; 144 typedef skiagm::GM INHERITED;
142 }; 145 };
143 146
144 /////////////////////////////////////////////////////////////////////////////// 147 ///////////////////////////////////////////////////////////////////////////////
145 148
146 DEF_GM(return new SrcModeGM;) 149 DEF_GM(return new SrcModeGM;)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698