reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame^] | 8 | #include "SkImage_Gpu.h" |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 9 | #include "SkCanvas.h" |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 10 | #include "GrContext.h" |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 11 | |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame^] | 12 | SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap, int sampleCountForNewSurfaces, |
| 13 | SkSurface::Budgeted budgeted) |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 14 | : INHERITED(bitmap.width(), bitmap.height(), NULL) |
| 15 | , fBitmap(bitmap) |
reed | 3f10b9d | 2014-11-21 10:27:53 -0800 | [diff] [blame] | 16 | , fSampleCountForNewSurfaces(sampleCountForNewSurfaces) |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame^] | 17 | , fBudgeted(budgeted) |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 18 | { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 19 | SkASSERT(fBitmap.getTexture()); |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 20 | } |
| 21 | |
piotaixr | 76d5b47 | 2014-07-22 15:02:05 -0700 | [diff] [blame] | 22 | SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, |
| 23 | SkShader::TileMode tileY, |
| 24 | const SkMatrix* localMatrix) const |
| 25 | { |
| 26 | return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); |
piotaixr | cef04f8 | 2014-07-14 07:48:04 -0700 | [diff] [blame] | 27 | } |
| 28 | |
reed | 8572fc0 | 2014-08-11 13:03:55 -0700 | [diff] [blame] | 29 | void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const { |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 30 | canvas->drawBitmap(fBitmap, x, y, paint); |
| 31 | } |
| 32 | |
piotaixr | 5ceff91 | 2014-09-26 07:36:26 -0700 | [diff] [blame] | 33 | void SkImage_Gpu::onDrawRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, |
reed | 8572fc0 | 2014-08-11 13:03:55 -0700 | [diff] [blame] | 34 | const SkPaint* paint) const { |
commit-bot@chromium.org | dfec28d | 2013-07-23 15:52:16 +0000 | [diff] [blame] | 35 | canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); |
| 36 | } |
| 37 | |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 38 | SkSurface* SkImage_Gpu::onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props) const { |
| 39 | GrContext* ctx = this->getTexture()->getContext(); |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 40 | // TODO: Change signature of onNewSurface to take a budgeted param. |
| 41 | static const SkSurface::Budgeted kBudgeted = SkSurface::kNo_Budgeted; |
| 42 | return SkSurface::NewRenderTarget(ctx, kBudgeted, info, fSampleCountForNewSurfaces, &props); |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 43 | } |
| 44 | |
reed | 8572fc0 | 2014-08-11 13:03:55 -0700 | [diff] [blame] | 45 | GrTexture* SkImage_Gpu::onGetTexture() const { |
commit-bot@chromium.org | 4d24b74 | 2013-07-25 23:29:40 +0000 | [diff] [blame] | 46 | return fBitmap.getTexture(); |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 47 | } |
| 48 | |
reed@google.com | ace1354 | 2014-02-06 22:00:58 +0000 | [diff] [blame] | 49 | bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 50 | return fBitmap.copyTo(dst, kN32_SkColorType); |
reed@google.com | ace1354 | 2014-02-06 22:00:58 +0000 | [diff] [blame] | 51 | } |
| 52 | |
piotaixr | d2a3522 | 2014-08-19 14:29:02 -0700 | [diff] [blame] | 53 | bool SkImage_Gpu::isOpaque() const { |
| 54 | return fBitmap.isOpaque(); |
| 55 | } |
| 56 | |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 57 | /////////////////////////////////////////////////////////////////////////////// |
| 58 | |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame^] | 59 | SkImage* SkNewImageFromBitmapTexture(const SkBitmap& bitmap, int sampleCountForNewSurfaces, |
| 60 | SkSurface::Budgeted budgeted) { |
reed | 7983bf9 | 2015-01-23 04:24:16 -0800 | [diff] [blame] | 61 | if (0 == bitmap.width() || 0 == bitmap.height() || NULL == bitmap.getTexture()) { |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 62 | return NULL; |
| 63 | } |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame^] | 64 | return SkNEW_ARGS(SkImage_Gpu, (bitmap, sampleCountForNewSurfaces, budgeted)); |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 65 | } |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 66 | |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 67 | GrTexture* SkTextureImageGetTexture(SkImage* image) { |
| 68 | return ((SkImage_Gpu*)image)->getTexture(); |
| 69 | } |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 70 | |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame^] | 71 | extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { |
| 72 | ((SkImage_Gpu*)image)->applyBudgetDecision(); |
| 73 | } |