| 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkData.h" | 9 #include "SkData.h" |
| 10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
| 11 #include "SkImageEncoder.h" | 11 #include "SkImageEncoder.h" |
| 12 #include "SkImage_Base.h" | 12 #include "SkImage_Base.h" |
| 13 #include "SkRRect.h" | 13 #include "SkRRect.h" |
| 14 #include "SkSurface.h" | 14 #include "SkSurface.h" |
| 15 #include "SkUtils.h" | 15 #include "SkUtils.h" |
| 16 #include "Test.h" | 16 #include "Test.h" |
| 17 | 17 |
| 18 #if SK_SUPPORT_GPU | 18 #if SK_SUPPORT_GPU |
| 19 #include "GrContextFactory.h" | 19 #include "GrContextFactory.h" |
| 20 #include "GrTest.h" | 20 #include "GrTest.h" |
| 21 #include "gl/GrGLInterface.h" | |
| 22 #include "gl/GrGLUtil.h" | |
| 23 #else | 21 #else |
| 24 class GrContextFactory; | 22 class GrContextFactory; |
| 25 class GrContext; | 23 class GrContext; |
| 26 #endif | 24 #endif |
| 27 | 25 |
| 28 enum SurfaceType { | 26 enum SurfaceType { |
| 29 kRaster_SurfaceType, | 27 kRaster_SurfaceType, |
| 30 kRasterDirect_SurfaceType, | 28 kRasterDirect_SurfaceType, |
| 31 kGpu_SurfaceType, | 29 kGpu_SurfaceType, |
| 32 kGpuScratch_SurfaceType, | 30 kGpuScratch_SurfaceType, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted,
info, 0, NULL)); | 98 SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted,
info, 0, NULL)); |
| 101 } | 99 } |
| 102 } | 100 } |
| 103 | 101 |
| 104 #if SK_SUPPORT_GPU | 102 #if SK_SUPPORT_GPU |
| 105 static void test_wrapped_texture_surface(skiatest::Reporter* reporter, GrContext
* ctx) { | 103 static void test_wrapped_texture_surface(skiatest::Reporter* reporter, GrContext
* ctx) { |
| 106 if (NULL == ctx) { | 104 if (NULL == ctx) { |
| 107 return; | 105 return; |
| 108 } | 106 } |
| 109 | 107 |
| 110 GrTestTarget tt; | 108 const GrGpu* gpu = ctx->getGpu(); |
| 111 ctx->getTestTarget(&tt); | 109 if (!gpu) { |
| 112 if (!tt.target()) { | |
| 113 SkDEBUGFAIL("Couldn't get Gr test target."); | |
| 114 return; | 110 return; |
| 115 } | 111 } |
| 116 | 112 |
| 117 // We currently have only implemented the texture uploads for GL. | 113 // Test the wrapped factory for SkSurface by creating a backend texture and
then wrap it in |
| 118 const GrGLInterface* gl = tt.glContext()->interface(); | |
| 119 if (!gl) { | |
| 120 return; | |
| 121 } | |
| 122 | |
| 123 // Test the wrapped factory for SkSurface by creating a texture using GL and
then wrap it in | |
| 124 // a SkSurface. | 114 // a SkSurface. |
| 125 GrGLuint texID; | |
| 126 static const int kW = 100; | 115 static const int kW = 100; |
| 127 static const int kH = 100; | 116 static const int kH = 100; |
| 128 static const uint32_t kOrigColor = 0xFFAABBCC; | 117 static const uint32_t kOrigColor = 0xFFAABBCC; |
| 129 SkAutoTArray<uint32_t> pixels(kW * kH); | 118 SkAutoTArray<uint32_t> pixels(kW * kH); |
| 130 sk_memset32(pixels.get(), kOrigColor, kW * kH); | 119 sk_memset32(pixels.get(), kOrigColor, kW * kH); |
| 131 GR_GL_CALL(gl, GenTextures(1, &texID)); | 120 GrBackendObject texID = gpu->createBackendTexture(pixels.get(), kW, kH, |
| 132 GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0)); | 121 kRGBA_8888_GrPixelConfig); |
| 133 GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); | |
| 134 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texID)); | |
| 135 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAG_FILTER, | |
| 136 GR_GL_NEAREST)); | |
| 137 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, | |
| 138 GR_GL_NEAREST)); | |
| 139 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_S, | |
| 140 GR_GL_CLAMP_TO_EDGE)); | |
| 141 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_T, | |
| 142 GR_GL_CLAMP_TO_EDGE)); | |
| 143 GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, kW, kH, 0, GR_GL_
RGBA, | |
| 144 GR_GL_UNSIGNED_BYTE, | |
| 145 pixels.get())); | |
| 146 | 122 |
| 147 GrBackendTextureDesc wrappedDesc; | 123 GrBackendTextureDesc wrappedDesc; |
| 148 wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig; | 124 wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 149 wrappedDesc.fWidth = kW; | 125 wrappedDesc.fWidth = kW; |
| 150 wrappedDesc.fHeight = kH; | 126 wrappedDesc.fHeight = kH; |
| 151 wrappedDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 127 wrappedDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 152 wrappedDesc.fSampleCnt = 0; | 128 wrappedDesc.fSampleCnt = 0; |
| 153 wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag; | 129 wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 154 wrappedDesc.fTextureHandle = texID; | 130 wrappedDesc.fTextureHandle = texID; |
| 155 | 131 |
| (...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 // We expect the ref'd image to see the new color, but cpy'd one should stil
l see the old color | 982 // We expect the ref'd image to see the new color, but cpy'd one should stil
l see the old color |
| 1007 test_image_color(reporter, refImg, expected1); | 983 test_image_color(reporter, refImg, expected1); |
| 1008 test_image_color(reporter, cpyImg, expected0); | 984 test_image_color(reporter, cpyImg, expected0); |
| 1009 | 985 |
| 1010 // Now exercise the release proc | 986 // Now exercise the release proc |
| 1011 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased); | 987 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased); |
| 1012 refImg.reset(NULL); // force a release of the image | 988 refImg.reset(NULL); // force a release of the image |
| 1013 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased); | 989 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased); |
| 1014 } | 990 } |
| 1015 #endif | 991 #endif |
| OLD | NEW |