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 "GrContext.h" | 10 #include "GrContext.h" |
11 #include "Resources.h" | 11 #include "Resources.h" |
12 #include "SkImage.h" | 12 #include "SkImage.h" |
13 | 13 |
14 #if SK_SUPPORT_GPU | 14 #if SK_SUPPORT_GPU |
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 bool DrawDeferredTextureImageData(GrContext* context, SkCanvas* canvas, S
kImage* image, | 18 static bool DrawDeferredTextureImageData(GrContext* context, SkCanvas* canvas, S
kImage* image, |
19 SkImage::DeferredTextureImageUsageParam
s* params, | 19 SkImage::DeferredTextureImageUsageParam
s* params, |
20 SkScalar x, SkScalar y) { | 20 SkScalar x, SkScalar y) { |
21 size_t deferredSize = | 21 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy()); |
22 image->getDeferredTextureImageData(*context->threadSafeProxy(), params, 1,
nullptr); | 22 size_t deferredSize = image->getDeferredTextureImageData(*proxy, params, 1,
nullptr); |
23 if (deferredSize == 0) { | 23 if (deferredSize == 0) { |
24 SkDebugf("\nCould not create DeferredTextureImageData.\n"); | 24 SkDebugf("\nCould not create DeferredTextureImageData.\n"); |
25 return false; | 25 return false; |
26 } | 26 } |
27 | 27 |
28 std::vector<uint8_t> memory; | 28 std::vector<uint8_t> memory; |
29 memory.resize(deferredSize); | 29 memory.resize(deferredSize); |
30 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy()); | 30 image->getDeferredTextureImageData(*proxy, params, 1, memory.data()); |
31 image->getDeferredTextureImageData(*proxy, params, 1, memory.data()); | 31 sk_sp<SkImage> uploadedImage = |
32 sk_sp<SkImage> uploadedImage = | 32 SkImage::MakeFromDeferredTextureImageData(context, memory.data(), SkBudg
eted::kNo); |
33 SkImage::MakeFromDeferredTextureImageData(context, memory.data(), SkBudget
ed::kNo); | 33 canvas->drawImage(uploadedImage, x, y); |
34 canvas->drawImage(uploadedImage, x, y); | |
35 | 34 |
36 return true; | 35 return true; |
37 } | 36 } |
38 | 37 |
39 DEF_SIMPLE_GM(deferred_texture_image_data, canvas, 60, 10) { | 38 DEF_SIMPLE_GM(deferred_texture_image_data, canvas, 60, 10) { |
40 GrContext* context = canvas->getGrContext(); | 39 GrContext* context = canvas->getGrContext(); |
41 if (!context) { | 40 if (!context) { |
42 skiagm::GM::DrawGpuOnlyMessage(canvas); | 41 skiagm::GM::DrawGpuOnlyMessage(canvas); |
43 return; | 42 return; |
44 } | 43 } |
(...skipping 28 matching lines...) Expand all Loading... |
73 // Draw 50% scaled versions of the encoded and decoded images at none qualit
y. | 72 // Draw 50% scaled versions of the encoded and decoded images at none qualit
y. |
74 SkImage::DeferredTextureImageUsageParams noneScaledParams; | 73 SkImage::DeferredTextureImageUsageParams noneScaledParams; |
75 noneScaledParams.fPreScaleMipLevel = 1; | 74 noneScaledParams.fPreScaleMipLevel = 1; |
76 noneScaledParams.fQuality = kNone_SkFilterQuality; | 75 noneScaledParams.fQuality = kNone_SkFilterQuality; |
77 | 76 |
78 DrawDeferredTextureImageData(context, canvas, encodedImage.get(), &noneScale
dParams, 40, 0); | 77 DrawDeferredTextureImageData(context, canvas, encodedImage.get(), &noneScale
dParams, 40, 0); |
79 DrawDeferredTextureImageData(context, canvas, decodedImage.get(), &noneScale
dParams, 50, 0); | 78 DrawDeferredTextureImageData(context, canvas, decodedImage.get(), &noneScale
dParams, 50, 0); |
80 } | 79 } |
81 | 80 |
82 #endif | 81 #endif |
OLD | NEW |