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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 1643873002: allow the caller to specified raster-surface rowbytes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update dox for snapped image rowbytes Created 4 years, 10 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
« no previous file with comments | « src/image/SkSurface_Raster.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { 654 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) {
655 for (auto& mode : modes) { 655 for (auto& mode : modes) {
656 SkAutoTUnref<SkSurface> surface( 656 SkAutoTUnref<SkSurface> surface(
657 surface_func(context, kPremul_SkAlphaType, nullptr)); 657 surface_func(context, kPremul_SkAlphaType, nullptr));
658 test_func(reporter, surface, mode); 658 test_func(reporter, surface, mode);
659 } 659 }
660 } 660 }
661 } 661 }
662 } 662 }
663 #endif 663 #endif
664
665 static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Repor ter* reporter) {
666 SkImageInfo info;
667 size_t rowBytes;
668 REPORTER_ASSERT(reporter, surface->peekPixels(&info, &rowBytes));
669
670 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
671 SkImageInfo im_info;
672 size_t im_rowbytes;
673 REPORTER_ASSERT(reporter, image->peekPixels(&im_info, &im_rowbytes));
674
675 REPORTER_ASSERT(reporter, rowBytes == im_rowbytes);
676
677 // trigger a copy-on-write
678 surface->getCanvas()->drawPaint(SkPaint());
679 SkAutoTUnref<SkImage> image2(surface->newImageSnapshot());
680 REPORTER_ASSERT(reporter, image->uniqueID() != image2->uniqueID());
681
682 SkImageInfo im_info2;
683 size_t im_rowbytes2;
684 REPORTER_ASSERT(reporter, image2->peekPixels(&im_info2, &im_rowbytes2));
685
686 REPORTER_ASSERT(reporter, im_rowbytes2 == im_rowbytes);
687 }
688
689 DEF_TEST(surface_rowbytes, reporter) {
690 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
691
692 SkAutoTUnref<SkSurface> surf0(SkSurface::NewRaster(info));
693 check_rowbytes_remain_consistent(surf0, reporter);
694
695 // specify a larger rowbytes
696 SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info, 500, nullptr));
697 check_rowbytes_remain_consistent(surf1, reporter);
698
699 // Try some illegal rowByte values
700 SkSurface* s = SkSurface::NewRaster(info, 396, nullptr); // needs to be a t least 400
701 REPORTER_ASSERT(reporter, nullptr == s);
702 s = SkSurface::NewRaster(info, 1 << 30, nullptr); // allocation to large
703 REPORTER_ASSERT(reporter, nullptr == s);
704 }
OLDNEW
« no previous file with comments | « src/image/SkSurface_Raster.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698