| 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" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 REPORTER_ASSERT(reporter, NULL == SkSurface::NewRaster(info)); | 96 REPORTER_ASSERT(reporter, NULL == SkSurface::NewRaster(info)); |
| 97 REPORTER_ASSERT(reporter, NULL == SkSurface::NewRasterDirect(info, NULL, 0))
; | 97 REPORTER_ASSERT(reporter, NULL == SkSurface::NewRasterDirect(info, NULL, 0))
; |
| 98 if (ctx) { | 98 if (ctx) { |
| 99 REPORTER_ASSERT(reporter, NULL == | 99 REPORTER_ASSERT(reporter, NULL == |
| 100 SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted,
info, 0, NULL)); | 100 SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted,
info, 0, NULL)); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 #if SK_SUPPORT_GPU | 104 #if SK_SUPPORT_GPU |
| 105 static void test_wrapped_texture_surface(skiatest::Reporter* reporter, GrContext
* ctx) { | 105 static void test_wrapped_surface(skiatest::Reporter* reporter, GrContext* ctx) { |
| 106 if (NULL == ctx) { | 106 if (NULL == ctx) { |
| 107 return; | 107 return; |
| 108 } | 108 } |
| 109 | 109 |
| 110 GrTestTarget tt; | 110 GrTestTarget tt; |
| 111 ctx->getTestTarget(&tt); | 111 ctx->getTestTarget(&tt); |
| 112 if (!tt.target()) { | 112 if (!tt.target()) { |
| 113 SkDEBUGFAIL("Couldn't get Gr test target."); | 113 SkDEBUGFAIL("Couldn't get Gr test target."); |
| 114 return; | 114 return; |
| 115 } | 115 } |
| 116 | 116 |
| 117 // We currently have only implemented the texture uploads for GL. | 117 // We currently have only implemented the texture uploads for GL. |
| 118 const GrGLInterface* gl = tt.glContext()->interface(); | 118 const GrGLInterface* gl = tt.glContext()->interface(); |
| 119 if (!gl) { | 119 if (!gl) { |
| 120 return; | 120 return; |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Test the wrapped factory for SkSurface by creating a texture using GL and
then wrap it in | 123 for (int useFBO = 0; useFBO < 2; ++useFBO) { |
| 124 // a SkSurface. | 124 // Test the wrapped factory for SkSurface by creating a texture using GL
and then wrap it in |
| 125 GrGLuint texID; | 125 // a SkSurface. |
| 126 static const int kW = 100; | 126 GrGLuint texID; |
| 127 static const int kH = 100; | 127 static const int kW = 100; |
| 128 static const uint32_t kOrigColor = 0xFFAABBCC; | 128 static const int kH = 100; |
| 129 SkAutoTArray<uint32_t> pixels(kW * kH); | 129 static const uint32_t kOrigColor = 0xFFAABBCC; |
| 130 sk_memset32(pixels.get(), kOrigColor, kW * kH); | 130 SkAutoTArray<uint32_t> pixels(kW * kH); |
| 131 GR_GL_CALL(gl, GenTextures(1, &texID)); | 131 sk_memset32(pixels.get(), kOrigColor, kW * kH); |
| 132 GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0)); | 132 GR_GL_CALL(gl, GenTextures(1, &texID)); |
| 133 GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); | 133 GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0)); |
| 134 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texID)); | 134 GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); |
| 135 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAG_FILTER, | 135 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texID)); |
| 136 GR_GL_NEAREST)); | 136 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAG_FILTER, |
| 137 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, | 137 GR_GL_NEAREST)); |
| 138 GR_GL_NEAREST)); | 138 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, |
| 139 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_S, | 139 GR_GL_NEAREST)); |
| 140 GR_GL_CLAMP_TO_EDGE)); | 140 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_S, |
| 141 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_T, | 141 GR_GL_CLAMP_TO_EDGE)); |
| 142 GR_GL_CLAMP_TO_EDGE)); | 142 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_T, |
| 143 GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, kW, kH, 0, GR_GL_
RGBA, | 143 GR_GL_CLAMP_TO_EDGE)); |
| 144 GR_GL_UNSIGNED_BYTE, | 144 GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, kW, kH, 0, GR
_GL_RGBA, |
| 145 pixels.get())); | 145 GR_GL_UNSIGNED_BYTE, |
| 146 pixels.get())); |
| 146 | 147 |
| 147 GrBackendTextureDesc wrappedDesc; | 148 SkAutoTUnref<SkSurface> surface; |
| 148 wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig; | 149 GrGLuint fboID = 0; |
| 149 wrappedDesc.fWidth = kW; | 150 if (useFBO) { |
| 150 wrappedDesc.fHeight = kH; | 151 GR_GL_CALL(gl, GenFramebuffers(1, &fboID)); |
| 151 wrappedDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 152 GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, fboID)); |
| 152 wrappedDesc.fSampleCnt = 0; | 153 GR_GL_CALL(gl, FramebufferTexture2D(GR_GL_FRAMEBUFFER, GR_GL_COLOR_A
TTACHMENT0, |
| 153 wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag; | 154 GR_GL_TEXTURE_2D, texID, 0)); |
| 154 wrappedDesc.fTextureHandle = texID; | 155 GrBackendRenderTargetDesc wrappedDesc; |
| 156 wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 157 wrappedDesc.fWidth = kW; |
| 158 wrappedDesc.fHeight = kH; |
| 159 wrappedDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 160 wrappedDesc.fSampleCnt = 0; |
| 161 wrappedDesc.fRenderTargetHandle = fboID; |
| 162 wrappedDesc.fStencilBits = 0; |
| 155 | 163 |
| 156 SkAutoTUnref<SkSurface> surface(SkSurface::NewWrappedRenderTarget(ctx, wrapp
edDesc, NULL)); | 164 ctx->resetContext(); |
| 157 REPORTER_ASSERT(reporter, surface); | 165 surface.reset(SkSurface::NewFromBackendRenderTarget(ctx, wrappedDesc
, NULL)); |
| 158 if (surface) { | 166 } else { |
| 159 // Validate that we can draw to the canvas and that the original texture
color is preserved | 167 GrBackendTextureDesc wrappedDesc; |
| 160 // in pixels that aren't rendered to via the surface. | 168 wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 161 SkPaint paint; | 169 wrappedDesc.fWidth = kW; |
| 162 static const SkColor kRectColor = ~kOrigColor | 0xFF000000; | 170 wrappedDesc.fHeight = kH; |
| 163 paint.setColor(kRectColor); | 171 wrappedDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 164 surface->getCanvas()->drawRect(SkRect::MakeWH(SkIntToScalar(kW), SkIntTo
Scalar(kH)/2), | 172 wrappedDesc.fSampleCnt = 0; |
| 165 paint); | 173 wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 166 SkImageInfo readInfo = SkImageInfo::MakeN32Premul(kW, kH); | 174 wrappedDesc.fTextureHandle = texID; |
| 167 surface->readPixels(readInfo, pixels.get(), kW * sizeof(uint32_t), 0, 0)
; | 175 |
| 168 bool stop = false; | 176 ctx->resetContext(); |
| 169 SkPMColor origColorPM = SkPackARGB32((kOrigColor >> 24 & 0xFF), | 177 surface.reset(SkSurface::NewFromBackendTexture(ctx, wrappedDesc, NUL
L)); |
| 170 (kOrigColor >> 0 & 0xFF), | 178 } |
| 171 (kOrigColor >> 8 & 0xFF), | 179 REPORTER_ASSERT(reporter, surface); |
| 172 (kOrigColor >> 16 & 0xFF)); | 180 if (surface) { |
| 173 SkPMColor rectColorPM = SkPackARGB32((kRectColor >> 24 & 0xFF), | 181 // Validate that we can draw to the canvas and that the original tex
ture color is |
| 174 (kRectColor >> 16 & 0xFF), | 182 // preserved in pixels that aren't rendered to via the surface. |
| 175 (kRectColor >> 8 & 0xFF), | 183 SkPaint paint; |
| 176 (kRectColor >> 0 & 0xFF)); | 184 static const SkColor kRectColor = ~kOrigColor | 0xFF000000; |
| 177 for (int y = 0; y < kH/2 && !stop; ++y) { | 185 paint.setColor(kRectColor); |
| 178 for (int x = 0; x < kW && !stop; ++x) { | 186 surface->getCanvas()->drawRect(SkRect::MakeWH(SkIntToScalar(kW), SkI
ntToScalar(kH)/2), |
| 179 REPORTER_ASSERT(reporter, rectColorPM == pixels[x + y * kW]); | 187 paint); |
| 180 if (rectColorPM != pixels[x + y * kW]) { | 188 SkImageInfo readInfo = SkImageInfo::MakeN32Premul(kW, kH); |
| 181 stop = true; | 189 surface->readPixels(readInfo, pixels.get(), kW * sizeof(uint32_t), 0
, 0); |
| 190 bool stop = false; |
| 191 SkPMColor origColorPM = SkPackARGB32((kOrigColor >> 24 & 0xFF), |
| 192 (kOrigColor >> 0 & 0xFF), |
| 193 (kOrigColor >> 8 & 0xFF), |
| 194 (kOrigColor >> 16 & 0xFF)); |
| 195 SkPMColor rectColorPM = SkPackARGB32((kRectColor >> 24 & 0xFF), |
| 196 (kRectColor >> 16 & 0xFF), |
| 197 (kRectColor >> 8 & 0xFF), |
| 198 (kRectColor >> 0 & 0xFF)); |
| 199 for (int y = 0; y < kH/2 && !stop; ++y) { |
| 200 for (int x = 0; x < kW && !stop; ++x) { |
| 201 REPORTER_ASSERT(reporter, rectColorPM == pixels[x + y * kW])
; |
| 202 if (rectColorPM != pixels[x + y * kW]) { |
| 203 stop = true; |
| 204 } |
| 205 } |
| 206 } |
| 207 stop = false; |
| 208 for (int y = kH/2; y < kH && !stop; ++y) { |
| 209 for (int x = 0; x < kW && !stop; ++x) { |
| 210 REPORTER_ASSERT(reporter, origColorPM == pixels[x + y * kW])
; |
| 211 if (origColorPM != pixels[x + y * kW]) { |
| 212 stop = true; |
| 213 } |
| 182 } | 214 } |
| 183 } | 215 } |
| 184 } | 216 } |
| 185 stop = false; | 217 if (texID) { |
| 186 for (int y = kH/2; y < kH && !stop; ++y) { | 218 GR_GL_CALL(gl, DeleteTextures(1, &texID)); |
| 187 for (int x = 0; x < kW && !stop; ++x) { | |
| 188 REPORTER_ASSERT(reporter, origColorPM == pixels[x + y * kW]); | |
| 189 if (origColorPM != pixels[x + y * kW]) { | |
| 190 stop = true; | |
| 191 } | |
| 192 } | |
| 193 } | 219 } |
| 220 if (fboID) { |
| 221 GR_GL_CALL(gl, DeleteFramebuffers(1, &fboID)); |
| 222 } |
| 223 |
| 194 } | 224 } |
| 195 } | 225 } |
| 196 #endif | 226 #endif |
| 197 | 227 |
| 198 | 228 |
| 199 static void test_image(skiatest::Reporter* reporter) { | 229 static void test_image(skiatest::Reporter* reporter) { |
| 200 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); | 230 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
| 201 size_t rowBytes = info.minRowBytes(); | 231 size_t rowBytes = info.minRowBytes(); |
| 202 size_t size = info.getSafeSize(rowBytes); | 232 size_t size = info.getSafeSize(rowBytes); |
| 203 SkData* data = SkData::NewUninitialized(size); | 233 SkData* data = SkData::NewUninitialized(size); |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy
pe, context); | 860 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy
pe, context); |
| 831 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su
rfaceType, context); | 861 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su
rfaceType, context); |
| 832 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kDiscard_ContentChangeMode); | 862 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kDiscard_ContentChangeMode); |
| 833 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kDiscard_ContentChangeMode); | 863 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kDiscard_ContentChangeMode); |
| 834 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kRetain_ContentChangeMode); | 864 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kRetain_ContentChangeMode); |
| 835 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kRetain_ContentChangeMode); | 865 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kRetain_ContentChangeMode); |
| 836 TestGetTexture(reporter, kGpu_SurfaceType, context); | 866 TestGetTexture(reporter, kGpu_SurfaceType, context); |
| 837 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); | 867 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); |
| 838 test_empty_surface(reporter, context); | 868 test_empty_surface(reporter, context); |
| 839 test_surface_budget(reporter, context); | 869 test_surface_budget(reporter, context); |
| 840 test_wrapped_texture_surface(reporter, context); | 870 test_wrapped_surface(reporter, context); |
| 841 } | 871 } |
| 842 } | 872 } |
| 843 } | 873 } |
| 844 #endif | 874 #endif |
| 845 } | 875 } |
| 846 | 876 |
| 847 #if SK_SUPPORT_GPU | 877 #if SK_SUPPORT_GPU |
| 848 | 878 |
| 849 struct ReleaseTextureContext { | 879 struct ReleaseTextureContext { |
| 850 ReleaseTextureContext(skiatest::Reporter* reporter) { | 880 ReleaseTextureContext(skiatest::Reporter* reporter) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 // We expect the ref'd image to see the new color, but cpy'd one should stil
l see the old color | 963 // We expect the ref'd image to see the new color, but cpy'd one should stil
l see the old color |
| 934 test_image_color(reporter, refImg, expected1); | 964 test_image_color(reporter, refImg, expected1); |
| 935 test_image_color(reporter, cpyImg, expected0); | 965 test_image_color(reporter, cpyImg, expected0); |
| 936 | 966 |
| 937 // Now exercise the release proc | 967 // Now exercise the release proc |
| 938 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased); | 968 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased); |
| 939 refImg.reset(NULL); // force a release of the image | 969 refImg.reset(NULL); // force a release of the image |
| 940 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased); | 970 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased); |
| 941 } | 971 } |
| 942 #endif | 972 #endif |
| OLD | NEW |