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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } | 139 } |
140 | 140 |
141 GrAuditTrail* Request::getAuditTrail(SkCanvas* canvas) { | |
142 GrAuditTrail* at = nullptr; | |
143 #if SK_SUPPORT_GPU | |
144 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget(); | |
145 if (rt) { | |
146 GrContext* ctx = rt->getContext(); | |
147 if (ctx) { | |
148 at = ctx->getAuditTrail(); | |
149 } | |
150 } | |
151 #endif | |
152 return at; | |
153 } | |
154 | |
155 void Request::cleanupAuditTrail(SkCanvas* canvas) { | |
156 GrAuditTrail* at = this->getAuditTrail(canvas); | |
157 if (at) { | |
158 GrAuditTrail::AutoEnable ae(at); | |
159 at->fullReset(); | |
160 } | |
161 } | |
162 | |
163 SkData* Request::getJsonOps(int n) { | 141 SkData* Request::getJsonOps(int n) { |
164 SkCanvas* canvas = this->getCanvas(); | 142 SkCanvas* canvas = this->getCanvas(); |
165 Json::Value root = fDebugCanvas->toJSON(fUrlDataManager, n, canvas); | 143 Json::Value root = fDebugCanvas->toJSON(fUrlDataManager, n, canvas); |
166 root["mode"] = Json::Value(fGPUEnabled ? "gpu" : "cpu"); | 144 root["mode"] = Json::Value(fGPUEnabled ? "gpu" : "cpu"); |
167 SkDynamicMemoryWStream stream; | 145 SkDynamicMemoryWStream stream; |
168 stream.writeText(Json::FastWriter().write(root).c_str()); | 146 stream.writeText(Json::FastWriter().write(root).c_str()); |
169 | 147 |
170 this->cleanupAuditTrail(canvas); | |
171 | |
172 return stream.copyToData(); | 148 return stream.copyToData(); |
173 } | 149 } |
174 | 150 |
175 SkData* Request::getJsonBatchList(int n) { | 151 SkData* Request::getJsonBatchList(int n) { |
176 SkCanvas* canvas = this->getCanvas(); | 152 SkCanvas* canvas = this->getCanvas(); |
177 SkASSERT(fGPUEnabled); | 153 SkASSERT(fGPUEnabled); |
178 | 154 |
179 // TODO if this is inefficient we could add a method to GrAuditTrail which t
akes | 155 // TODO if this is inefficient we could add a method to GrAuditTrail which t
akes |
180 // a Json::Value and is only compiled in this file | 156 // a Json::Value and is only compiled in this file |
181 Json::Value parsedFromString; | 157 Json::Value parsedFromString; |
182 #if SK_SUPPORT_GPU | 158 #if SK_SUPPORT_GPU |
183 GrAuditTrail* at = this->getAuditTrail(canvas); | 159 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget(); |
| 160 SkASSERT(rt); |
| 161 GrContext* ctx = rt->getContext(); |
| 162 SkASSERT(ctx); |
| 163 GrAuditTrail* at = ctx->getAuditTrail(); |
184 GrAuditTrail::AutoManageBatchList enable(at); | 164 GrAuditTrail::AutoManageBatchList enable(at); |
185 | 165 |
186 fDebugCanvas->drawTo(canvas, n); | 166 fDebugCanvas->drawTo(canvas, n); |
187 | 167 |
188 Json::Reader reader; | 168 Json::Reader reader; |
189 SkDEBUGCODE(bool parsingSuccessful = )reader.parse(at->toJson(true).c_str(), | 169 SkDEBUGCODE(bool parsingSuccessful = )reader.parse(at->toJson(true).c_str(), |
190 parsedFromString); | 170 parsedFromString); |
191 SkASSERT(parsingSuccessful); | 171 SkASSERT(parsingSuccessful); |
192 #endif | 172 #endif |
193 | 173 |
(...skipping 16 matching lines...) Expand all Loading... |
210 SkIRect clip = fDebugCanvas->getCurrentClip(); | 190 SkIRect clip = fDebugCanvas->getCurrentClip(); |
211 Json::Value info(Json::objectValue); | 191 Json::Value info(Json::objectValue); |
212 info["ViewMatrix"] = SkJSONCanvas::MakeMatrix(vm); | 192 info["ViewMatrix"] = SkJSONCanvas::MakeMatrix(vm); |
213 info["ClipRect"] = SkJSONCanvas::MakeIRect(clip); | 193 info["ClipRect"] = SkJSONCanvas::MakeIRect(clip); |
214 | 194 |
215 std::string json = Json::FastWriter().write(info); | 195 std::string json = Json::FastWriter().write(info); |
216 | 196 |
217 // We don't want the null terminator so strlen is correct | 197 // We don't want the null terminator so strlen is correct |
218 return SkData::NewWithCopy(json.c_str(), strlen(json.c_str())); | 198 return SkData::NewWithCopy(json.c_str(), strlen(json.c_str())); |
219 } | 199 } |
OLD | NEW |