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

Side by Side Diff: tests/GrTextureMipMapInvalidationTest.cpp

Issue 2149133002: Rewrite GrTextureMipMapInvalidationTest using SkImage (Closed) Base URL: https://chromium.googlesource.com/skia.git@rm_skgr_texture_pr
Patch Set: Created 4 years, 5 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 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 "SkTypes.h" 8 #include "SkTypes.h"
9 9
10 #if SK_SUPPORT_GPU 10 #if SK_SUPPORT_GPU
11 11
12 #include "GrContext.h" 12 #include "GrContext.h"
13 #include "GrTexture.h" 13 #include "GrTexture.h"
14 #include "GrTexturePriv.h" 14 #include "GrTexturePriv.h"
15 #include "SkCanvas.h" 15 #include "SkCanvas.h"
16 #include "SkGrPriv.h" 16 #include "SkImage_Base.h"
17 #include "SkSurface.h" 17 #include "SkSurface.h"
18 #include "Test.h" 18 #include "Test.h"
19 19
20 // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static up casting of texture 20 // Tests that MIP maps are created and invalidated as expected when drawing to a nd from GrTextures.
21 // and render targets to GrSurface all work as expected.
22 DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrTextureMipMapInvalidationTest, reporter, ctxInf o) { 21 DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrTextureMipMapInvalidationTest, reporter, ctxInf o) {
22 auto isMipped = [] (SkSurface* surf) {
23 return as_IB(surf->makeImageSnapshot(SkBudgeted::kYes))->
24 peekTexture()->texturePriv().hasMipMaps();
25 };
26
27 auto mipsAreDirty = [] (SkSurface* surf) {
28 return as_IB(surf->makeImageSnapshot(SkBudgeted::kYes))->
29 peekTexture()->texturePriv().mipMapsAreDirty();
30 };
31
23 GrContext* context = ctxInfo.grContext(); 32 GrContext* context = ctxInfo.grContext();
24 GrSurfaceDesc desc; 33 auto info = SkImageInfo::MakeN32Premul(256, 256);
25 desc.fConfig = kSkia8888_GrPixelConfig; 34 auto surf1 = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info);
26 desc.fFlags = kRenderTarget_GrSurfaceFlag; 35 auto surf2 = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info);
27 desc.fWidth = 256; 36 // Draw something just in case we ever had a solid color optimization
28 desc.fHeight = 256; 37 surf1->getCanvas()->drawCircle(128, 128, 50, SkPaint());
29 desc.fSampleCnt = 0; 38 surf1->getCanvas()->flush();
30 GrSurface* texRT1 = context->textureProvider()->createTexture(
31 desc, SkBudgeted::kNo, nullptr, 0);
32 GrSurface* texRT2 = context->textureProvider()->createTexture(
33 desc, SkBudgeted::kNo, nullptr, 0);
34 REPORTER_ASSERT(reporter, nullptr != texRT1);
35 REPORTER_ASSERT(reporter, nullptr != texRT2);
36 GrTexture* tex = texRT1->asTexture();
37 REPORTER_ASSERT(reporter, nullptr != tex);
38 SkBitmap bitmap;
39 GrWrapTextureInBitmap(tex, 256, 256, false, &bitmap);
40 39
41 // No mipmaps initially 40 // No mipmaps initially
42 REPORTER_ASSERT(reporter, false == tex->texturePriv().hasMipMaps()); 41 REPORTER_ASSERT(reporter, !isMipped(surf1.get()));
43 42
44 // Painting with downscale and medium filter quality should result in mipmap creation 43 // Painting with downscale and medium filter quality should result in mipmap creation
45 auto surface = SkSurface::MakeRenderTargetDirect(texRT2->asRenderTarget());
46 SkPaint paint; 44 SkPaint paint;
47 paint.setFilterQuality(kMedium_SkFilterQuality); 45 paint.setFilterQuality(kMedium_SkFilterQuality);
48 surface->getCanvas()->scale(0.2f, 0.2f); 46 surf2->getCanvas()->scale(0.2f, 0.2f);
49 surface->getCanvas()->drawBitmap(bitmap, 0, 0, &paint); 47 surf2->getCanvas()->drawImage(surf1->makeImageSnapshot(SkBudgeted::kYes), 0, 0, &paint);
50 context->flush(); 48 surf2->getCanvas()->flush();
49 REPORTER_ASSERT(reporter, isMipped(surf1.get()));
50 REPORTER_ASSERT(reporter, !mipsAreDirty(surf1.get()));
51 51
52 REPORTER_ASSERT(reporter, true == tex->texturePriv().hasMipMaps()); 52 // Changing the contents of the surface should invalidate the mipmap, but no t de-allocate
53 REPORTER_ASSERT(reporter, false == tex->texturePriv().mipMapsAreDirty()); 53 surf1->getCanvas()->drawCircle(128, 128, 100, SkPaint());
54 54 surf1->getCanvas()->flush();
55 // Invalidating the contents of the bitmap should invalidate the mipmap, but not de-allocate 55 REPORTER_ASSERT(reporter, isMipped(surf1.get()));
56 bitmap.notifyPixelsChanged(); 56 REPORTER_ASSERT(reporter, mipsAreDirty(surf1.get()));
57 REPORTER_ASSERT(reporter, true == tex->texturePriv().hasMipMaps());
58 REPORTER_ASSERT(reporter, true == tex->texturePriv().mipMapsAreDirty());
59
60 texRT1->unref();
61 texRT2->unref();
62 } 57 }
63 58
64 #endif 59 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698