99
1010#include " include/gpu/GrTexture.h"
1111#include " src/core/SkConvertPixels.h"
12+ #include " src/core/SkAutoPixmapStorage.h"
1213#include " src/gpu/GrContextPriv.h"
1314#include " src/gpu/GrGpu.h"
1415#include " src/gpu/SkGr.h"
@@ -20,12 +21,12 @@ void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context,
2021
2122 const int kWidth = 16 ;
2223 const int kHeight = 16 ;
23- SkAutoTMalloc<GrColor> srcBuffer;
24- if (doDataUpload) {
25- srcBuffer. reset ( kWidth * kHeight );
26- fill_pixel_data ( kWidth , kHeight , srcBuffer. get ()) ;
27- }
28- SkAutoTMalloc<GrColor> dstBuffer ( kWidth * kHeight );
24+
25+ SkImageInfo ii = SkImageInfo::Make ( kWidth , kHeight , ct, kPremul_SkAlphaType );
26+
27+ SkAutoPixmapStorage expectedPixels, actualPixels ;
28+ expectedPixels. alloc (ii);
29+ actualPixels. alloc (ii );
2930
3031 const GrCaps* caps = context->priv ().caps ();
3132 GrGpu* gpu = context->priv ().getGpu ();
@@ -44,10 +45,23 @@ void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context,
4445 return ;
4546 }
4647
47- GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture (
48- kWidth , kHeight , ct,
49- mipMapped, renderable, srcBuffer, 0 ,
50- &SkColors::kTransparent );
48+ GrBackendTexture backendTex;
49+
50+ if (doDataUpload) {
51+ SkASSERT (GrMipMapped::kNo == mipMapped);
52+
53+ fill_pixel_data (kWidth , kHeight , expectedPixels.writable_addr32 (0 , 0 ));
54+
55+ backendTex = context->priv ().createBackendTexture (&expectedPixels, 1 , renderable);
56+ } else {
57+ backendTex = context->createBackendTexture (kWidth , kHeight , ct, SkColors::kTransparent ,
58+ mipMapped, renderable);
59+
60+ size_t allocSize = SkAutoPixmapStorage::AllocSize (ii, nullptr );
61+ // createBackendTexture will fill the texture with 0's if no data is provided, so
62+ // we set the expected result likewise.
63+ memset (expectedPixels.writable_addr32 (0 , 0 ), 0 , allocSize);
64+ }
5165 if (!backendTex.isValid ()) {
5266 return ;
5367 }
@@ -62,18 +76,14 @@ void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context,
6276 }
6377 REPORTER_ASSERT (reporter, wrappedTex);
6478
65- int rowBytes = GrColorTypeBytesPerPixel (grCT) * kWidth ;
6679 bool result = gpu->readPixels (wrappedTex.get (), 0 , 0 , kWidth ,
67- kHeight , grCT, dstBuffer, rowBytes);
80+ kHeight , grCT,
81+ actualPixels.writable_addr32 (0 , 0 ),
82+ actualPixels.rowBytes ());
6883
69- if (!doDataUpload) {
70- // createTestingOnlyBackendTexture will fill the texture with 0's if no data is provided, so
71- // we set the expected result likewise.
72- srcBuffer.reset (kWidth * kHeight );
73- memset (srcBuffer, 0 , kWidth * kHeight * sizeof (GrColor));
74- }
7584 REPORTER_ASSERT (reporter, result);
76- REPORTER_ASSERT (reporter, does_full_buffer_contain_correct_color (srcBuffer, dstBuffer,
85+ REPORTER_ASSERT (reporter, does_full_buffer_contain_correct_color (expectedPixels.addr32 (),
86+ actualPixels.addr32 (),
7787 kWidth , kHeight ));
7888}
7989
0 commit comments