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