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 1725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1736 // must be pushed upstack. | 1736 // must be pushed upstack. |
1737 AutoBitmapTexture abt(fContext, src, NULL, &texture); | 1737 AutoBitmapTexture abt(fContext, src, NULL, &texture); |
1738 if (!texture) { | 1738 if (!texture) { |
1739 return false; | 1739 return false; |
1740 } | 1740 } |
1741 | 1741 |
1742 return this->filterTexture(fContext, texture, src.width(), src.height(), | 1742 return this->filterTexture(fContext, texture, src.width(), src.height(), |
1743 filter, ctx, result, offset); | 1743 filter, ctx, result, offset); |
1744 } | 1744 } |
1745 | 1745 |
| 1746 #include "SkImage_Base.h" |
| 1747 |
| 1748 static SkImageInfo make_info(GrTexture* tex, int w, int h, bool isOpaque) { |
| 1749 const GrPixelConfig config = tex->config(); |
| 1750 SkColorType ct; |
| 1751 SkAlphaType at = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
| 1752 if (!GrPixelConfig2ColorAndProfileType(config, &ct, NULL)) { |
| 1753 ct = kUnknown_SkColorType; |
| 1754 } |
| 1755 return SkImageInfo::Make(w, h, ct, at); |
| 1756 } |
| 1757 |
| 1758 static bool wrap_as_bm(const SkImage* image, SkBitmap* bm) { |
| 1759 GrTexture* tex = image->getTexture(); |
| 1760 if (tex) { |
| 1761 // TODO: handle the GrTexture directly, and skip GrPixelRef |
| 1762 const SkImageInfo info = make_info(tex, image->width(), image->height(),
image->isOpaque()); |
| 1763 bm->setInfo(info); |
| 1764 bm->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, tex)))->unref(); |
| 1765 } else { |
| 1766 if (!as_IB(image)->getROPixels(bm)) { |
| 1767 return false; |
| 1768 } |
| 1769 } |
| 1770 return true; |
| 1771 } |
| 1772 |
| 1773 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x
, SkScalar y, |
| 1774 const SkPaint& paint) { |
| 1775 SkBitmap bm; |
| 1776 if (wrap_as_bm(image, &bm)) { |
| 1777 this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); |
| 1778 } |
| 1779 } |
| 1780 |
| 1781 void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const
SkRect* src, |
| 1782 const SkRect& dst, const SkPaint& paint) { |
| 1783 SkBitmap bm; |
| 1784 if (wrap_as_bm(image, &bm)) { |
| 1785 this->drawBitmapRect(draw, bm, src, dst, paint, SkCanvas::DrawBitmapRect
Flags(0)); |
| 1786 } |
| 1787 } |
| 1788 |
1746 /////////////////////////////////////////////////////////////////////////////// | 1789 /////////////////////////////////////////////////////////////////////////////// |
1747 | 1790 |
1748 // must be in SkCanvas::VertexMode order | 1791 // must be in SkCanvas::VertexMode order |
1749 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { | 1792 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { |
1750 kTriangles_GrPrimitiveType, | 1793 kTriangles_GrPrimitiveType, |
1751 kTriangleStrip_GrPrimitiveType, | 1794 kTriangleStrip_GrPrimitiveType, |
1752 kTriangleFan_GrPrimitiveType, | 1795 kTriangleFan_GrPrimitiveType, |
1753 }; | 1796 }; |
1754 | 1797 |
1755 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, | 1798 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2043 #endif | 2086 #endif |
2044 } | 2087 } |
2045 | 2088 |
2046 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 2089 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
2047 // We always return a transient cache, so it is freed after each | 2090 // We always return a transient cache, so it is freed after each |
2048 // filter traversal. | 2091 // filter traversal. |
2049 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 2092 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
2050 } | 2093 } |
2051 | 2094 |
2052 #endif | 2095 #endif |
OLD | NEW |