junov | da5469d | 2015-06-15 09:48:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | |
| 8 | #include "SkTypes.h" |
| 9 | |
| 10 | #if SK_SUPPORT_GPU |
| 11 | |
| 12 | #include "GrContext.h" |
junov | da5469d | 2015-06-15 09:48:15 -0700 | [diff] [blame] | 13 | #include "GrTexture.h" |
| 14 | #include "GrTexturePriv.h" |
| 15 | #include "SkCanvas.h" |
| 16 | #include "SkGr.h" |
| 17 | #include "SkSurface.h" |
| 18 | #include "Test.h" |
| 19 | |
| 20 | // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture |
| 21 | // and render targets to GrSurface all work as expected. |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 22 | DEF_GPUTEST_FOR_NULL_CONTEXT(GrTextureMipMapInvalidationTest, reporter, context) { |
| 23 | GrSurfaceDesc desc; |
| 24 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 25 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 26 | desc.fWidth = 256; |
| 27 | desc.fHeight = 256; |
| 28 | desc.fSampleCnt = 0; |
| 29 | GrSurface* texRT1 = context->textureProvider()->createTexture(desc, false, nullptr, 0); |
| 30 | GrSurface* texRT2 = context->textureProvider()->createTexture(desc, false, nullptr, 0); |
| 31 | REPORTER_ASSERT(reporter, nullptr != texRT1); |
| 32 | REPORTER_ASSERT(reporter, nullptr != texRT2); |
| 33 | GrTexture* tex = texRT1->asTexture(); |
| 34 | REPORTER_ASSERT(reporter, nullptr != tex); |
| 35 | SkBitmap bitmap; |
| 36 | GrWrapTextureInBitmap(tex, 256, 256, false, &bitmap); |
junov | da5469d | 2015-06-15 09:48:15 -0700 | [diff] [blame] | 37 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 38 | // No mipmaps initially |
| 39 | REPORTER_ASSERT(reporter, false == tex->texturePriv().hasMipMaps()); |
junov | da5469d | 2015-06-15 09:48:15 -0700 | [diff] [blame] | 40 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 41 | // Painting with downscale and medium filter quality should result in mipmap creation |
| 42 | SkSurface* surface = SkSurface::NewRenderTargetDirect(texRT2->asRenderTarget()); |
| 43 | SkPaint paint; |
| 44 | paint.setFilterQuality(kMedium_SkFilterQuality); |
| 45 | surface->getCanvas()->scale(0.2f, 0.2f); |
| 46 | surface->getCanvas()->drawBitmap(bitmap, 0, 0, &paint); |
| 47 | context->flush(); |
junov | da5469d | 2015-06-15 09:48:15 -0700 | [diff] [blame] | 48 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 49 | REPORTER_ASSERT(reporter, true == tex->texturePriv().hasMipMaps()); |
| 50 | REPORTER_ASSERT(reporter, false == tex->texturePriv().mipMapsAreDirty()); |
junov | da5469d | 2015-06-15 09:48:15 -0700 | [diff] [blame] | 51 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 52 | // Invalidating the contents of the bitmap should invalidate the mipmap, but not de-allocate |
| 53 | bitmap.notifyPixelsChanged(); |
| 54 | REPORTER_ASSERT(reporter, true == tex->texturePriv().hasMipMaps()); |
| 55 | REPORTER_ASSERT(reporter, true == tex->texturePriv().mipMapsAreDirty()); |
junov | da5469d | 2015-06-15 09:48:15 -0700 | [diff] [blame] | 56 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 57 | surface->unref(); |
| 58 | texRT1->unref(); |
| 59 | texRT2->unref(); |
junov | da5469d | 2015-06-15 09:48:15 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | #endif |