OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrContextFactory.h" | |
14 #include "GrTexture.h" | 13 #include "GrTexture.h" |
15 #include "GrTexturePriv.h" | 14 #include "GrTexturePriv.h" |
16 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
17 #include "SkGr.h" | 16 #include "SkGr.h" |
18 #include "SkSurface.h" | 17 #include "SkSurface.h" |
19 #include "Test.h" | 18 #include "Test.h" |
20 | 19 |
21 // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static up
casting of texture | 20 // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static up
casting of texture |
22 // and render targets to GrSurface all work as expected. | 21 // and render targets to GrSurface all work as expected. |
23 DEF_GPUTEST(GrTextureMipMapInvalidationTest, reporter, factory) { | 22 DEF_GPUTEST_FOR_NULL_CONTEXT(GrTextureMipMapInvalidationTest, reporter, context)
{ |
24 GrContext* context = factory->get(GrContextFactory::kNull_GLContextType); | 23 GrSurfaceDesc desc; |
25 if (context) { | 24 desc.fConfig = kSkia8888_GrPixelConfig; |
26 GrSurfaceDesc desc; | 25 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
27 desc.fConfig = kSkia8888_GrPixelConfig; | 26 desc.fWidth = 256; |
28 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 27 desc.fHeight = 256; |
29 desc.fWidth = 256; | 28 desc.fSampleCnt = 0; |
30 desc.fHeight = 256; | 29 GrSurface* texRT1 = context->textureProvider()->createTexture(desc, false, n
ullptr, 0); |
31 desc.fSampleCnt = 0; | 30 GrSurface* texRT2 = context->textureProvider()->createTexture(desc, false, n
ullptr, 0); |
32 GrSurface* texRT1 = context->textureProvider()->createTexture(desc, fals
e, nullptr, 0); | 31 REPORTER_ASSERT(reporter, nullptr != texRT1); |
33 GrSurface* texRT2 = context->textureProvider()->createTexture(desc, fals
e, nullptr, 0); | 32 REPORTER_ASSERT(reporter, nullptr != texRT2); |
34 REPORTER_ASSERT(reporter, nullptr != texRT1); | 33 GrTexture* tex = texRT1->asTexture(); |
35 REPORTER_ASSERT(reporter, nullptr != texRT2); | 34 REPORTER_ASSERT(reporter, nullptr != tex); |
36 GrTexture* tex = texRT1->asTexture(); | 35 SkBitmap bitmap; |
37 REPORTER_ASSERT(reporter, nullptr != tex); | 36 GrWrapTextureInBitmap(tex, 256, 256, false, &bitmap); |
38 SkBitmap bitmap; | |
39 GrWrapTextureInBitmap(tex, 256, 256, false, &bitmap); | |
40 | 37 |
41 // No mipmaps initially | 38 // No mipmaps initially |
42 REPORTER_ASSERT(reporter, false == tex->texturePriv().hasMipMaps()); | 39 REPORTER_ASSERT(reporter, false == tex->texturePriv().hasMipMaps()); |
43 | 40 |
44 // Painting with downscale and medium filter quality should result in mi
pmap creation | 41 // Painting with downscale and medium filter quality should result in mipmap
creation |
45 SkSurface* surface = SkSurface::NewRenderTargetDirect(texRT2->asRenderTa
rget()); | 42 SkSurface* surface = SkSurface::NewRenderTargetDirect(texRT2->asRenderTarget
()); |
46 SkPaint paint; | 43 SkPaint paint; |
47 paint.setFilterQuality(kMedium_SkFilterQuality); | 44 paint.setFilterQuality(kMedium_SkFilterQuality); |
48 surface->getCanvas()->scale(0.2f, 0.2f); | 45 surface->getCanvas()->scale(0.2f, 0.2f); |
49 surface->getCanvas()->drawBitmap(bitmap, 0, 0, &paint); | 46 surface->getCanvas()->drawBitmap(bitmap, 0, 0, &paint); |
50 context->flush(); | 47 context->flush(); |
51 | 48 |
52 REPORTER_ASSERT(reporter, true == tex->texturePriv().hasMipMaps()); | 49 REPORTER_ASSERT(reporter, true == tex->texturePriv().hasMipMaps()); |
53 REPORTER_ASSERT(reporter, false == tex->texturePriv().mipMapsAreDirty())
; | 50 REPORTER_ASSERT(reporter, false == tex->texturePriv().mipMapsAreDirty()); |
54 | 51 |
55 // Invalidating the contents of the bitmap should invalidate the mipmap,
but not de-allocate | 52 // Invalidating the contents of the bitmap should invalidate the mipmap, but
not de-allocate |
56 bitmap.notifyPixelsChanged(); | 53 bitmap.notifyPixelsChanged(); |
57 REPORTER_ASSERT(reporter, true == tex->texturePriv().hasMipMaps()); | 54 REPORTER_ASSERT(reporter, true == tex->texturePriv().hasMipMaps()); |
58 REPORTER_ASSERT(reporter, true == tex->texturePriv().mipMapsAreDirty()); | 55 REPORTER_ASSERT(reporter, true == tex->texturePriv().mipMapsAreDirty()); |
59 | 56 |
60 surface->unref(); | 57 surface->unref(); |
61 texRT1->unref(); | 58 texRT1->unref(); |
62 texRT2->unref(); | 59 texRT2->unref(); |
63 } | |
64 } | 60 } |
65 | 61 |
66 #endif | 62 #endif |
OLD | NEW |