Chromium Code Reviews| 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 "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
| 9 | 9 |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 1714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1725 AutoBitmapTexture abt(fContext, src, NULL, &texture); | 1725 AutoBitmapTexture abt(fContext, src, NULL, &texture); |
| 1726 if (!texture) { | 1726 if (!texture) { |
| 1727 return false; | 1727 return false; |
| 1728 } | 1728 } |
| 1729 | 1729 |
| 1730 return this->filterTexture(fContext, texture, src.width(), src.height(), | 1730 return this->filterTexture(fContext, texture, src.width(), src.height(), |
| 1731 filter, ctx, result, offset); | 1731 filter, ctx, result, offset); |
| 1732 } | 1732 } |
| 1733 | 1733 |
| 1734 static SkImageInfo make_info(GrTexture* tex, int w, int h, bool isOpaque) { | 1734 static SkImageInfo make_info(GrTexture* tex, int w, int h, bool isOpaque) { |
| 1735 #ifdef SK_DEBUG | |
| 1736 const GrSurfaceDesc& desc = tex->desc(); | |
| 1737 SkASSERT(w <= desc.fWidth); | |
| 1738 SkASSERT(h <= desc.fHeight); | |
| 1739 #endif | |
| 1735 const GrPixelConfig config = tex->config(); | 1740 const GrPixelConfig config = tex->config(); |
| 1736 SkColorType ct; | 1741 SkColorType ct; |
| 1737 SkAlphaType at = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | 1742 SkAlphaType at = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
| 1738 if (!GrPixelConfig2ColorAndProfileType(config, &ct, NULL)) { | 1743 if (!GrPixelConfig2ColorAndProfileType(config, &ct, NULL)) { |
| 1739 ct = kUnknown_SkColorType; | 1744 ct = kUnknown_SkColorType; |
| 1740 } | 1745 } |
| 1741 return SkImageInfo::Make(w, h, ct, at); | 1746 return SkImageInfo::Make(w, h, ct, at); |
| 1742 } | 1747 } |
| 1743 | 1748 |
| 1749 void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, SkBitmap * dst) { | |
|
bsalomon
2015/05/07 17:05:56
This code should maybe move to SkGr.h/cpp where th
reed1
2015/05/07 17:49:11
Done.
| |
| 1750 const SkImageInfo info = make_info(src, w, h, isOpaque); | |
| 1751 dst->setInfo(info); | |
| 1752 dst->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, src)))->unref(); | |
| 1753 } | |
| 1754 | |
|
robertphillips
2015/05/07 16:50:03
Move the #include up ?
Do we even need this ?
reed1
2015/05/07 17:49:11
Done.
| |
| 1755 #include "SkImage_Base.h" | |
| 1756 | |
| 1744 static bool wrap_as_bm(const SkImage* image, SkBitmap* bm) { | 1757 static bool wrap_as_bm(const SkImage* image, SkBitmap* bm) { |
| 1745 GrTexture* tex = image->getTexture(); | 1758 GrTexture* tex = image->getTexture(); |
| 1746 if (tex) { | 1759 if (tex) { |
| 1747 // TODO: handle the GrTexture directly, and skip GrPixelRef | 1760 GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpa que(), bm); |
| 1748 const SkImageInfo info = make_info(tex, image->width(), image->height(), image->isOpaque()); | 1761 return true; |
| 1749 bm->setInfo(info); | |
| 1750 bm->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, tex)))->unref(); | |
| 1751 } else { | 1762 } else { |
| 1752 if (!as_IB(image)->getROPixels(bm)) { | 1763 return as_IB(image)->getROPixels(bm); |
| 1753 return false; | |
| 1754 } | |
| 1755 } | 1764 } |
| 1756 return true; | |
| 1757 } | 1765 } |
| 1758 | 1766 |
| 1759 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x , SkScalar y, | 1767 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x , SkScalar y, |
| 1760 const SkPaint& paint) { | 1768 const SkPaint& paint) { |
| 1761 SkBitmap bm; | 1769 SkBitmap bm; |
| 1762 if (wrap_as_bm(image, &bm)) { | 1770 if (wrap_as_bm(image, &bm)) { |
| 1763 this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); | 1771 this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); |
| 1764 } | 1772 } |
| 1765 } | 1773 } |
| 1766 | 1774 |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2072 #endif | 2080 #endif |
| 2073 } | 2081 } |
| 2074 | 2082 |
| 2075 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 2083 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 2076 // We always return a transient cache, so it is freed after each | 2084 // We always return a transient cache, so it is freed after each |
| 2077 // filter traversal. | 2085 // filter traversal. |
| 2078 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 2086 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 2079 } | 2087 } |
| 2080 | 2088 |
| 2081 #endif | 2089 #endif |
| OLD | NEW |