| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 SkASSERT(bmp); | 58 SkASSERT(bmp); |
| 59 | 59 |
| 60 // Convert to format suitable for PNG output | 60 // Convert to format suitable for PNG output |
| 61 sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(*bmp); | 61 sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(*bmp); |
| 62 SkASSERT(encodedBitmap.get()); | 62 SkASSERT(encodedBitmap.get()); |
| 63 | 63 |
| 64 // write to an opaque png (black background) | 64 // write to an opaque png (black background) |
| 65 SkDynamicMemoryWStream buffer; | 65 SkDynamicMemoryWStream buffer; |
| 66 SkDrawCommand::WritePNG((const png_bytep) encodedBitmap->bytes(), bmp->width
(), bmp->height(), | 66 SkDrawCommand::WritePNG((const png_bytep) encodedBitmap->bytes(), bmp->width
(), bmp->height(), |
| 67 buffer, true); | 67 buffer, true); |
| 68 return sk_sp<SkData>(buffer.copyToData()); | 68 return buffer.detachAsData(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 SkCanvas* Request::getCanvas() { | 71 SkCanvas* Request::getCanvas() { |
| 72 #if SK_SUPPORT_GPU | 72 #if SK_SUPPORT_GPU |
| 73 GrContextFactory* factory = fContextFactory; | 73 GrContextFactory* factory = fContextFactory; |
| 74 GLTestContext* gl = factory->getContextInfo(GrContextFactory::kNativeGL_Cont
extType, | 74 GLTestContext* gl = factory->getContextInfo(GrContextFactory::kNativeGL_Cont
extType, |
| 75 GrContextFactory::kNone_ContextO
ptions).glContext(); | 75 GrContextFactory::kNone_ContextO
ptions).glContext(); |
| 76 if (!gl) { | 76 if (!gl) { |
| 77 gl = factory->getContextInfo(GrContextFactory::kMESA_ContextType, | 77 gl = factory->getContextInfo(GrContextFactory::kMESA_ContextType, |
| 78 GrContextFactory::kNone_ContextOptions).glC
ontext(); | 78 GrContextFactory::kNone_ContextOptions).glC
ontext(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 fDebugCanvas->draw(canvas); | 111 fDebugCanvas->draw(canvas); |
| 112 | 112 |
| 113 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); | 113 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
| 114 | 114 |
| 115 SkDynamicMemoryWStream outStream; | 115 SkDynamicMemoryWStream outStream; |
| 116 | 116 |
| 117 SkAutoTUnref<SkPixelSerializer> serializer(SkImageEncoder::CreatePixelSerial
izer()); | 117 SkAutoTUnref<SkPixelSerializer> serializer(SkImageEncoder::CreatePixelSerial
izer()); |
| 118 picture->serialize(&outStream, serializer); | 118 picture->serialize(&outStream, serializer); |
| 119 | 119 |
| 120 return sk_sp<SkData>(outStream.copyToData()); | 120 return outStream.detachAsData(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 GrContext* Request::getContext() { | 123 GrContext* Request::getContext() { |
| 124 #if SK_SUPPORT_GPU | 124 #if SK_SUPPORT_GPU |
| 125 GrContext* result = fContextFactory->get(GrContextFactory::kNativeGL_Context
Type, | 125 GrContext* result = fContextFactory->get(GrContextFactory::kNativeGL_Context
Type, |
| 126 GrContextFactory::kNone_ContextOpti
ons); | 126 GrContextFactory::kNone_ContextOpti
ons); |
| 127 if (!result) { | 127 if (!result) { |
| 128 result = fContextFactory->get(GrContextFactory::kMESA_ContextType, | 128 result = fContextFactory->get(GrContextFactory::kMESA_ContextType, |
| 129 GrContextFactory::kNone_ContextOptions); | 129 GrContextFactory::kNone_ContextOptions); |
| 130 } | 130 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 250 |
| 251 sk_sp<SkData> Request::getJsonOps(int n) { | 251 sk_sp<SkData> Request::getJsonOps(int n) { |
| 252 SkCanvas* canvas = this->getCanvas(); | 252 SkCanvas* canvas = this->getCanvas(); |
| 253 Json::Value root = fDebugCanvas->toJSON(fUrlDataManager, n, canvas); | 253 Json::Value root = fDebugCanvas->toJSON(fUrlDataManager, n, canvas); |
| 254 root["mode"] = Json::Value(fGPUEnabled ? "gpu" : "cpu"); | 254 root["mode"] = Json::Value(fGPUEnabled ? "gpu" : "cpu"); |
| 255 root["drawGpuBatchBounds"] = Json::Value(fDebugCanvas->getDrawGpuBatchBounds
()); | 255 root["drawGpuBatchBounds"] = Json::Value(fDebugCanvas->getDrawGpuBatchBounds
()); |
| 256 root["colorMode"] = Json::Value(fColorMode); | 256 root["colorMode"] = Json::Value(fColorMode); |
| 257 SkDynamicMemoryWStream stream; | 257 SkDynamicMemoryWStream stream; |
| 258 stream.writeText(Json::FastWriter().write(root).c_str()); | 258 stream.writeText(Json::FastWriter().write(root).c_str()); |
| 259 | 259 |
| 260 return sk_sp<SkData>(stream.copyToData()); | 260 return stream.detachAsData(); |
| 261 } | 261 } |
| 262 | 262 |
| 263 sk_sp<SkData> Request::getJsonBatchList(int n) { | 263 sk_sp<SkData> Request::getJsonBatchList(int n) { |
| 264 SkCanvas* canvas = this->getCanvas(); | 264 SkCanvas* canvas = this->getCanvas(); |
| 265 SkASSERT(fGPUEnabled); | 265 SkASSERT(fGPUEnabled); |
| 266 | 266 |
| 267 Json::Value result = fDebugCanvas->toJSONBatchList(n, canvas); | 267 Json::Value result = fDebugCanvas->toJSONBatchList(n, canvas); |
| 268 | 268 |
| 269 SkDynamicMemoryWStream stream; | 269 SkDynamicMemoryWStream stream; |
| 270 stream.writeText(Json::FastWriter().write(result).c_str()); | 270 stream.writeText(Json::FastWriter().write(result).c_str()); |
| 271 | 271 |
| 272 return sk_sp<SkData>(stream.copyToData()); | 272 return stream.detachAsData(); |
| 273 } | 273 } |
| 274 | 274 |
| 275 sk_sp<SkData> Request::getJsonInfo(int n) { | 275 sk_sp<SkData> Request::getJsonInfo(int n) { |
| 276 // drawTo | 276 // drawTo |
| 277 SkAutoTUnref<SkSurface> surface(this->createCPUSurface()); | 277 SkAutoTUnref<SkSurface> surface(this->createCPUSurface()); |
| 278 SkCanvas* canvas = surface->getCanvas(); | 278 SkCanvas* canvas = surface->getCanvas(); |
| 279 | 279 |
| 280 // TODO this is really slow and we should cache the matrix and clip | 280 // TODO this is really slow and we should cache the matrix and clip |
| 281 fDebugCanvas->drawTo(canvas, n); | 281 fDebugCanvas->drawTo(canvas, n); |
| 282 | 282 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 294 } | 294 } |
| 295 | 295 |
| 296 SkColor Request::getPixel(int x, int y) { | 296 SkColor Request::getPixel(int x, int y) { |
| 297 SkCanvas* canvas = this->getCanvas(); | 297 SkCanvas* canvas = this->getCanvas(); |
| 298 canvas->flush(); | 298 canvas->flush(); |
| 299 SkAutoTDelete<SkBitmap> bitmap(this->getBitmapFromCanvas(canvas)); | 299 SkAutoTDelete<SkBitmap> bitmap(this->getBitmapFromCanvas(canvas)); |
| 300 SkASSERT(bitmap); | 300 SkASSERT(bitmap); |
| 301 | 301 |
| 302 // Convert to format suitable for inspection | 302 // Convert to format suitable for inspection |
| 303 sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(*bitmap); | 303 sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(*bitmap); |
| 304 SkASSERT(encodedBitmap.get()); | 304 SkASSERT(encodedBitmap); |
| 305 | 305 |
| 306 const uint8_t* start = encodedBitmap->bytes() + ((y * bitmap->width() + x) *
4); | 306 const uint8_t* start = encodedBitmap->bytes() + ((y * bitmap->width() + x) *
4); |
| 307 SkColor result = SkColorSetARGB(start[3], start[0], start[1], start[2]); | 307 SkColor result = SkColorSetARGB(start[3], start[0], start[1], start[2]); |
| 308 return result; | 308 return result; |
| 309 } | 309 } |
| OLD | NEW |