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