| 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 here to ensure SK_SUPPORT_GPU is set correctly before it is examined. | 8 // Include here to ensure SK_SUPPORT_GPU is set correctly before it is examined. |
| 9 #include "SkTypes.h" | 9 #include "SkTypes.h" |
| 10 | 10 |
| 11 #if SK_SUPPORT_GPU | 11 #if SK_SUPPORT_GPU |
| 12 | 12 |
| 13 #include "GrContext.h" | 13 #include "GrContext.h" |
| 14 #include "GrContextFactory.h" | 14 #include "GrContextFactory.h" |
| 15 #include "gl/GrGLInterface.h" | |
| 16 #include "GrGpu.h" | 15 #include "GrGpu.h" |
| 17 #include "GrGpuResourceCacheAccess.h" | 16 #include "GrGpuResourceCacheAccess.h" |
| 18 #include "GrGpuResourcePriv.h" | 17 #include "GrGpuResourcePriv.h" |
| 19 #include "GrRenderTarget.h" | 18 #include "GrRenderTarget.h" |
| 20 #include "GrRenderTargetPriv.h" | 19 #include "GrRenderTargetPriv.h" |
| 21 #include "GrResourceCache.h" | 20 #include "GrResourceCache.h" |
| 22 #include "GrTest.h" | 21 #include "GrTest.h" |
| 23 #include "SkCanvas.h" | 22 #include "SkCanvas.h" |
| 24 #include "SkGr.h" | 23 #include "SkGr.h" |
| 25 #include "SkMessageBus.h" | 24 #include "SkMessageBus.h" |
| 26 #include "SkSurface.h" | 25 #include "SkSurface.h" |
| 27 #include "Test.h" | 26 #include "Test.h" |
| 28 #include "../src/gpu/gl/GrGLDefines.h" | |
| 29 #include "../src/gpu/gl/GrGLUtil.h" | |
| 30 | 27 |
| 31 static const int gWidth = 640; | 28 static const int gWidth = 640; |
| 32 static const int gHeight = 480; | 29 static const int gHeight = 480; |
| 33 | 30 |
| 34 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
| 35 static void test_cache(skiatest::Reporter* reporter, GrContext* context, SkCanva
s* canvas) { | 32 static void test_cache(skiatest::Reporter* reporter, GrContext* context, SkCanva
s* canvas) { |
| 36 const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); | 33 const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); |
| 37 | 34 |
| 38 SkBitmap src; | 35 SkBitmap src; |
| 39 src.allocN32Pixels(size.width(), size.height()); | 36 src.allocN32Pixels(size.width(), size.height()); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 smallMSAART0 && smallMSAART1 && | 168 smallMSAART0 && smallMSAART1 && |
| 172 smallMSAART0->asRenderTarget() && | 169 smallMSAART0->asRenderTarget() && |
| 173 smallMSAART1->asRenderTarget() && | 170 smallMSAART1->asRenderTarget() && |
| 174 smallMSAART0->asRenderTarget()->renderTargetPriv().getSt
encilAttachment() != | 171 smallMSAART0->asRenderTarget()->renderTargetPriv().getSt
encilAttachment() != |
| 175 smallMSAART1->asRenderTarget()->renderTargetPriv().getSt
encilAttachment()); | 172 smallMSAART1->asRenderTarget()->renderTargetPriv().getSt
encilAttachment()); |
| 176 } | 173 } |
| 177 } | 174 } |
| 178 } | 175 } |
| 179 | 176 |
| 180 static void test_wrapped_resources(skiatest::Reporter* reporter, GrContext* cont
ext) { | 177 static void test_wrapped_resources(skiatest::Reporter* reporter, GrContext* cont
ext) { |
| 181 GrTestTarget tt; | 178 const GrGpu* gpu = context->getGpu(); |
| 182 context->getTestTarget(&tt); | 179 if (!gpu) { |
| 183 | |
| 184 const GrGLInterface* gl = tt.glContext()->interface(); | |
| 185 if (!gl) { | |
| 186 return; | 180 return; |
| 187 } | 181 } |
| 188 | 182 |
| 189 GrGLuint texIDs[2]; | 183 GrBackendObject texIDs[2]; |
| 190 static const int kW = 100; | 184 static const int kW = 100; |
| 191 static const int kH = 100; | 185 static const int kH = 100; |
| 192 GR_GL_CALL(gl, GenTextures(2, texIDs)); | 186 |
| 193 GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0)); | 187 texIDs[0] = gpu->createBackendTexture(NULL, kW, kH, kRGBA_8888_GrPixelConfig
); |
| 194 GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); | 188 texIDs[1] = gpu->createBackendTexture(NULL, kW, kH, kRGBA_8888_GrPixelConfig
); |
| 195 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texIDs[0])); | 189 |
| 196 GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, kW, kH, 0, GR_GL_
RGBA, | |
| 197 GR_GL_UNSIGNED_BYTE, NULL)); | |
| 198 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texIDs[1])); | |
| 199 GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, kW, kH, 0, GR_GL_
RGBA, | |
| 200 GR_GL_UNSIGNED_BYTE, NULL)); | |
| 201 context->resetContext(); | 190 context->resetContext(); |
| 202 | 191 |
| 203 GrBackendTextureDesc desc; | 192 GrBackendTextureDesc desc; |
| 204 desc.fConfig = kBGRA_8888_GrPixelConfig; | 193 desc.fConfig = kBGRA_8888_GrPixelConfig; |
| 205 desc.fWidth = kW; | 194 desc.fWidth = kW; |
| 206 desc.fHeight = kH; | 195 desc.fHeight = kH; |
| 207 | 196 |
| 208 desc.fTextureHandle = texIDs[0]; | 197 desc.fTextureHandle = texIDs[0]; |
| 209 SkAutoTUnref<GrTexture> borrowed(context->textureProvider()->wrapBackendText
ure( | 198 SkAutoTUnref<GrTexture> borrowed(context->textureProvider()->wrapBackendText
ure( |
| 210 desc, kBorrow_GrWrapOwnership)); | 199 desc, kBorrow_GrWrapOwnership)); |
| 211 | 200 |
| 212 desc.fTextureHandle = texIDs[1]; | 201 desc.fTextureHandle = texIDs[1]; |
| 213 SkAutoTUnref<GrTexture> adopted(context->textureProvider()->wrapBackendTextu
re( | 202 SkAutoTUnref<GrTexture> adopted(context->textureProvider()->wrapBackendTextu
re( |
| 214 desc, kAdopt_GrWrapOwnership)); | 203 desc, kAdopt_GrWrapOwnership)); |
| 215 | 204 |
| 216 REPORTER_ASSERT(reporter, SkToBool(borrowed) && SkToBool(adopted)); | 205 REPORTER_ASSERT(reporter, SkToBool(borrowed) && SkToBool(adopted)); |
| 217 if (!SkToBool(borrowed) || !SkToBool(adopted)) { | 206 if (!SkToBool(borrowed) || !SkToBool(adopted)) { |
| 218 return; | 207 return; |
| 219 } | 208 } |
| 220 | 209 |
| 221 borrowed.reset(NULL); | 210 borrowed.reset(NULL); |
| 222 adopted.reset(NULL); | 211 adopted.reset(NULL); |
| 223 | 212 |
| 224 context->flush(); | 213 context->flush(); |
| 225 | 214 |
| 226 GrGLboolean borrowedIsAlive; | 215 bool borrowedIsAlive = gpu->isBackendTexture(texIDs[0]); |
| 227 GrGLboolean adoptedIsAlive; | 216 bool adoptedIsAlive = gpu->isBackendTexture(texIDs[1]); |
| 228 GR_GL_CALL_RET(gl, borrowedIsAlive, IsTexture(texIDs[0])); | |
| 229 GR_GL_CALL_RET(gl, adoptedIsAlive, IsTexture(texIDs[1])); | |
| 230 | 217 |
| 231 REPORTER_ASSERT(reporter, borrowedIsAlive); | 218 REPORTER_ASSERT(reporter, borrowedIsAlive); |
| 232 REPORTER_ASSERT(reporter, !adoptedIsAlive); | 219 REPORTER_ASSERT(reporter, !adoptedIsAlive); |
| 233 | 220 |
| 234 GR_GL_CALL(gl, GenTextures(1, &texIDs[0])); | 221 gpu->deleteBackendTexture(texIDs[0]); |
| 235 | 222 |
| 236 context->resetContext(); | 223 context->resetContext(); |
| 237 } | 224 } |
| 238 | 225 |
| 239 class TestResource : public GrGpuResource { | 226 class TestResource : public GrGpuResource { |
| 240 static const size_t kDefaultSize = 100; | 227 static const size_t kDefaultSize = 100; |
| 241 enum ScratchConstructor { kScratchConstructor }; | 228 enum ScratchConstructor { kScratchConstructor }; |
| 242 public: | 229 public: |
| 243 | 230 |
| 244 /** Property that distinctly categorizes the resource. | 231 /** Property that distinctly categorizes the resource. |
| (...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1270 test_scratch_key_consistency(reporter); | 1257 test_scratch_key_consistency(reporter); |
| 1271 test_purge_invalidated(reporter); | 1258 test_purge_invalidated(reporter); |
| 1272 test_cache_chained_purge(reporter); | 1259 test_cache_chained_purge(reporter); |
| 1273 test_resource_size_changed(reporter); | 1260 test_resource_size_changed(reporter); |
| 1274 test_timestamp_wrap(reporter); | 1261 test_timestamp_wrap(reporter); |
| 1275 test_flush(reporter); | 1262 test_flush(reporter); |
| 1276 test_large_resource_count(reporter); | 1263 test_large_resource_count(reporter); |
| 1277 } | 1264 } |
| 1278 | 1265 |
| 1279 #endif | 1266 #endif |
| OLD | NEW |