| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "DMSrcSink.h" | 8 #include "DMSrcSink.h" |
| 9 #include "SkAndroidCodec.h" | 9 #include "SkAndroidCodec.h" |
| 10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
| (...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 SkImageInfo::Make(size.width(), size.height(), fColorType, | 983 SkImageInfo::Make(size.width(), size.height(), fColorType, |
| 984 kPremul_SkAlphaType, fProfileType); | 984 kPremul_SkAlphaType, fProfileType); |
| 985 #if SK_SUPPORT_GPU | 985 #if SK_SUPPORT_GPU |
| 986 const int maxDimension = factory.getContextInfo(fContextType, fContextOption
s). | 986 const int maxDimension = factory.getContextInfo(fContextType, fContextOption
s). |
| 987 fGrContext->caps()->maxTextureSize(); | 987 fGrContext->caps()->maxTextureSize(); |
| 988 if (maxDimension < SkTMax(size.width(), size.height())) { | 988 if (maxDimension < SkTMax(size.width(), size.height())) { |
| 989 return Error::Nonfatal("Src too large to create a texture.\n"); | 989 return Error::Nonfatal("Src too large to create a texture.\n"); |
| 990 } | 990 } |
| 991 #endif | 991 #endif |
| 992 | 992 |
| 993 SkAutoTUnref<SkSurface> surface( | 993 auto surface( |
| 994 NewGpuSurface(&factory, fContextType, fContextOptions, info, fSample
Count, fUseDIText)); | 994 NewGpuSurface(&factory, fContextType, fContextOptions, info, fSample
Count, fUseDIText)); |
| 995 if (!surface) { | 995 if (!surface) { |
| 996 return "Could not create a surface."; | 996 return "Could not create a surface."; |
| 997 } | 997 } |
| 998 if (FLAGS_preAbandonGpuContext) { | 998 if (FLAGS_preAbandonGpuContext) { |
| 999 SkSetErrorCallback(&PreAbandonGpuContextErrorHandler, nullptr); | 999 SkSetErrorCallback(&PreAbandonGpuContextErrorHandler, nullptr); |
| 1000 factory.abandonContexts(); | 1000 factory.abandonContexts(); |
| 1001 } | 1001 } |
| 1002 SkCanvas* canvas = surface->getCanvas(); | 1002 SkCanvas* canvas = surface->getCanvas(); |
| 1003 Error err = src.draw(canvas); | 1003 Error err = src.draw(canvas); |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 fFactory.get())); | 1302 fFactory.get())); |
| 1303 if (!err.isEmpty()) { | 1303 if (!err.isEmpty()) { |
| 1304 return err; | 1304 return err; |
| 1305 } | 1305 } |
| 1306 sk_sp<SkPicture> pic(recorder.finishRecordingAsPicture()); | 1306 sk_sp<SkPicture> pic(recorder.finishRecordingAsPicture()); |
| 1307 | 1307 |
| 1308 return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas*
canvas) { | 1308 return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas*
canvas) { |
| 1309 const int xTiles = (size.width() + fW - 1) / fW, | 1309 const int xTiles = (size.width() + fW - 1) / fW, |
| 1310 yTiles = (size.height() + fH - 1) / fH; | 1310 yTiles = (size.height() + fH - 1) / fH; |
| 1311 SkMultiPictureDraw mpd(xTiles*yTiles); | 1311 SkMultiPictureDraw mpd(xTiles*yTiles); |
| 1312 SkTDArray<SkSurface*> surfaces; | 1312 SkTArray<sk_sp<SkSurface>> surfaces; |
| 1313 surfaces.setReserve(xTiles*yTiles); | 1313 // surfaces.setReserve(xTiles*yTiles); |
| 1314 | 1314 |
| 1315 SkImageInfo info = canvas->imageInfo().makeWH(fW, fH); | 1315 SkImageInfo info = canvas->imageInfo().makeWH(fW, fH); |
| 1316 for (int j = 0; j < yTiles; j++) { | 1316 for (int j = 0; j < yTiles; j++) { |
| 1317 for (int i = 0; i < xTiles; i++) { | 1317 for (int i = 0; i < xTiles; i++) { |
| 1318 // This lets our ultimate Sink determine the best kind of surfac
e. | 1318 // This lets our ultimate Sink determine the best kind of surfac
e. |
| 1319 // E.g., if it's a GpuSink, the surfaces and images are textures
. | 1319 // E.g., if it's a GpuSink, the surfaces and images are textures
. |
| 1320 SkSurface* s = canvas->newSurface(info); | 1320 auto s = canvas->makeSurface(info); |
| 1321 if (!s) { | 1321 if (!s) { |
| 1322 s = SkSurface::NewRaster(info); // Some canvases can't crea
te surfaces. | 1322 s = SkSurface::MakeRaster(info); // Some canvases can't cre
ate surfaces. |
| 1323 } | 1323 } |
| 1324 surfaces.push(s); | 1324 surfaces.push_back(s); |
| 1325 SkCanvas* c = s->getCanvas(); | 1325 SkCanvas* c = s->getCanvas(); |
| 1326 c->translate(SkIntToScalar(-i * fW), | 1326 c->translate(SkIntToScalar(-i * fW), |
| 1327 SkIntToScalar(-j * fH)); // Line up the canvas wit
h this tile. | 1327 SkIntToScalar(-j * fH)); // Line up the canvas wit
h this tile. |
| 1328 mpd.add(c, pic.get()); | 1328 mpd.add(c, pic.get()); |
| 1329 } | 1329 } |
| 1330 } | 1330 } |
| 1331 mpd.draw(); | 1331 mpd.draw(); |
| 1332 for (int j = 0; j < yTiles; j++) { | 1332 for (int j = 0; j < yTiles; j++) { |
| 1333 for (int i = 0; i < xTiles; i++) { | 1333 for (int i = 0; i < xTiles; i++) { |
| 1334 sk_sp<SkImage> image(surfaces[i+xTiles*j]->makeImageSnapshot()); | 1334 sk_sp<SkImage> image(surfaces[i+xTiles*j]->makeImageSnapshot()); |
| 1335 canvas->drawImage(image, SkIntToScalar(i*fW), SkIntToScalar(j*fH
)); | 1335 canvas->drawImage(image, SkIntToScalar(i*fW), SkIntToScalar(j*fH
)); |
| 1336 } | 1336 } |
| 1337 } | 1337 } |
| 1338 surfaces.unrefAll(); | |
| 1339 return ""; | 1338 return ""; |
| 1340 }); | 1339 }); |
| 1341 } | 1340 } |
| 1342 | 1341 |
| 1343 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 1342 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
| 1344 | 1343 |
| 1345 Error ViaPicture::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkSt
ring* log) const { | 1344 Error ViaPicture::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkSt
ring* log) const { |
| 1346 auto size = src.size(); | 1345 auto size = src.size(); |
| 1347 return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas
) -> Error { | 1346 return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas
) -> Error { |
| 1348 SkPictureRecorder recorder; | 1347 SkPictureRecorder recorder; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1511 skr.visit(i, drawsAsSingletonPictures); | 1510 skr.visit(i, drawsAsSingletonPictures); |
| 1512 } | 1511 } |
| 1513 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); | 1512 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); |
| 1514 | 1513 |
| 1515 canvas->drawPicture(macroPic); | 1514 canvas->drawPicture(macroPic); |
| 1516 return check_against_reference(bitmap, src, fSink); | 1515 return check_against_reference(bitmap, src, fSink); |
| 1517 }); | 1516 }); |
| 1518 } | 1517 } |
| 1519 | 1518 |
| 1520 } // namespace DM | 1519 } // namespace DM |
| OLD | NEW |