OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 #include "SkSpecialImage.h" | 7 #include "SkSpecialImage.h" |
8 | 8 |
9 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
10 #include "GrTexture.h" | 10 #include "GrTexture.h" |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 SkSpecialImage_Raster(const SkIRect& subset, const SkBitmap& bm, const SkSur
faceProps* props) | 328 SkSpecialImage_Raster(const SkIRect& subset, const SkBitmap& bm, const SkSur
faceProps* props) |
329 : INHERITED(subset, bm.getGenerationID(), props) | 329 : INHERITED(subset, bm.getGenerationID(), props) |
330 , fBitmap(bm) { | 330 , fBitmap(bm) { |
331 if (bm.pixelRef() && bm.pixelRef()->isPreLocked()) { | 331 if (bm.pixelRef() && bm.pixelRef()->isPreLocked()) { |
332 // we only preemptively lock if there is no chance of triggering som
ething expensive | 332 // we only preemptively lock if there is no chance of triggering som
ething expensive |
333 // like a lazy decode or imagegenerator. PreLocked means it is flat
pixels already. | 333 // like a lazy decode or imagegenerator. PreLocked means it is flat
pixels already. |
334 fBitmap.lockPixels(); | 334 fBitmap.lockPixels(); |
335 } | 335 } |
336 } | 336 } |
337 | 337 |
338 SkSpecialImage_Raster(const SkIRect& subset, | |
339 const SkPixmap& pixmap, | |
340 RasterReleaseProc releaseProc, | |
341 ReleaseContext context, | |
342 const SkSurfaceProps* props) | |
343 : INHERITED(subset, kNeedNewImageUniqueID_SpecialImage, props) { | |
344 fBitmap.installPixels(pixmap.info(), pixmap.writable_addr(), | |
345 pixmap.rowBytes(), pixmap.ctable(), | |
346 releaseProc, context); | |
347 } | |
348 | |
349 ~SkSpecialImage_Raster() override { } | |
350 | |
351 bool isOpaque() const override { return fBitmap.isOpaque(); } | 338 bool isOpaque() const override { return fBitmap.isOpaque(); } |
352 | 339 |
353 size_t getSize() const override { return fBitmap.getSize(); } | 340 size_t getSize() const override { return fBitmap.getSize(); } |
354 | 341 |
355 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { | 342 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { |
356 SkRect dst = SkRect::MakeXYWH(x, y, | 343 SkRect dst = SkRect::MakeXYWH(x, y, |
357 this->subset().width(), this->subset().hei
ght()); | 344 this->subset().width(), this->subset().hei
ght()); |
358 | 345 |
359 canvas->drawBitmapRect(fBitmap, this->subset(), | 346 canvas->drawBitmapRect(fBitmap, this->subset(), |
360 dst, paint, SkCanvas::kStrict_SrcRectConstraint); | 347 dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 408 |
422 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(const SkIRect& subset, | 409 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(const SkIRect& subset, |
423 const SkBitmap& bm, | 410 const SkBitmap& bm, |
424 const SkSurfaceProps* props
) { | 411 const SkSurfaceProps* props
) { |
425 SkASSERT(nullptr == bm.getTexture()); | 412 SkASSERT(nullptr == bm.getTexture()); |
426 SkASSERT(rect_fits(subset, bm.width(), bm.height())); | 413 SkASSERT(rect_fits(subset, bm.width(), bm.height())); |
427 | 414 |
428 return sk_make_sp<SkSpecialImage_Raster>(subset, bm, props); | 415 return sk_make_sp<SkSpecialImage_Raster>(subset, bm, props); |
429 } | 416 } |
430 | 417 |
431 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromPixmap(const SkIRect& subset, | |
432 const SkPixmap& src, | |
433 RasterReleaseProc releasePr
oc, | |
434 ReleaseContext context, | |
435 const SkSurfaceProps* props
) { | |
436 if (!src.addr()) { | |
437 return nullptr; | |
438 } | |
439 | |
440 return sk_make_sp<SkSpecialImage_Raster>(subset, src, releaseProc, context,
props); | |
441 } | |
442 | |
443 | |
444 #if SK_SUPPORT_GPU | 418 #if SK_SUPPORT_GPU |
445 /////////////////////////////////////////////////////////////////////////////// | 419 /////////////////////////////////////////////////////////////////////////////// |
446 #include "GrTexture.h" | 420 #include "GrTexture.h" |
447 #include "SkImage_Gpu.h" | 421 #include "SkImage_Gpu.h" |
448 | 422 |
449 class SkSpecialImage_Gpu : public SkSpecialImage_Base { | 423 class SkSpecialImage_Gpu : public SkSpecialImage_Base { |
450 public: | 424 public: |
451 SkSpecialImage_Gpu(const SkIRect& subset, | 425 SkSpecialImage_Gpu(const SkIRect& subset, |
452 uint32_t uniqueID, sk_sp<GrTexture> tex, SkAlphaType at, | 426 uint32_t uniqueID, sk_sp<GrTexture> tex, SkAlphaType at, |
453 const SkSurfaceProps* props) | 427 const SkSurfaceProps* props) |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, | 560 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, |
587 uint32_t uniqueID, | 561 uint32_t uniqueID, |
588 sk_sp<GrTexture> tex, | 562 sk_sp<GrTexture> tex, |
589 const SkSurfaceProps* props, | 563 const SkSurfaceProps* props, |
590 SkAlphaType at) { | 564 SkAlphaType at) { |
591 SkASSERT(rect_fits(subset, tex->width(), tex->height())); | 565 SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
592 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at,
props); | 566 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at,
props); |
593 } | 567 } |
594 | 568 |
595 #endif | 569 #endif |
OLD | NEW |