Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: gm/deferredtextureimagedata.cpp

Issue 2242883004: Store mipmap levels in deferred texture image (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixing opening brace location. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gm/deferredtextureimage.cpp ('k') | include/core/SkImage.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include <vector>
8
9 #include "gm.h"
10 #include "GrContext.h"
11 #include "Resources.h"
12 #include "SkImage.h"
13
14 #if SK_SUPPORT_GPU
15
16 // Helper function that uploads the given SkImage using MakdeFromDeferredTexture ImageData and then
17 // draws the uploaded version at the specified coordinates.
18 static bool DrawDeferredTextureImageData(GrContext* context, SkCanvas* canvas, S kImage* image,
19 SkImage::DeferredTextureImageUsageParam s* params,
20 SkScalar x, SkScalar y) {
21 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy());
22 size_t deferredSize = image->getDeferredTextureImageData(*proxy, params, 1, nullptr);
23 if (deferredSize == 0) {
24 SkDebugf("\nCould not create DeferredTextureImageData.\n");
25 return false;
26 }
27
28 std::vector<uint8_t> memory;
29 memory.resize(deferredSize);
30 image->getDeferredTextureImageData(*proxy, params, 1, memory.data());
31 sk_sp<SkImage> uploadedImage =
32 SkImage::MakeFromDeferredTextureImageData(context, memory.data(), SkBudg eted::kNo);
33 canvas->drawImage(uploadedImage, x, y);
34
35 return true;
36 }
37
38 DEF_SIMPLE_GM(deferred_texture_image_data, canvas, 60, 10) {
39 GrContext* context = canvas->getGrContext();
40 if (!context) {
41 skiagm::GM::DrawGpuOnlyMessage(canvas);
42 return;
43 }
44
45 sk_sp<SkImage> encodedImage = GetResourceAsImage("randPixels.png");
46 if (!encodedImage) {
47 SkDebugf("\nCould not load resource.\n");
48 return;
49 }
50
51 SkBitmap bitmap;
52 if (!GetResourceAsBitmap("randPixels.png", &bitmap)) {
53 SkDebugf("\nCould not decode resource.\n");
54 return;
55 }
56
57 sk_sp<SkImage> decodedImage = SkImage::MakeFromBitmap(bitmap);
58
59 // Draw both encoded and decoded image via deferredTextureImageData.
60 SkImage::DeferredTextureImageUsageParams params;
61 DrawDeferredTextureImageData(context, canvas, encodedImage.get(), &params, 0 , 0);
62 DrawDeferredTextureImageData(context, canvas, decodedImage.get(), &params, 1 0, 0);
63
64 // Draw 50% scaled versions of the encoded and decoded images at medium qual ity.
65 SkImage::DeferredTextureImageUsageParams mediumScaledParams;
66 mediumScaledParams.fPreScaleMipLevel = 1;
67 mediumScaledParams.fQuality = kMedium_SkFilterQuality;
68
69 DrawDeferredTextureImageData(context, canvas, encodedImage.get(), &mediumSca ledParams, 20, 0);
70 DrawDeferredTextureImageData(context, canvas, decodedImage.get(), &mediumSca ledParams, 30, 0);
71
72 // Draw 50% scaled versions of the encoded and decoded images at none qualit y.
73 SkImage::DeferredTextureImageUsageParams noneScaledParams;
74 noneScaledParams.fPreScaleMipLevel = 1;
75 noneScaledParams.fQuality = kNone_SkFilterQuality;
76
77 DrawDeferredTextureImageData(context, canvas, encodedImage.get(), &noneScale dParams, 40, 0);
78 DrawDeferredTextureImageData(context, canvas, decodedImage.get(), &noneScale dParams, 50, 0);
79 }
80
81 #endif
OLDNEW
« no previous file with comments | « gm/deferredtextureimage.cpp ('k') | include/core/SkImage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698