Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: tests/ReadPixelsTest.cpp

Issue 355193006: stop calling SkCanvas::getDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkMathPriv.h" 11 #include "SkMathPriv.h"
12 #include "SkRegion.h" 12 #include "SkRegion.h"
13 #include "SkSurface.h"
13 #include "Test.h" 14 #include "Test.h"
14 15
15 #if SK_SUPPORT_GPU 16 #if SK_SUPPORT_GPU
16 #include "GrContextFactory.h" 17 #include "GrContextFactory.h"
17 #include "SkGpuDevice.h" 18 #include "SkGpuDevice.h"
18 #endif 19 #endif
19 20
20 static const int DEV_W = 100, DEV_H = 100; 21 static const int DEV_W = 100, DEV_H = 100;
21 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H); 22 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H);
22 static const SkRect DEV_RECT_S = SkRect::MakeWH(DEV_W * SK_Scalar1, 23 static const SkRect DEV_RECT_S = SkRect::MakeWH(DEV_W * SK_Scalar1,
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H + 10), 291 SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H + 10),
291 }; 292 };
292 293
293 for (int dtype = 0; dtype < 3; ++dtype) { 294 for (int dtype = 0; dtype < 3; ++dtype) {
294 int glCtxTypeCnt = 1; 295 int glCtxTypeCnt = 1;
295 #if SK_SUPPORT_GPU 296 #if SK_SUPPORT_GPU
296 if (0 != dtype) { 297 if (0 != dtype) {
297 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt; 298 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt;
298 } 299 }
299 #endif 300 #endif
301 const SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H);
300 for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) { 302 for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) {
301 SkAutoTUnref<SkBaseDevice> device; 303 SkAutoTUnref<SkSurface> surface;
302 if (0 == dtype) { 304 if (0 == dtype) {
303 SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H); 305 surface.reset(SkSurface::NewRaster(info));
304 device.reset(SkBitmapDevice::Create(info));
305 } else { 306 } else {
306 #if SK_SUPPORT_GPU 307 #if SK_SUPPORT_GPU
307 GrContextFactory::GLContextType type = 308 GrContextFactory::GLContextType type =
308 static_cast<GrContextFactory::GLContextType>(glCtxType); 309 static_cast<GrContextFactory::GLContextType>(glCtxType);
309 if (!GrContextFactory::IsRenderingGLContext(type)) { 310 if (!GrContextFactory::IsRenderingGLContext(type)) {
310 continue; 311 continue;
311 } 312 }
312 GrContext* context = factory->get(type); 313 GrContext* context = factory->get(type);
313 if (NULL == context) { 314 if (NULL == context) {
314 continue; 315 continue;
315 } 316 }
316 GrTextureDesc desc; 317 GrTextureDesc desc;
318 surface.reset(SkSurface::NewScratchRenderTarget(context, info));
bsalomon 2014/06/30 13:24:33 You don't need this line and line 323. The code at
reed1 2014/06/30 14:33:12 Yes. Don't know why I had that line.
317 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrText ureFlagBit; 319 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrText ureFlagBit;
318 desc.fWidth = DEV_W; 320 desc.fWidth = DEV_W;
319 desc.fHeight = DEV_H; 321 desc.fHeight = DEV_H;
320 desc.fConfig = kSkia8888_GrPixelConfig; 322 desc.fConfig = kSkia8888_GrPixelConfig;
321 desc.fOrigin = 1 == dtype ? kBottomLeft_GrSurfaceOrigin 323 desc.fOrigin = 1 == dtype ? kBottomLeft_GrSurfaceOrigin : kTopLe ft_GrSurfaceOrigin;
322 : kTopLeft_GrSurfaceOrigin;
323 GrAutoScratchTexture ast(context, desc, GrContext::kExact_Scratc hTexMatch); 324 GrAutoScratchTexture ast(context, desc, GrContext::kExact_Scratc hTexMatch);
324 SkAutoTUnref<GrTexture> tex(ast.detach()); 325 SkAutoTUnref<GrTexture> tex(ast.detach());
325 device.reset(new SkGpuDevice(context, tex)); 326 surface.reset(SkSurface::NewRenderTargetDirect(tex->asRenderTarg et()));
326 #else 327 #else
327 continue; 328 continue;
328 #endif 329 #endif
329 } 330 }
330 SkCanvas canvas(device); 331 SkCanvas& canvas = *surface->getCanvas();
331 fillCanvas(&canvas); 332 fillCanvas(&canvas);
332 333
333 static const struct { 334 static const struct {
334 SkColorType fColorType; 335 SkColorType fColorType;
335 SkAlphaType fAlphaType; 336 SkAlphaType fAlphaType;
336 } gReadConfigs[] = { 337 } gReadConfigs[] = {
337 { kRGBA_8888_SkColorType, kPremul_SkAlphaType }, 338 { kRGBA_8888_SkColorType, kPremul_SkAlphaType },
338 { kRGBA_8888_SkColorType, kUnpremul_SkAlphaType }, 339 { kRGBA_8888_SkColorType, kUnpremul_SkAlphaType },
339 { kBGRA_8888_SkColorType, kPremul_SkAlphaType }, 340 { kBGRA_8888_SkColorType, kPremul_SkAlphaType },
340 { kBGRA_8888_SkColorType, kUnpremul_SkAlphaType }, 341 { kBGRA_8888_SkColorType, kUnpremul_SkAlphaType },
341 }; 342 };
342 for (size_t rect = 0; rect < SK_ARRAY_COUNT(testRects); ++rect) { 343 for (size_t rect = 0; rect < SK_ARRAY_COUNT(testRects); ++rect) {
343 const SkIRect& srcRect = testRects[rect]; 344 const SkIRect& srcRect = testRects[rect];
344 for (BitmapInit bmi = kFirstBitmapInit; bmi < kBitmapInitCnt; bm i = nextBMI(bmi)) { 345 for (BitmapInit bmi = kFirstBitmapInit; bmi < kBitmapInitCnt; bm i = nextBMI(bmi)) {
345 for (size_t c = 0; c < SK_ARRAY_COUNT(gReadConfigs); ++c) { 346 for (size_t c = 0; c < SK_ARRAY_COUNT(gReadConfigs); ++c) {
346 SkBitmap bmp; 347 SkBitmap bmp;
347 init_bitmap(&bmp, srcRect, bmi, 348 init_bitmap(&bmp, srcRect, bmi,
348 gReadConfigs[c].fColorType, gReadConfigs[c]. fAlphaType); 349 gReadConfigs[c].fColorType, gReadConfigs[c]. fAlphaType);
349 350
350 // if the bitmap has pixels allocated before the readPix els, 351 // if the bitmap has pixels allocated before the readPix els,
351 // note that and fill them with pattern 352 // note that and fill them with pattern
352 bool startsWithPixels = !bmp.isNull(); 353 bool startsWithPixels = !bmp.isNull();
353 if (startsWithPixels) { 354 if (startsWithPixels) {
354 fillBitmap(&bmp); 355 fillBitmap(&bmp);
355 } 356 }
356 uint32_t idBefore = canvas.getDevice()->accessBitmap(fal se).getGenerationID(); 357 uint32_t idBefore = surface->generationID();
357 bool success = canvas.readPixels(&bmp, srcRect.fLeft, sr cRect.fTop); 358 bool success = canvas.readPixels(&bmp, srcRect.fLeft, sr cRect.fTop);
358 uint32_t idAfter = canvas.getDevice()->accessBitmap(fals e).getGenerationID(); 359 uint32_t idAfter = surface->generationID();
359 360
360 // we expect to succeed when the read isn't fully clippe d 361 // we expect to succeed when the read isn't fully clippe d
361 // out. 362 // out.
362 bool expectSuccess = SkIRect::Intersects(srcRect, DEV_RE CT); 363 bool expectSuccess = SkIRect::Intersects(srcRect, DEV_RE CT);
363 // determine whether we expected the read to succeed. 364 // determine whether we expected the read to succeed.
364 REPORTER_ASSERT(reporter, success == expectSuccess); 365 REPORTER_ASSERT(reporter, success == expectSuccess);
365 // read pixels should never change the gen id 366 // read pixels should never change the gen id
366 REPORTER_ASSERT(reporter, idBefore == idAfter); 367 REPORTER_ASSERT(reporter, idBefore == idAfter);
367 368
368 if (success || startsWithPixels) { 369 if (success || startsWithPixels) {
(...skipping 17 matching lines...) Expand all
386 checkRead(reporter, wkbmp, clippedRect.fLeft, 387 checkRead(reporter, wkbmp, clippedRect.fLeft,
387 clippedRect.fTop, true, false); 388 clippedRect.fTop, true, false);
388 } else { 389 } else {
389 REPORTER_ASSERT(reporter, !success); 390 REPORTER_ASSERT(reporter, !success);
390 } 391 }
391 } 392 }
392 } 393 }
393 } 394 }
394 } 395 }
395 } 396 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698