Chromium Code Reviews| 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 #else | 20 #include "GrTest.h" |
| 21 #include "gl/GrGLInterface.h" | |
| 22 #include "gl/GrGLUtil.h"#else | |
|
reed1
2015/06/15 16:09:26
LF before #else ?
| |
| 21 class GrContextFactory; | 23 class GrContextFactory; |
| 22 class GrContext; | 24 class GrContext; |
| 23 #endif | 25 #endif |
| 24 | 26 |
| 25 enum SurfaceType { | 27 enum SurfaceType { |
| 26 kRaster_SurfaceType, | 28 kRaster_SurfaceType, |
| 27 kRasterDirect_SurfaceType, | 29 kRasterDirect_SurfaceType, |
| 28 kGpu_SurfaceType, | 30 kGpu_SurfaceType, |
| 29 kGpuScratch_SurfaceType, | 31 kGpuScratch_SurfaceType, |
| 30 }; | 32 }; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 REPORTER_ASSERT(reporter, NULL == | 92 REPORTER_ASSERT(reporter, NULL == |
| 91 SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted, info, 0, NULL)); | 93 SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted, info, 0, NULL)); |
| 92 } | 94 } |
| 93 } | 95 } |
| 94 | 96 |
| 95 #if SK_SUPPORT_GPU | 97 #if SK_SUPPORT_GPU |
| 96 static void test_wrapped_texture_surface(skiatest::Reporter* reporter, GrContext * ctx) { | 98 static void test_wrapped_texture_surface(skiatest::Reporter* reporter, GrContext * ctx) { |
| 97 if (NULL == ctx) { | 99 if (NULL == ctx) { |
| 98 return; | 100 return; |
| 99 } | 101 } |
| 100 // Test the wrapped factory for SkSurface by creating a texture using ctx an d then treat it as | |
| 101 // an external texture and wrap it in a SkSurface. | |
| 102 | 102 |
| 103 GrSurfaceDesc texDesc; | 103 GrTestTarget tt; |
| 104 texDesc.fConfig = kRGBA_8888_GrPixelConfig; | 104 ctx->getTestTarget(&tt); |
| 105 texDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 105 if (!tt.target()) { |
| 106 texDesc.fWidth = texDesc.fHeight = 100; | 106 SkDEBUGFAIL("Couldn't get Gr test target."); |
| 107 texDesc.fSampleCnt = 0; | |
| 108 texDesc.fOrigin = kTopLeft_GrSurfaceOrigin; | |
| 109 SkAutoTUnref<GrSurface> dummySurface(ctx->textureProvider()->createTexture(t exDesc, false)); | |
| 110 | |
| 111 REPORTER_ASSERT(reporter, dummySurface && dummySurface->asTexture() && | |
| 112 dummySurface->asRenderTarget()); | |
| 113 if (!dummySurface || !dummySurface->asTexture() || !dummySurface->asRenderTa rget()) { | |
| 114 return; | 107 return; |
| 115 } | 108 } |
| 116 | 109 |
| 117 GrBackendObject textureHandle = dummySurface->asTexture()->getTextureHandle( ); | 110 // We currently have only implemented the texture uploads for GL. |
| 111 const GrGLInterface* gl = tt.glInterface(); | |
| 112 if (!gl) { | |
| 113 return; | |
| 114 } | |
| 115 | |
| 116 // Test the wrapped factory for SkSurface by creating a texture using GL and then wrap it in | |
| 117 // a SkSurface. | |
| 118 GrGLuint texID; | |
| 119 static const int kW = 100; | |
| 120 static const int kH = 100; | |
| 121 static const uint32_t kOrigColor = 0xFFAABBCC; | |
| 122 SkAutoTArray<uint32_t> pixels(kW * kH); | |
| 123 sk_memset32(pixels.get(), kOrigColor, kW * kH); | |
| 124 GR_GL_CALL(gl, GenTextures(1, &texID)); | |
| 125 GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0)); | |
| 126 GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); | |
| 127 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texID)); | |
| 128 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAG_FILTER, | |
| 129 GR_GL_NEAREST)); | |
| 130 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, | |
| 131 GR_GL_NEAREST)); | |
| 132 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_S, | |
| 133 GR_GL_CLAMP_TO_EDGE)); | |
| 134 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_T, | |
| 135 GR_GL_CLAMP_TO_EDGE)); | |
| 136 GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, kW, kH, 0, GR_GL_ RGBA, | |
| 137 GR_GL_UNSIGNED_BYTE, | |
| 138 pixels.get())); | |
| 118 | 139 |
| 119 GrBackendTextureDesc wrappedDesc; | 140 GrBackendTextureDesc wrappedDesc; |
| 120 wrappedDesc.fConfig = dummySurface->config(); | 141 wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 121 wrappedDesc.fWidth = dummySurface->width(); | 142 wrappedDesc.fWidth = kW; |
| 122 wrappedDesc.fHeight = dummySurface->height(); | 143 wrappedDesc.fHeight = kH; |
| 123 wrappedDesc.fOrigin = dummySurface->origin(); | 144 wrappedDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 124 wrappedDesc.fSampleCnt = dummySurface->asRenderTarget()->numColorSamples(); | 145 wrappedDesc.fSampleCnt = 0; |
| 125 wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag; | 146 wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 126 wrappedDesc.fTextureHandle = textureHandle; | 147 wrappedDesc.fTextureHandle = texID; |
| 127 | 148 |
| 128 SkAutoTUnref<SkSurface> surface(SkSurface::NewWrappedRenderTarget(ctx, wrapp edDesc, NULL)); | 149 SkAutoTUnref<SkSurface> surface(SkSurface::NewWrappedRenderTarget(ctx, wrapp edDesc, NULL)); |
| 129 REPORTER_ASSERT(reporter, surface); | 150 REPORTER_ASSERT(reporter, surface); |
| 151 if (surface) { | |
| 152 // Validate that we can draw to the canvas and that the original texture color is preserved | |
| 153 // in pixels that aren't rendered to via the surface. | |
| 154 SkPaint paint; | |
| 155 static const SkColor kRectColor = ~kOrigColor | 0xFF000000; | |
| 156 paint.setColor(kRectColor); | |
| 157 surface->getCanvas()->drawRect(SkRect::MakeWH(SkIntToScalar(kW), SkIntTo Scalar(kH)/2), | |
| 158 paint); | |
| 159 SkImageInfo readInfo = SkImageInfo::MakeN32Premul(kW, kH); | |
| 160 surface->readPixels(readInfo, pixels.get(), kW * sizeof(uint32_t), 0, 0) ; | |
| 161 bool stop = false; | |
| 162 SkPMColor origColorPM = SkPackARGB32((kOrigColor >> 24 & 0xFF), | |
| 163 (kOrigColor >> 0 & 0xFF), | |
| 164 (kOrigColor >> 8 & 0xFF), | |
| 165 (kOrigColor >> 16 & 0xFF)); | |
| 166 SkPMColor rectColorPM = SkPackARGB32((kRectColor >> 24 & 0xFF), | |
| 167 (kRectColor >> 16 & 0xFF), | |
| 168 (kRectColor >> 8 & 0xFF), | |
| 169 (kRectColor >> 0 & 0xFF)); | |
| 170 for (int y = 0; y < kH/2 && !stop; ++y) { | |
| 171 for (int x = 0; x < kW && !stop; ++x) { | |
| 172 REPORTER_ASSERT(reporter, rectColorPM == pixels[x + y * kW]); | |
| 173 if (rectColorPM != pixels[x + y * kW]) { | |
| 174 stop = true; | |
| 175 } | |
| 176 } | |
| 177 } | |
| 178 stop = false; | |
| 179 for (int y = kH/2; y < kH && !stop; ++y) { | |
| 180 for (int x = 0; x < kW && !stop; ++x) { | |
| 181 REPORTER_ASSERT(reporter, origColorPM == pixels[x + y * kW]); | |
| 182 if (origColorPM != pixels[x + y * kW]) { | |
| 183 stop = true; | |
| 184 } | |
| 185 } | |
| 186 } | |
| 187 } | |
| 130 } | 188 } |
| 131 #endif | 189 #endif |
| 132 | 190 |
| 133 | 191 |
| 134 static void test_image(skiatest::Reporter* reporter) { | 192 static void test_image(skiatest::Reporter* reporter) { |
| 135 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); | 193 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
| 136 size_t rowBytes = info.minRowBytes(); | 194 size_t rowBytes = info.minRowBytes(); |
| 137 size_t size = info.getSafeSize(rowBytes); | 195 size_t size = info.getSafeSize(rowBytes); |
| 138 SkData* data = SkData::NewUninitialized(size); | 196 SkData* data = SkData::NewUninitialized(size); |
| 139 | 197 |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 // Now lets jam new colors into our "external" texture, and see if the image s notice | 795 // Now lets jam new colors into our "external" texture, and see if the image s notice |
| 738 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE); | 796 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE); |
| 739 sk_memset32(storage, expected1, w * h); | 797 sk_memset32(storage, expected1, w * h); |
| 740 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF lushWrites_PixelOp); | 798 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF lushWrites_PixelOp); |
| 741 | 799 |
| 742 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color | 800 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color |
| 743 test_image_color(reporter, refImg, expected1); | 801 test_image_color(reporter, refImg, expected1); |
| 744 test_image_color(reporter, cpyImg, expected0); | 802 test_image_color(reporter, cpyImg, expected0); |
| 745 } | 803 } |
| 746 #endif | 804 #endif |
| OLD | NEW |