| 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 "png.h" | 10 #include "png.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 if (surface) { | 129 if (surface) { |
| 130 fSurface.reset(surface); | 130 fSurface.reset(surface); |
| 131 fGPUEnabled = true; | 131 fGPUEnabled = true; |
| 132 return true; | 132 return true; |
| 133 } | 133 } |
| 134 return false; | 134 return false; |
| 135 } | 135 } |
| 136 fSurface.reset(this->createCPUSurface()); | 136 fSurface.reset(this->createCPUSurface()); |
| 137 fGPUEnabled = false; | 137 fGPUEnabled = false; |
| 138 return true; | 138 return true; |
| 139 } |
| 140 |
| 141 bool Request::initPictureFromStream(SkStream* stream) { |
| 142 // parse picture from stream |
| 143 fPicture.reset(SkPicture::CreateFromStream(stream)); |
| 144 if (!fPicture.get()) { |
| 145 fprintf(stderr, "Could not create picture from stream.\n"); |
| 146 return false; |
| 147 } |
| 148 |
| 149 // pour picture into debug canvas |
| 150 fDebugCanvas.reset(new SkDebugCanvas(kImageWidth, Request::kImageHeight)); |
| 151 fDebugCanvas->drawPicture(fPicture); |
| 152 return true; |
| 139 } | 153 } |
| 140 | 154 |
| 141 SkData* Request::getJsonOps(int n) { | 155 SkData* Request::getJsonOps(int n) { |
| 142 SkCanvas* canvas = this->getCanvas(); | 156 SkCanvas* canvas = this->getCanvas(); |
| 143 Json::Value root = fDebugCanvas->toJSON(fUrlDataManager, n, canvas); | 157 Json::Value root = fDebugCanvas->toJSON(fUrlDataManager, n, canvas); |
| 144 root["mode"] = Json::Value(fGPUEnabled ? "gpu" : "cpu"); | 158 root["mode"] = Json::Value(fGPUEnabled ? "gpu" : "cpu"); |
| 145 SkDynamicMemoryWStream stream; | 159 SkDynamicMemoryWStream stream; |
| 146 stream.writeText(Json::FastWriter().write(root).c_str()); | 160 stream.writeText(Json::FastWriter().write(root).c_str()); |
| 147 | 161 |
| 148 return stream.copyToData(); | 162 return stream.copyToData(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 SkIRect clip = fDebugCanvas->getCurrentClip(); | 204 SkIRect clip = fDebugCanvas->getCurrentClip(); |
| 191 Json::Value info(Json::objectValue); | 205 Json::Value info(Json::objectValue); |
| 192 info["ViewMatrix"] = SkJSONCanvas::MakeMatrix(vm); | 206 info["ViewMatrix"] = SkJSONCanvas::MakeMatrix(vm); |
| 193 info["ClipRect"] = SkJSONCanvas::MakeIRect(clip); | 207 info["ClipRect"] = SkJSONCanvas::MakeIRect(clip); |
| 194 | 208 |
| 195 std::string json = Json::FastWriter().write(info); | 209 std::string json = Json::FastWriter().write(info); |
| 196 | 210 |
| 197 // We don't want the null terminator so strlen is correct | 211 // We don't want the null terminator so strlen is correct |
| 198 return SkData::NewWithCopy(json.c_str(), strlen(json.c_str())); | 212 return SkData::NewWithCopy(json.c_str(), strlen(json.c_str())); |
| 199 } | 213 } |
| OLD | NEW |