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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 SkDrawCommand::WritePNG((const png_bytep) encodedBitmap->writable_data(), | 64 SkDrawCommand::WritePNG((const png_bytep) encodedBitmap->writable_data(), |
65 bmp->width(), bmp->height(), | 65 bmp->width(), bmp->height(), |
66 buffer); | 66 buffer); |
67 return buffer.copyToData(); | 67 return buffer.copyToData(); |
68 } | 68 } |
69 | 69 |
70 SkCanvas* Request::getCanvas() { | 70 SkCanvas* Request::getCanvas() { |
71 #if SK_SUPPORT_GPU | 71 #if SK_SUPPORT_GPU |
72 GrContextFactory* factory = fContextFactory; | 72 GrContextFactory* factory = fContextFactory; |
73 GLTestContext* gl = factory->getContextInfo(GrContextFactory::kNativeGL_Cont
extType, | 73 GLTestContext* gl = factory->getContextInfo(GrContextFactory::kNativeGL_Cont
extType, |
74 GrContextFactory::kNone_ContextOptio
ns).glContext(); | 74 GrContextFactory::kNone_ContextO
ptions).glContext(); |
75 gl->makeCurrent(); | 75 if (!gl) { |
| 76 gl = factory->getContextInfo(GrContextFactory::kMESA_ContextType, |
| 77 GrContextFactory::kNone_ContextOptions).glC
ontext(); |
| 78 } |
| 79 if (gl) { |
| 80 gl->makeCurrent(); |
| 81 } |
76 #endif | 82 #endif |
77 SkASSERT(fDebugCanvas); | 83 SkASSERT(fDebugCanvas); |
78 | 84 |
79 // create the appropriate surface if necessary | 85 // create the appropriate surface if necessary |
80 if (!fSurface) { | 86 if (!fSurface) { |
81 this->enableGPU(fGPUEnabled); | 87 this->enableGPU(fGPUEnabled); |
82 } | 88 } |
83 SkCanvas* target = fSurface->getCanvas(); | 89 SkCanvas* target = fSurface->getCanvas(); |
84 return target; | 90 return target; |
85 } | 91 } |
(...skipping 22 matching lines...) Expand all Loading... |
108 SkDynamicMemoryWStream outStream; | 114 SkDynamicMemoryWStream outStream; |
109 | 115 |
110 SkAutoTUnref<SkPixelSerializer> serializer(SkImageEncoder::CreatePixelSerial
izer()); | 116 SkAutoTUnref<SkPixelSerializer> serializer(SkImageEncoder::CreatePixelSerial
izer()); |
111 picture->serialize(&outStream, serializer); | 117 picture->serialize(&outStream, serializer); |
112 | 118 |
113 return outStream.copyToData(); | 119 return outStream.copyToData(); |
114 } | 120 } |
115 | 121 |
116 GrContext* Request::getContext() { | 122 GrContext* Request::getContext() { |
117 #if SK_SUPPORT_GPU | 123 #if SK_SUPPORT_GPU |
118 return fContextFactory->get(GrContextFactory::kNativeGL_ContextType, | 124 GrContext* result = fContextFactory->get(GrContextFactory::kNativeGL_Context
Type, |
119 GrContextFactory::kNone_ContextOptions); | 125 GrContextFactory::kNone_ContextOpti
ons); |
| 126 if (!result) { |
| 127 result = fContextFactory->get(GrContextFactory::kMESA_ContextType, |
| 128 GrContextFactory::kNone_ContextOptions); |
| 129 } |
| 130 return result; |
120 #else | 131 #else |
121 return nullptr; | 132 return nullptr; |
122 #endif | 133 #endif |
123 } | 134 } |
124 | 135 |
125 SkIRect Request::getBounds() { | 136 SkIRect Request::getBounds() { |
126 SkIRect bounds; | 137 SkIRect bounds; |
127 if (fPicture) { | 138 if (fPicture) { |
128 bounds = fPicture->cullRect().roundOut(); | 139 bounds = fPicture->cullRect().roundOut(); |
129 if (fGPUEnabled) { | 140 if (fGPUEnabled) { |
130 #if SK_SUPPORT_GPU | 141 #if SK_SUPPORT_GPU |
131 int maxRTSize = this->getContext()->caps()->maxRenderTargetSize(); | 142 int maxRTSize = this->getContext()->caps()->maxRenderTargetSize(); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 SkASSERT(bitmap); | 303 SkASSERT(bitmap); |
293 | 304 |
294 // Convert to format suitable for inspection | 305 // Convert to format suitable for inspection |
295 sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(*bitmap); | 306 sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(*bitmap); |
296 SkASSERT(encodedBitmap.get()); | 307 SkASSERT(encodedBitmap.get()); |
297 | 308 |
298 const uint8_t* start = encodedBitmap->bytes() + ((y * bitmap->width() + x) *
4); | 309 const uint8_t* start = encodedBitmap->bytes() + ((y * bitmap->width() + x) *
4); |
299 SkColor result = SkColorSetARGB(start[3], start[0], start[1], start[2]); | 310 SkColor result = SkColorSetARGB(start[3], start[0], start[1], start[2]); |
300 return result; | 311 return result; |
301 } | 312 } |
OLD | NEW |