joshualitt | 4dcbe43 | 2016-02-25 10:50:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "Request.h" |
| 9 | |
Brian Osman | d8a90f9 | 2019-01-28 13:41:19 -0500 | [diff] [blame] | 10 | #include "SkJSONWriter.h" |
joshualitt | e0449cf | 2016-03-09 10:07:02 -0800 | [diff] [blame] | 11 | #include "SkPictureRecorder.h" |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 12 | #include "sk_tool_utils.h" |
joshualitt | 4dcbe43 | 2016-02-25 10:50:28 -0800 | [diff] [blame] | 13 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 14 | using namespace sk_gpu_test; |
| 15 | |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 16 | static int kDefaultWidth = 1920; |
| 17 | static int kDefaultHeight = 1080; |
jcgregorio | 9a7acdc | 2016-06-30 07:54:14 -0700 | [diff] [blame] | 18 | static int kMaxWidth = 8192; |
| 19 | static int kMaxHeight = 8192; |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 20 | |
joshualitt | 4dcbe43 | 2016-02-25 10:50:28 -0800 | [diff] [blame] | 21 | |
joshualitt | ee5348b | 2016-02-26 08:36:25 -0800 | [diff] [blame] | 22 | Request::Request(SkString rootUrl) |
| 23 | : fUploadContext(nullptr) |
| 24 | , fUrlDataManager(rootUrl) |
brianosman | 7831295 | 2016-04-19 10:16:53 -0700 | [diff] [blame] | 25 | , fGPUEnabled(false) |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame] | 26 | , fOverdraw(false) |
brianosman | 7831295 | 2016-04-19 10:16:53 -0700 | [diff] [blame] | 27 | , fColorMode(0) { |
joshualitt | ee5348b | 2016-02-26 08:36:25 -0800 | [diff] [blame] | 28 | // create surface |
| 29 | GrContextOptions grContextOpts; |
joshualitt | 4083610 | 2016-03-11 11:45:53 -0800 | [diff] [blame] | 30 | fContextFactory = new GrContextFactory(grContextOpts); |
joshualitt | 4083610 | 2016-03-11 11:45:53 -0800 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | Request::~Request() { |
joshualitt | 4083610 | 2016-03-11 11:45:53 -0800 | [diff] [blame] | 34 | if (fContextFactory) { |
| 35 | delete fContextFactory; |
| 36 | } |
joshualitt | ee5348b | 2016-02-26 08:36:25 -0800 | [diff] [blame] | 37 | } |
| 38 | |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 39 | sk_sp<SkData> Request::writeCanvasToPng(SkCanvas* canvas) { |
joshualitt | 4dcbe43 | 2016-02-25 10:50:28 -0800 | [diff] [blame] | 40 | // capture pixels |
Brian Osman | d9ea816 | 2018-08-08 17:03:39 -0400 | [diff] [blame] | 41 | SkBitmap bmp; |
| 42 | bmp.allocPixels(canvas->imageInfo()); |
| 43 | SkAssertResult(canvas->readPixels(bmp, 0, 0)); |
brianosman | 7831295 | 2016-04-19 10:16:53 -0700 | [diff] [blame] | 44 | |
msarett | a5cf4f4 | 2016-06-30 10:06:51 -0700 | [diff] [blame] | 45 | // write to an opaque png (black background) |
joshualitt | 4dcbe43 | 2016-02-25 10:50:28 -0800 | [diff] [blame] | 46 | SkDynamicMemoryWStream buffer; |
Brian Osman | d9ea816 | 2018-08-08 17:03:39 -0400 | [diff] [blame] | 47 | SkDrawCommand::WritePNG(bmp, buffer); |
reed | 42943c8 | 2016-09-12 12:01:44 -0700 | [diff] [blame] | 48 | return buffer.detachAsData(); |
joshualitt | 4dcbe43 | 2016-02-25 10:50:28 -0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | SkCanvas* Request::getCanvas() { |
| 52 | GrContextFactory* factory = fContextFactory; |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 53 | GLTestContext* gl = factory->getContextInfo(GrContextFactory::kGL_ContextType, |
| 54 | GrContextFactory::ContextOverrides::kNone).glContext(); |
| 55 | if (!gl) { |
| 56 | gl = factory->getContextInfo(GrContextFactory::kGLES_ContextType, |
| 57 | GrContextFactory::ContextOverrides::kNone).glContext(); |
| 58 | } |
ethannicholas | 2ec06c9 | 2016-06-13 10:20:52 -0700 | [diff] [blame] | 59 | if (gl) { |
| 60 | gl->makeCurrent(); |
| 61 | } |
joshualitt | 4dcbe43 | 2016-02-25 10:50:28 -0800 | [diff] [blame] | 62 | SkASSERT(fDebugCanvas); |
joshualitt | e0449cf | 2016-03-09 10:07:02 -0800 | [diff] [blame] | 63 | |
| 64 | // create the appropriate surface if necessary |
| 65 | if (!fSurface) { |
| 66 | this->enableGPU(fGPUEnabled); |
| 67 | } |
joshualitt | 4dcbe43 | 2016-02-25 10:50:28 -0800 | [diff] [blame] | 68 | SkCanvas* target = fSurface->getCanvas(); |
| 69 | return target; |
| 70 | } |
| 71 | |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 72 | sk_sp<SkData> Request::drawToPng(int n, int m) { |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame] | 73 | //fDebugCanvas->setOverdrawViz(true); |
Brian Osman | d9ea816 | 2018-08-08 17:03:39 -0400 | [diff] [blame] | 74 | fDebugCanvas->drawTo(this->getCanvas(), n, m); |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame] | 75 | //fDebugCanvas->setOverdrawViz(false); |
joshualitt | 4dcbe43 | 2016-02-25 10:50:28 -0800 | [diff] [blame] | 76 | return writeCanvasToPng(this->getCanvas()); |
| 77 | } |
| 78 | |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 79 | sk_sp<SkData> Request::writeOutSkp() { |
joshualitt | e0449cf | 2016-03-09 10:07:02 -0800 | [diff] [blame] | 80 | // Playback into picture recorder |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 81 | SkIRect bounds = this->getBounds(); |
joshualitt | e0449cf | 2016-03-09 10:07:02 -0800 | [diff] [blame] | 82 | SkPictureRecorder recorder; |
brianosman | 82996b8 | 2016-04-20 10:52:54 -0700 | [diff] [blame] | 83 | SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bounds.width()), |
| 84 | SkIntToScalar(bounds.height())); |
joshualitt | e0449cf | 2016-03-09 10:07:02 -0800 | [diff] [blame] | 85 | |
| 86 | fDebugCanvas->draw(canvas); |
| 87 | |
Mike Reed | ef03848 | 2017-12-16 08:41:28 -0500 | [diff] [blame] | 88 | return recorder.finishRecordingAsPicture()->serialize(); |
joshualitt | e0449cf | 2016-03-09 10:07:02 -0800 | [diff] [blame] | 89 | } |
| 90 | |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 91 | GrContext* Request::getContext() { |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 92 | GrContext* result = fContextFactory->get(GrContextFactory::kGL_ContextType, |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 93 | GrContextFactory::ContextOverrides::kNone); |
ethannicholas | 2ec06c9 | 2016-06-13 10:20:52 -0700 | [diff] [blame] | 94 | if (!result) { |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 95 | result = fContextFactory->get(GrContextFactory::kGLES_ContextType, |
| 96 | GrContextFactory::ContextOverrides::kNone); |
| 97 | } |
ethannicholas | 2ec06c9 | 2016-06-13 10:20:52 -0700 | [diff] [blame] | 98 | return result; |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | SkIRect Request::getBounds() { |
| 102 | SkIRect bounds; |
| 103 | if (fPicture) { |
| 104 | bounds = fPicture->cullRect().roundOut(); |
| 105 | if (fGPUEnabled) { |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 106 | int maxRTSize = this->getContext()->maxRenderTargetSize(); |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 107 | bounds = SkIRect::MakeWH(SkTMin(bounds.width(), maxRTSize), |
| 108 | SkTMin(bounds.height(), maxRTSize)); |
| 109 | } |
| 110 | } else { |
| 111 | bounds = SkIRect::MakeWH(kDefaultWidth, kDefaultHeight); |
| 112 | } |
| 113 | |
jcgregorio | 9a7acdc | 2016-06-30 07:54:14 -0700 | [diff] [blame] | 114 | // We clip to kMaxWidth / kMaxHeight for performance reasons. |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 115 | // TODO make this configurable |
jcgregorio | 9a7acdc | 2016-06-30 07:54:14 -0700 | [diff] [blame] | 116 | bounds = SkIRect::MakeWH(SkTMin(bounds.width(), kMaxWidth), |
| 117 | SkTMin(bounds.height(), kMaxHeight)); |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 118 | return bounds; |
| 119 | } |
| 120 | |
brianosman | 7831295 | 2016-04-19 10:16:53 -0700 | [diff] [blame] | 121 | namespace { |
| 122 | |
| 123 | struct ColorAndProfile { |
| 124 | SkColorType fColorType; |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 125 | bool fSRGB; |
brianosman | 7831295 | 2016-04-19 10:16:53 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | ColorAndProfile ColorModes[] = { |
brianosman | 3a0dbde | 2016-07-26 11:36:05 -0700 | [diff] [blame] | 129 | { kN32_SkColorType, false }, |
| 130 | { kN32_SkColorType, true }, |
| 131 | { kRGBA_F16_SkColorType, true }, |
brianosman | 7831295 | 2016-04-19 10:16:53 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | } |
| 135 | |
joshualitt | 4dcbe43 | 2016-02-25 10:50:28 -0800 | [diff] [blame] | 136 | SkSurface* Request::createCPUSurface() { |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 137 | SkIRect bounds = this->getBounds(); |
brianosman | 7831295 | 2016-04-19 10:16:53 -0700 | [diff] [blame] | 138 | ColorAndProfile cap = ColorModes[fColorMode]; |
raftias | 7c602de | 2016-10-13 10:45:44 -0700 | [diff] [blame] | 139 | auto colorSpace = kRGBA_F16_SkColorType == cap.fColorType |
Matt Sarett | 77a7a1b | 2017-02-07 13:56:11 -0500 | [diff] [blame] | 140 | ? SkColorSpace::MakeSRGBLinear() |
| 141 | : SkColorSpace::MakeSRGB(); |
brianosman | 7831295 | 2016-04-19 10:16:53 -0700 | [diff] [blame] | 142 | SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fColorType, |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 143 | kPremul_SkAlphaType, cap.fSRGB ? colorSpace : nullptr); |
brianosman | 3a0dbde | 2016-07-26 11:36:05 -0700 | [diff] [blame] | 144 | return SkSurface::MakeRaster(info).release(); |
joshualitt | 4dcbe43 | 2016-02-25 10:50:28 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | SkSurface* Request::createGPUSurface() { |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 148 | GrContext* context = this->getContext(); |
| 149 | SkIRect bounds = this->getBounds(); |
brianosman | 7831295 | 2016-04-19 10:16:53 -0700 | [diff] [blame] | 150 | ColorAndProfile cap = ColorModes[fColorMode]; |
raftias | 7c602de | 2016-10-13 10:45:44 -0700 | [diff] [blame] | 151 | auto colorSpace = kRGBA_F16_SkColorType == cap.fColorType |
Matt Sarett | 77a7a1b | 2017-02-07 13:56:11 -0500 | [diff] [blame] | 152 | ? SkColorSpace::MakeSRGBLinear() |
| 153 | : SkColorSpace::MakeSRGB(); |
brianosman | 7831295 | 2016-04-19 10:16:53 -0700 | [diff] [blame] | 154 | SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fColorType, |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 155 | kPremul_SkAlphaType, cap.fSRGB ? colorSpace: nullptr); |
brianosman | 3a0dbde | 2016-07-26 11:36:05 -0700 | [diff] [blame] | 156 | SkSurface* surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info).release(); |
joshualitt | 4dcbe43 | 2016-02-25 10:50:28 -0800 | [diff] [blame] | 157 | return surface; |
| 158 | } |
| 159 | |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame] | 160 | bool Request::setOverdraw(bool enable) { |
| 161 | fOverdraw = enable; |
| 162 | return true; |
| 163 | } |
| 164 | |
brianosman | 7831295 | 2016-04-19 10:16:53 -0700 | [diff] [blame] | 165 | bool Request::setColorMode(int mode) { |
| 166 | fColorMode = mode; |
| 167 | return enableGPU(fGPUEnabled); |
| 168 | } |
| 169 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 170 | bool Request::enableGPU(bool enable) { |
joshualitt | ee5348b | 2016-02-26 08:36:25 -0800 | [diff] [blame] | 171 | if (enable) { |
| 172 | SkSurface* surface = this->createGPUSurface(); |
| 173 | if (surface) { |
| 174 | fSurface.reset(surface); |
| 175 | fGPUEnabled = true; |
joshualitt | 98bd5b1 | 2016-03-11 12:08:15 -0800 | [diff] [blame] | 176 | |
| 177 | // When we switch to GPU, there seems to be some mystery draws in the canvas. So we |
| 178 | // draw once to flush the pipe |
| 179 | // TODO understand what is actually happening here |
brianosman | 7831295 | 2016-04-19 10:16:53 -0700 | [diff] [blame] | 180 | if (fDebugCanvas) { |
| 181 | fDebugCanvas->drawTo(this->getCanvas(), this->getLastOp()); |
| 182 | this->getCanvas()->flush(); |
| 183 | } |
joshualitt | 98bd5b1 | 2016-03-11 12:08:15 -0800 | [diff] [blame] | 184 | |
joshualitt | ee5348b | 2016-02-26 08:36:25 -0800 | [diff] [blame] | 185 | return true; |
| 186 | } |
| 187 | return false; |
| 188 | } |
| 189 | fSurface.reset(this->createCPUSurface()); |
| 190 | fGPUEnabled = false; |
| 191 | return true; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 192 | } |
joshualitt | 6bc9679 | 2016-02-29 05:35:04 -0800 | [diff] [blame] | 193 | |
| 194 | bool Request::initPictureFromStream(SkStream* stream) { |
| 195 | // parse picture from stream |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 196 | fPicture = SkPicture::MakeFromStream(stream); |
| 197 | if (!fPicture) { |
joshualitt | 6bc9679 | 2016-02-29 05:35:04 -0800 | [diff] [blame] | 198 | fprintf(stderr, "Could not create picture from stream.\n"); |
| 199 | return false; |
| 200 | } |
| 201 | |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 202 | // reinitialize canvas with the new picture dimensions |
| 203 | this->enableGPU(fGPUEnabled); |
| 204 | |
joshualitt | 6bc9679 | 2016-02-29 05:35:04 -0800 | [diff] [blame] | 205 | // pour picture into debug canvas |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 206 | SkIRect bounds = this->getBounds(); |
joshualitt | e0449cf | 2016-03-09 10:07:02 -0800 | [diff] [blame] | 207 | fDebugCanvas.reset(new SkDebugCanvas(bounds.width(), bounds.height())); |
joshualitt | 6bc9679 | 2016-02-29 05:35:04 -0800 | [diff] [blame] | 208 | fDebugCanvas->drawPicture(fPicture); |
joshualitt | 3a9be69 | 2016-02-29 11:38:11 -0800 | [diff] [blame] | 209 | |
| 210 | // for some reason we need to 'flush' the debug canvas by drawing all of the ops |
| 211 | fDebugCanvas->drawTo(this->getCanvas(), this->getLastOp()); |
joshualitt | b0666ad | 2016-03-08 10:43:41 -0800 | [diff] [blame] | 212 | this->getCanvas()->flush(); |
joshualitt | 6bc9679 | 2016-02-29 05:35:04 -0800 | [diff] [blame] | 213 | return true; |
joshualitt | ee5348b | 2016-02-26 08:36:25 -0800 | [diff] [blame] | 214 | } |
| 215 | |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 216 | sk_sp<SkData> Request::getJsonOps(int n) { |
joshualitt | 1e5884b | 2016-02-26 08:22:49 -0800 | [diff] [blame] | 217 | SkCanvas* canvas = this->getCanvas(); |
joshualitt | 1e5884b | 2016-02-26 08:22:49 -0800 | [diff] [blame] | 218 | SkDynamicMemoryWStream stream; |
Brian Osman | d8a90f9 | 2019-01-28 13:41:19 -0500 | [diff] [blame] | 219 | SkJSONWriter writer(&stream, SkJSONWriter::Mode::kFast); |
| 220 | writer.beginObject(); // root |
joshualitt | 1e5884b | 2016-02-26 08:22:49 -0800 | [diff] [blame] | 221 | |
Brian Osman | d8a90f9 | 2019-01-28 13:41:19 -0500 | [diff] [blame] | 222 | writer.appendString("mode", fGPUEnabled ? "gpu" : "cpu"); |
| 223 | writer.appendBool("drawGpuOpBounds", fDebugCanvas->getDrawGpuOpBounds()); |
| 224 | writer.appendS32("colorMode", fColorMode); |
| 225 | fDebugCanvas->toJSON(writer, fUrlDataManager, n, canvas); |
| 226 | |
| 227 | writer.endObject(); // root |
| 228 | writer.flush(); |
reed | 42943c8 | 2016-09-12 12:01:44 -0700 | [diff] [blame] | 229 | return stream.detachAsData(); |
joshualitt | 1e5884b | 2016-02-26 08:22:49 -0800 | [diff] [blame] | 230 | } |
| 231 | |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 232 | sk_sp<SkData> Request::getJsonOpList(int n) { |
joshualitt | 1e5884b | 2016-02-26 08:22:49 -0800 | [diff] [blame] | 233 | SkCanvas* canvas = this->getCanvas(); |
| 234 | SkASSERT(fGPUEnabled); |
joshualitt | 1e5884b | 2016-02-26 08:22:49 -0800 | [diff] [blame] | 235 | SkDynamicMemoryWStream stream; |
Brian Osman | d8a90f9 | 2019-01-28 13:41:19 -0500 | [diff] [blame] | 236 | SkJSONWriter writer(&stream, SkJSONWriter::Mode::kFast); |
joshualitt | 1e5884b | 2016-02-26 08:22:49 -0800 | [diff] [blame] | 237 | |
Brian Osman | d8a90f9 | 2019-01-28 13:41:19 -0500 | [diff] [blame] | 238 | fDebugCanvas->toJSONOpList(writer, n, canvas); |
| 239 | |
| 240 | writer.flush(); |
reed | 42943c8 | 2016-09-12 12:01:44 -0700 | [diff] [blame] | 241 | return stream.detachAsData(); |
joshualitt | 1e5884b | 2016-02-26 08:22:49 -0800 | [diff] [blame] | 242 | } |
joshualitt | ee5348b | 2016-02-26 08:36:25 -0800 | [diff] [blame] | 243 | |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 244 | sk_sp<SkData> Request::getJsonInfo(int n) { |
joshualitt | ee5348b | 2016-02-26 08:36:25 -0800 | [diff] [blame] | 245 | // drawTo |
Hal Canary | 1b612a8 | 2016-11-03 16:26:13 -0400 | [diff] [blame] | 246 | sk_sp<SkSurface> surface(this->createCPUSurface()); |
joshualitt | ee5348b | 2016-02-26 08:36:25 -0800 | [diff] [blame] | 247 | SkCanvas* canvas = surface->getCanvas(); |
| 248 | |
| 249 | // TODO this is really slow and we should cache the matrix and clip |
| 250 | fDebugCanvas->drawTo(canvas, n); |
| 251 | |
| 252 | // make some json |
Brian Osman | d8a90f9 | 2019-01-28 13:41:19 -0500 | [diff] [blame] | 253 | SkDynamicMemoryWStream stream; |
| 254 | SkJSONWriter writer(&stream, SkJSONWriter::Mode::kFast); |
| 255 | |
joshualitt | ee5348b | 2016-02-26 08:36:25 -0800 | [diff] [blame] | 256 | SkMatrix vm = fDebugCanvas->getCurrentMatrix(); |
| 257 | SkIRect clip = fDebugCanvas->getCurrentClip(); |
joshualitt | ee5348b | 2016-02-26 08:36:25 -0800 | [diff] [blame] | 258 | |
Brian Osman | d8a90f9 | 2019-01-28 13:41:19 -0500 | [diff] [blame] | 259 | writer.beginObject(); // root |
| 260 | writer.appendName("ViewMatrix"); SkDrawCommand::MakeJsonMatrix(writer, vm); |
| 261 | writer.appendName("ClipRect"); SkDrawCommand::MakeJsonIRect(writer, clip); |
| 262 | writer.endObject(); // root |
joshualitt | ee5348b | 2016-02-26 08:36:25 -0800 | [diff] [blame] | 263 | |
Brian Osman | d8a90f9 | 2019-01-28 13:41:19 -0500 | [diff] [blame] | 264 | // TODO: Old code explicitly avoided the null terminator in the returned data. Important? |
| 265 | writer.flush(); |
| 266 | return stream.detachAsData(); |
joshualitt | ee5348b | 2016-02-26 08:36:25 -0800 | [diff] [blame] | 267 | } |
joshualitt | e0449cf | 2016-03-09 10:07:02 -0800 | [diff] [blame] | 268 | |
| 269 | SkColor Request::getPixel(int x, int y) { |
Brian Osman | d9ea816 | 2018-08-08 17:03:39 -0400 | [diff] [blame] | 270 | SkBitmap bmp; |
| 271 | bmp.allocPixels(this->getCanvas()->imageInfo().makeWH(1, 1)); |
| 272 | SkAssertResult(this->getCanvas()->readPixels(bmp, x, y)); |
| 273 | return bmp.getColor(0, 0); |
joshualitt | e0449cf | 2016-03-09 10:07:02 -0800 | [diff] [blame] | 274 | } |