| OLD | NEW |
| 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 "Test.h" | 13 #include "Test.h" |
| 14 #include "sk_tool_utils.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 #else | 19 #else |
| 19 class GrContext; | 20 class GrContext; |
| 20 class GrContextFactory; | 21 class GrContextFactory; |
| 21 #endif | 22 #endif |
| 22 | 23 |
| 23 static const int DEV_W = 100, DEV_H = 100; | 24 static const int DEV_W = 100, DEV_H = 100; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 128 } |
| 128 if (config8888IsPremul(config8888)) { | 129 if (config8888IsPremul(config8888)) { |
| 129 r = SkMulDiv255Ceiling(r, a); | 130 r = SkMulDiv255Ceiling(r, a); |
| 130 g = SkMulDiv255Ceiling(g, a); | 131 g = SkMulDiv255Ceiling(g, a); |
| 131 b = SkMulDiv255Ceiling(b, a); | 132 b = SkMulDiv255Ceiling(b, a); |
| 132 } | 133 } |
| 133 return packConfig8888(config8888, a, r, g , b); | 134 return packConfig8888(config8888, a, r, g , b); |
| 134 } | 135 } |
| 135 | 136 |
| 136 static void fillCanvas(SkCanvas* canvas) { | 137 static void fillCanvas(SkCanvas* canvas) { |
| 137 static SkBitmap bmp; | 138 SkBitmap bmp; |
| 138 if (bmp.isNull()) { | 139 if (bmp.isNull()) { |
| 139 SkDEBUGCODE(bool alloc = ) bmp.allocN32Pixels(DEV_W, DEV_H); | 140 SkDEBUGCODE(bool alloc = ) bmp.allocN32Pixels(DEV_W, DEV_H); |
| 140 SkASSERT(alloc); | 141 SkASSERT(alloc); |
| 141 SkAutoLockPixels alp(bmp); | |
| 142 intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels()); | |
| 143 for (int y = 0; y < DEV_H; ++y) { | 142 for (int y = 0; y < DEV_H; ++y) { |
| 144 for (int x = 0; x < DEV_W; ++x) { | 143 for (int x = 0; x < DEV_W; ++x) { |
| 145 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bmp
.rowBytes() + x * bmp.bytesPerPixel()); | 144 *bmp.getAddr32(x, y) = getCanvasColor(x, y); |
| 146 *pixel = getCanvasColor(x, y); | |
| 147 } | 145 } |
| 148 } | 146 } |
| 149 } | 147 } |
| 150 canvas->save(); | 148 canvas->save(); |
| 151 canvas->setMatrix(SkMatrix::I()); | 149 canvas->setMatrix(SkMatrix::I()); |
| 152 canvas->clipRect(DEV_RECT_S, SkRegion::kReplace_Op); | 150 canvas->clipRect(DEV_RECT_S, SkRegion::kReplace_Op); |
| 153 SkPaint paint; | 151 SkPaint paint; |
| 154 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 152 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 155 canvas->drawBitmap(bmp, 0, 0, &paint); | 153 canvas->drawBitmap(bmp, 0, 0, &paint); |
| 156 canvas->restore(); | 154 canvas->restore(); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 }; | 459 }; |
| 462 for (size_t r = 0; r < SK_ARRAY_COUNT(testRects); ++r) { | 460 for (size_t r = 0; r < SK_ARRAY_COUNT(testRects); ++r) { |
| 463 const SkIRect& rect = testRects[r]; | 461 const SkIRect& rect = testRects[r]; |
| 464 for (int tightBmp = 0; tightBmp < 2; ++tightBmp) { | 462 for (int tightBmp = 0; tightBmp < 2; ++tightBmp) { |
| 465 for (size_t c = 0; c < SK_ARRAY_COUNT(gSrcConfigs); ++c) { | 463 for (size_t c = 0; c < SK_ARRAY_COUNT(gSrcConfigs); ++c) { |
| 466 fillCanvas(&canvas); | 464 fillCanvas(&canvas); |
| 467 SkCanvas::Config8888 config8888 = gSrcConfigs[c]; | 465 SkCanvas::Config8888 config8888 = gSrcConfigs[c]; |
| 468 SkBitmap bmp; | 466 SkBitmap bmp; |
| 469 REPORTER_ASSERT(reporter, setupBitmap(&bmp, config8888,
rect.width(), rect.height(), SkToBool(tightBmp))); | 467 REPORTER_ASSERT(reporter, setupBitmap(&bmp, config8888,
rect.width(), rect.height(), SkToBool(tightBmp))); |
| 470 uint32_t idBefore = canvas.getDevice()->accessBitmap(fal
se).getGenerationID(); | 468 uint32_t idBefore = canvas.getDevice()->accessBitmap(fal
se).getGenerationID(); |
| 471 canvas.writePixels(bmp, rect.fLeft, rect.fTop, config888
8); | 469 |
| 470 SkColorType ct; |
| 471 SkAlphaType at; |
| 472 sk_tool_utils::config8888_to_imagetypes(config8888, &ct,
&at); |
| 473 sk_tool_utils::write_pixels(&canvas, bmp, rect.fLeft, re
ct.fTop, ct, at); |
| 474 |
| 472 uint32_t idAfter = canvas.getDevice()->accessBitmap(fals
e).getGenerationID(); | 475 uint32_t idAfter = canvas.getDevice()->accessBitmap(fals
e).getGenerationID(); |
| 473 REPORTER_ASSERT(reporter, checkWrite(reporter, &canvas,
bmp, rect.fLeft, rect.fTop, config8888)); | 476 REPORTER_ASSERT(reporter, checkWrite(reporter, &canvas,
bmp, rect.fLeft, rect.fTop, config8888)); |
| 474 | 477 |
| 475 // we should change the genID iff pixels were actually w
ritten. | 478 // we should change the genID iff pixels were actually w
ritten. |
| 476 SkIRect canvasRect = SkIRect::MakeSize(canvas.getDeviceS
ize()); | 479 SkIRect canvasRect = SkIRect::MakeSize(canvas.getDeviceS
ize()); |
| 477 SkIRect writeRect = SkIRect::MakeXYWH(rect.fLeft, rect.f
Top, | 480 SkIRect writeRect = SkIRect::MakeXYWH(rect.fLeft, rect.f
Top, |
| 478 bmp.width(), bmp.h
eight()); | 481 bmp.width(), bmp.h
eight()); |
| 479 bool intersects = SkIRect::Intersects(canvasRect, writeR
ect) ; | 482 bool intersects = SkIRect::Intersects(canvasRect, writeR
ect) ; |
| 480 REPORTER_ASSERT(reporter, intersects == (idBefore != idA
fter)); | 483 REPORTER_ASSERT(reporter, intersects == (idBefore != idA
fter)); |
| 481 } | 484 } |
| 482 } | 485 } |
| 483 } | 486 } |
| 484 } | 487 } |
| 485 } | 488 } |
| 486 } | 489 } |
| OLD | NEW |