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 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "gm.h" | 9 #include "gm.h" |
10 #include "SkMipMap.h" | 10 #include "SkMipMap.h" |
11 #include "Resources.h" | 11 #include "Resources.h" |
12 | 12 |
13 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
14 #include "GrContext.h" | 14 #include "GrContext.h" |
15 | 15 |
16 // Helper function that uploads the given SkImage using MakdeFromDeferredTexture
ImageData and then | 16 // Helper function that uploads the given SkImage using MakdeFromDeferredTexture
ImageData and then |
17 // draws the uploaded version at the specified coordinates. | 17 // draws the uploaded version at the specified coordinates. |
18 static void DrawDeferredTextureImageData(SkCanvas* canvas, | 18 static void DrawDeferredTextureImageData(SkCanvas* canvas, |
19 SkImage::DeferredTextureImageUsageParam
s* params) { | 19 SkImage::DeferredTextureImageUsageParam
s* params) { |
20 GrContext* context = canvas->getGrContext(); | 20 GrContext* context = canvas->getGrContext(); |
21 if (!context) { | 21 if (!context) { |
22 skiagm::GM::DrawGpuOnlyMessage(canvas); | 22 skiagm::GM::DrawGpuOnlyMessage(canvas); |
23 return; | 23 return; |
24 } | 24 } |
25 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy()); | 25 sk_sp<GrContextThreadSafeProxy> proxy(context->threadSafeProxy()); |
26 | 26 |
27 | 27 |
28 | 28 |
29 sk_sp<SkImage> encodedImage = GetResourceAsImage("mandrill_512.png"); | 29 sk_sp<SkImage> encodedImage = GetResourceAsImage("mandrill_512.png"); |
30 if (!encodedImage) { | 30 if (!encodedImage) { |
31 SkDebugf("\nCould not load resource.\n"); | 31 SkDebugf("\nCould not load resource.\n"); |
32 return; | 32 return; |
33 } | 33 } |
34 | 34 |
35 size_t requiredMemoryInBytes = encodedImage->getDeferredTextureImageData( | 35 size_t requiredMemoryInBytes = encodedImage->getDeferredTextureImageData( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 canvas->drawImage(uploadedDecodedImage, 512 + 20, 10); | 73 canvas->drawImage(uploadedDecodedImage, 512 + 20, 10); |
74 } | 74 } |
75 | 75 |
76 static void DrawDeferredTextureImageMipMapTree(SkCanvas* canvas, SkImage* image, | 76 static void DrawDeferredTextureImageMipMapTree(SkCanvas* canvas, SkImage* image, |
77 SkImage::DeferredTextureImageUsag
eParams* params) { | 77 SkImage::DeferredTextureImageUsag
eParams* params) { |
78 GrContext* context = canvas->getGrContext(); | 78 GrContext* context = canvas->getGrContext(); |
79 if (!context) { | 79 if (!context) { |
80 skiagm::GM::DrawGpuOnlyMessage(canvas); | 80 skiagm::GM::DrawGpuOnlyMessage(canvas); |
81 return; | 81 return; |
82 } | 82 } |
83 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy()); | 83 sk_sp<GrContextThreadSafeProxy> proxy(context->threadSafeProxy()); |
84 | 84 |
85 SkPaint paint; | 85 SkPaint paint; |
86 paint.setFilterQuality(params->fQuality); | 86 paint.setFilterQuality(params->fQuality); |
87 | 87 |
88 int mipLevelCount = SkMipMap::ComputeLevelCount(512, 512); | 88 int mipLevelCount = SkMipMap::ComputeLevelCount(512, 512); |
89 size_t requiredMemoryInBytes = image->getDeferredTextureImageData( | 89 size_t requiredMemoryInBytes = image->getDeferredTextureImageData( |
90 *proxy, params, 1, nullptr, canvas->imageInfo().colorSpace()); | 90 *proxy, params, 1, nullptr, canvas->imageInfo().colorSpace()); |
91 if (requiredMemoryInBytes == 0) { | 91 if (requiredMemoryInBytes == 0) { |
92 SkDebugf("\nCould not create DeferredTextureImageData.\n"); | 92 SkDebugf("\nCould not create DeferredTextureImageData.\n"); |
93 return; | 93 return; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 DrawDeferredTextureImageMipMapTree(canvas, decodedImage.get(), ¶ms); | 176 DrawDeferredTextureImageMipMapTree(canvas, decodedImage.get(), ¶ms); |
177 } | 177 } |
178 | 178 |
179 DEF_SIMPLE_GM(deferred_texture_image_high, canvas, 512 + 512 + 30, 512 + 20) { | 179 DEF_SIMPLE_GM(deferred_texture_image_high, canvas, 512 + 512 + 30, 512 + 20) { |
180 auto params = SkImage::DeferredTextureImageUsageParams(SkMatrix::MakeScale(1
.f, 1.f), | 180 auto params = SkImage::DeferredTextureImageUsageParams(SkMatrix::MakeScale(1
.f, 1.f), |
181 kHigh_SkFilterQuality
, 0); | 181 kHigh_SkFilterQuality
, 0); |
182 DrawDeferredTextureImageData(canvas, ¶ms); | 182 DrawDeferredTextureImageData(canvas, ¶ms); |
183 } | 183 } |
184 | 184 |
185 #endif | 185 #endif |
OLD | NEW |