OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "Request.h" | 8 #include "Request.h" |
9 | 9 |
10 #include "SkPictureRecorder.h" | 10 #include "SkPictureRecorder.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 SkSurface* surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, i
nfo, 0, | 194 SkSurface* surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, i
nfo, 0, |
195 &props).release(); | 195 &props).release(); |
196 return surface; | 196 return surface; |
197 } | 197 } |
198 | 198 |
199 bool Request::setColorMode(int mode) { | 199 bool Request::setColorMode(int mode) { |
200 fColorMode = mode; | 200 fColorMode = mode; |
201 return enableGPU(fGPUEnabled); | 201 return enableGPU(fGPUEnabled); |
202 } | 202 } |
203 | 203 |
204 bool Request::setSRGBMode(bool enable) { | |
205 gTreatSkColorAsSRGB = enable; | |
206 return true; | |
207 } | |
208 | |
209 bool Request::enableGPU(bool enable) { | 204 bool Request::enableGPU(bool enable) { |
210 if (enable) { | 205 if (enable) { |
211 SkSurface* surface = this->createGPUSurface(); | 206 SkSurface* surface = this->createGPUSurface(); |
212 if (surface) { | 207 if (surface) { |
213 fSurface.reset(surface); | 208 fSurface.reset(surface); |
214 fGPUEnabled = true; | 209 fGPUEnabled = true; |
215 | 210 |
216 // When we switch to GPU, there seems to be some mystery draws in th
e canvas. So we | 211 // When we switch to GPU, there seems to be some mystery draws in th
e canvas. So we |
217 // draw once to flush the pipe | 212 // draw once to flush the pipe |
218 // TODO understand what is actually happening here | 213 // TODO understand what is actually happening here |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 this->getCanvas()->flush(); | 246 this->getCanvas()->flush(); |
252 return true; | 247 return true; |
253 } | 248 } |
254 | 249 |
255 SkData* Request::getJsonOps(int n) { | 250 SkData* Request::getJsonOps(int n) { |
256 SkCanvas* canvas = this->getCanvas(); | 251 SkCanvas* canvas = this->getCanvas(); |
257 Json::Value root = fDebugCanvas->toJSON(fUrlDataManager, n, canvas); | 252 Json::Value root = fDebugCanvas->toJSON(fUrlDataManager, n, canvas); |
258 root["mode"] = Json::Value(fGPUEnabled ? "gpu" : "cpu"); | 253 root["mode"] = Json::Value(fGPUEnabled ? "gpu" : "cpu"); |
259 root["drawGpuBatchBounds"] = Json::Value(fDebugCanvas->getDrawGpuBatchBounds
()); | 254 root["drawGpuBatchBounds"] = Json::Value(fDebugCanvas->getDrawGpuBatchBounds
()); |
260 root["colorMode"] = Json::Value(fColorMode); | 255 root["colorMode"] = Json::Value(fColorMode); |
261 root["srgbMode"] = Json::Value(gTreatSkColorAsSRGB); | |
262 SkDynamicMemoryWStream stream; | 256 SkDynamicMemoryWStream stream; |
263 stream.writeText(Json::FastWriter().write(root).c_str()); | 257 stream.writeText(Json::FastWriter().write(root).c_str()); |
264 | 258 |
265 return stream.copyToData(); | 259 return stream.copyToData(); |
266 } | 260 } |
267 | 261 |
268 SkData* Request::getJsonBatchList(int n) { | 262 SkData* Request::getJsonBatchList(int n) { |
269 SkCanvas* canvas = this->getCanvas(); | 263 SkCanvas* canvas = this->getCanvas(); |
270 SkASSERT(fGPUEnabled); | 264 SkASSERT(fGPUEnabled); |
271 | 265 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 SkASSERT(bitmap); | 299 SkASSERT(bitmap); |
306 | 300 |
307 // Convert to format suitable for inspection | 301 // Convert to format suitable for inspection |
308 sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(*bitmap); | 302 sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(*bitmap); |
309 SkASSERT(encodedBitmap.get()); | 303 SkASSERT(encodedBitmap.get()); |
310 | 304 |
311 const uint8_t* start = encodedBitmap->bytes() + ((y * bitmap->width() + x) *
4); | 305 const uint8_t* start = encodedBitmap->bytes() + ((y * bitmap->width() + x) *
4); |
312 SkColor result = SkColorSetARGB(start[3], start[0], start[1], start[2]); | 306 SkColor result = SkColorSetARGB(start[3], start[0], start[1], start[2]); |
313 return result; | 307 return result; |
314 } | 308 } |
OLD | NEW |