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 "GrGpu.h" 14 #include "GrRenderTarget.h" 15 #include "GrTexture.h" 16 #include "GrSurfacePriv.h" 17 #include "Test.h" 18 19 // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture 20 // and render targets to GrSurface all work as expected. 21 DEF_GPUTEST_FOR_NULL_CONTEXT(GrSurface, reporter, context) { 22 GrSurfaceDesc desc; 23 desc.fConfig = kSkia8888_GrPixelConfig; 24 desc.fFlags = kRenderTarget_GrSurfaceFlag; 25 desc.fWidth = 256; 26 desc.fHeight = 256; 27 desc.fSampleCnt = 0; 28 GrSurface* texRT1 = context->textureProvider()->createTexture( 29 desc, SkBudgeted::kNo, nullptr, 0); 30 31 REPORTER_ASSERT(reporter, texRT1 == texRT1->asRenderTarget()); 32 REPORTER_ASSERT(reporter, texRT1 == texRT1->asTexture()); 33 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) == 34 texRT1->asTexture()); 35 REPORTER_ASSERT(reporter, texRT1->asRenderTarget() == 36 static_cast<GrSurface*>(texRT1->asTexture())); 37 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) == 38 static_cast<GrSurface*>(texRT1->asTexture())); 39 40 desc.fFlags = kNone_GrSurfaceFlags; 41 GrSurface* tex1 = context->textureProvider()->createTexture(desc, SkBudgeted::kNo, nullptr, 0); 42 REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget()); 43 REPORTER_ASSERT(reporter, tex1 == tex1->asTexture()); 44 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1) == tex1->asTexture()); 45 46 GrBackendObject backendTex = context->getGpu()->createTestingOnlyBackendTexture( 47 nullptr, 256, 256, kSkia8888_GrPixelConfig); 48 49 GrBackendTextureDesc backendDesc; 50 backendDesc.fConfig = kSkia8888_GrPixelConfig; 51 backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag; 52 backendDesc.fWidth = 256; 53 backendDesc.fHeight = 256; 54 backendDesc.fSampleCnt = 0; 55 backendDesc.fTextureHandle = backendTex; 56 GrSurface* texRT2 = context->textureProvider()->wrapBackendTexture( 57 backendDesc, kBorrow_GrWrapOwnership); 58 REPORTER_ASSERT(reporter, texRT2 == texRT2->asRenderTarget()); 59 REPORTER_ASSERT(reporter, texRT2 == texRT2->asTexture()); 60 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) == 61 texRT2->asTexture()); 62 REPORTER_ASSERT(reporter, texRT2->asRenderTarget() == 63 static_cast<GrSurface*>(texRT2->asTexture())); 64 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) == 65 static_cast<GrSurface*>(texRT2->asTexture())); 66 67 texRT1->unref(); 68 texRT2->unref(); 69 tex1->unref(); 70 context->getGpu()->deleteTestingOnlyBackendTexture(backendTex); 71 } 72 73 #endif 74