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