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

Side by Side Diff: gm/deferredtextureimage.cpp

Issue 2083393002: Revert of Store mipmap levels in deferred texture image (Closed) Base URL: https://skia.googlesource.com/skia.git@pipe-mipmap-levels-to-creation
Patch Set: Created 4 years, 6 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 | « no previous file | 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 "SkMipMap.h"
12 #include "Resources.h"
13
14 #if SK_SUPPORT_GPU
15
16 class DeferredTextureImage_Medium : public skiagm::GM {
17 protected:
18 SkString onShortName() override {
19 return SkString("deferredtextureimage_medium");
20 }
21
22 SkISize onISize() override {
23 return SkISize::Make(512 + 512 + 30, 1110);
24 }
25
26 void onDraw(SkCanvas* canvas) override {
27 GrContext* context = canvas->getGrContext();
28 if (!context) {
29 skiagm::GM::DrawGpuOnlyMessage(canvas);
30 return;
31 }
32
33 SkPaint paint;
34 paint.setFilterQuality(kMedium_SkFilterQuality);
35
36 int mipLevelCount = SkMipMap::ComputeLevelCount(512, 512);
37
38 // create the deferred texture image
39 SkImage::DeferredTextureImageUsageParams params[1];
40 // These should cause mipmaps to be generated
41 params[0].fMatrix = SkMatrix::MakeScale(0.25f, 0.25f);
42 params[0].fQuality = kMedium_SkFilterQuality;
43 size_t requiredMemoryInBytes = fDecodedImage->getDeferredTextureImageDat a(
44 *context->threadSafeProxy(), params, 1, nullptr, SkSourceGammaTreatm ent::kRespect);
45 if (requiredMemoryInBytes == 0) {
46 SkDebugf("\nCould not create DeferredTextureImageData.\n");
47 return;
48 }
49
50 std::vector<uint8_t> memory;
51 memory.resize(requiredMemoryInBytes);
52 fDecodedImage->getDeferredTextureImageData(
53 *context->threadSafeProxy(), params, 1, memory.data(),
54 SkSourceGammaTreatment::kRespect);
55 sk_sp<SkImage> uploadedImage = SkImage::MakeFromDeferredTextureImageData (
56 context, memory.data(), SkBudgeted::kNo);
57
58 // draw a column using deferred texture images
59 SkScalar offsetHeight = 10.f;
60 // handle base mipmap level
61 canvas->save();
62 canvas->translate(10.f, offsetHeight);
63 canvas->drawImage(uploadedImage, 0, 0, &paint);
64 canvas->restore();
65 offsetHeight += 512 + 10;
66 // handle generated mipmap levels
67 for (int i = 0; i < mipLevelCount; i++) {
68 SkISize mipSize = SkMipMap::ComputeLevelSize(512, 512, i);
69 canvas->save();
70 canvas->translate(10.f, offsetHeight);
71 canvas->scale(mipSize.width() / 512.f, mipSize.height() / 512.f);
72 canvas->drawImage(uploadedImage, 0, 0, &paint);
73 canvas->restore();
74 offsetHeight += mipSize.height() + 10;
75 }
76
77 // draw a column using SkImage
78 offsetHeight = 10;
79 // handle base mipmap level
80 canvas->save();
81 canvas->translate(512.f + 20.f, offsetHeight);
82 canvas->drawImage(fDecodedImage, 0, 0, &paint);
83 canvas->restore();
84 offsetHeight += 512 + 10;
85 // handle generated mipmap levels
86 for (int i = 0; i < mipLevelCount; i++) {
87 SkISize mipSize = SkMipMap::ComputeLevelSize(512, 512, i);
88 canvas->save();
89 canvas->translate(512.f + 20.f, offsetHeight);
90 canvas->scale(mipSize.width() / 512.f, mipSize.height() / 512.f);
91 canvas->drawImage(fDecodedImage, 0, 0, &paint);
92 canvas->restore();
93 offsetHeight += mipSize.height() + 10;
94 }
95 }
96
97 private:
98
99 void onOnceBeforeDraw() override {
100 SkBitmap bitmap;
101 if (!GetResourceAsBitmap("mandrill_512.png", &bitmap)) {
102 bitmap.allocN32Pixels(1, 1);
103 bitmap.eraseARGB(255, 255, 0, 0); // red == bad
104 }
105 fDecodedImage = SkImage::MakeFromBitmap(bitmap);
106 }
107
108 sk_sp<SkImage> fDecodedImage;
109
110 typedef skiagm::GM INHERITED;
111 };
112
113 //////////////////////////////////////////////////////////////////////////////
114
115 DEF_GM( return new DeferredTextureImage_Medium; )
116
117 #endif
OLDNEW
« no previous file with comments | « no previous file | include/core/SkImage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698