| 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" |
| 11 #include "SkPixelSerializer.h" | 11 #include "SkPixelSerializer.h" |
| 12 | 12 |
| 13 using namespace sk_gpu_test; | |
| 14 | |
| 15 static int kDefaultWidth = 1920; | 13 static int kDefaultWidth = 1920; |
| 16 static int kDefaultHeight = 1080; | 14 static int kDefaultHeight = 1080; |
| 17 | 15 |
| 18 | 16 |
| 19 Request::Request(SkString rootUrl) | 17 Request::Request(SkString rootUrl) |
| 20 : fUploadContext(nullptr) | 18 : fUploadContext(nullptr) |
| 21 , fUrlDataManager(rootUrl) | 19 , fUrlDataManager(rootUrl) |
| 22 , fGPUEnabled(false) { | 20 , fGPUEnabled(false) { |
| 23 // create surface | 21 // create surface |
| 24 #if SK_SUPPORT_GPU | 22 #if SK_SUPPORT_GPU |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // write to png | 56 // write to png |
| 59 SkDynamicMemoryWStream buffer; | 57 SkDynamicMemoryWStream buffer; |
| 60 SkDrawCommand::WritePNG((const png_bytep) bmp->getPixels(), bmp->width(), bm
p->height(), | 58 SkDrawCommand::WritePNG((const png_bytep) bmp->getPixels(), bmp->width(), bm
p->height(), |
| 61 buffer); | 59 buffer); |
| 62 return buffer.copyToData(); | 60 return buffer.copyToData(); |
| 63 } | 61 } |
| 64 | 62 |
| 65 SkCanvas* Request::getCanvas() { | 63 SkCanvas* Request::getCanvas() { |
| 66 #if SK_SUPPORT_GPU | 64 #if SK_SUPPORT_GPU |
| 67 GrContextFactory* factory = fContextFactory; | 65 GrContextFactory* factory = fContextFactory; |
| 68 GLContext* gl = factory->getContextInfo(GrContextFactory::kNative_GLContextT
ype, | 66 SkGLContext* gl = factory->getContextInfo(GrContextFactory::kNative_GLContex
tType, |
| 69 GrContextFactory::kNone_GLContextOpt
ions).fGLContext; | 67 GrContextFactory::kNone_GLContextO
ptions).fGLContext; |
| 70 gl->makeCurrent(); | 68 gl->makeCurrent(); |
| 71 #endif | 69 #endif |
| 72 SkASSERT(fDebugCanvas); | 70 SkASSERT(fDebugCanvas); |
| 73 | 71 |
| 74 // create the appropriate surface if necessary | 72 // create the appropriate surface if necessary |
| 75 if (!fSurface) { | 73 if (!fSurface) { |
| 76 this->enableGPU(fGPUEnabled); | 74 this->enableGPU(fGPUEnabled); |
| 77 } | 75 } |
| 78 SkCanvas* target = fSurface->getCanvas(); | 76 SkCanvas* target = fSurface->getCanvas(); |
| 79 return target; | 77 return target; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 SkCanvas* canvas = this->getCanvas(); | 247 SkCanvas* canvas = this->getCanvas(); |
| 250 canvas->flush(); | 248 canvas->flush(); |
| 251 SkAutoTDelete<SkBitmap> bitmap(this->getBitmapFromCanvas(canvas)); | 249 SkAutoTDelete<SkBitmap> bitmap(this->getBitmapFromCanvas(canvas)); |
| 252 SkASSERT(bitmap); | 250 SkASSERT(bitmap); |
| 253 bitmap->lockPixels(); | 251 bitmap->lockPixels(); |
| 254 uint8_t* start = ((uint8_t*) bitmap->getPixels()) + (y * bitmap->width() + x
) * 4; | 252 uint8_t* start = ((uint8_t*) bitmap->getPixels()) + (y * bitmap->width() + x
) * 4; |
| 255 SkColor result = SkColorSetARGB(start[3], start[0], start[1], start[2]); | 253 SkColor result = SkColorSetARGB(start[3], start[0], start[1], start[2]); |
| 256 bitmap->unlockPixels(); | 254 bitmap->unlockPixels(); |
| 257 return result; | 255 return result; |
| 258 } | 256 } |
| OLD | NEW |