| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 at = kPremul_SkAlphaType; // force this setting | 192 at = kPremul_SkAlphaType; // force this setting |
| 193 } | 193 } |
| 194 const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height
(), ct, at); | 194 const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height
(), ct, at); |
| 195 | 195 |
| 196 GrSurfaceDesc desc; | 196 GrSurfaceDesc desc; |
| 197 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 197 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 198 desc.fWidth = info.width(); | 198 desc.fWidth = info.width(); |
| 199 desc.fHeight = info.height(); | 199 desc.fHeight = info.height(); |
| 200 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 200 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
| 201 desc.fSampleCnt = sampleCount; | 201 desc.fSampleCnt = sampleCount; |
| 202 GrTexture* texture = context->createTexture(desc, SkToBool(budgeted), NULL,
0); | 202 GrTexture* texture = context->textureProvider()->createTexture( |
| 203 desc, SkToBool(budgeted), NULL, 0); |
| 203 if (NULL == texture) { | 204 if (NULL == texture) { |
| 204 return NULL; | 205 return NULL; |
| 205 } | 206 } |
| 206 SkASSERT(NULL != texture->asRenderTarget()); | 207 SkASSERT(NULL != texture->asRenderTarget()); |
| 207 return texture->asRenderTarget(); | 208 return texture->asRenderTarget(); |
| 208 } | 209 } |
| 209 | 210 |
| 210 SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete
d, | 211 SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete
d, |
| 211 const SkImageInfo& info, int sampleCount, | 212 const SkImageInfo& info, int sampleCount, |
| 212 const SkSurfaceProps* props, unsigned flags) { | 213 const SkSurfaceProps* props, unsigned flags) { |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 return false; | 693 return false; |
| 693 } | 694 } |
| 694 | 695 |
| 695 // we now have a device-aligned 8bit mask in dstM, ready to be drawn using | 696 // we now have a device-aligned 8bit mask in dstM, ready to be drawn using |
| 696 // the current clip (and identity matrix) and GrPaint settings | 697 // the current clip (and identity matrix) and GrPaint settings |
| 697 GrSurfaceDesc desc; | 698 GrSurfaceDesc desc; |
| 698 desc.fWidth = dstM.fBounds.width(); | 699 desc.fWidth = dstM.fBounds.width(); |
| 699 desc.fHeight = dstM.fBounds.height(); | 700 desc.fHeight = dstM.fBounds.height(); |
| 700 desc.fConfig = kAlpha_8_GrPixelConfig; | 701 desc.fConfig = kAlpha_8_GrPixelConfig; |
| 701 | 702 |
| 702 SkAutoTUnref<GrTexture> texture( | 703 SkAutoTUnref<GrTexture> texture(context->textureProvider()->refScratchTextur
e( |
| 703 context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); | 704 desc, GrTextureProvider::kApprox_ScratchTexMatch)); |
| 704 if (!texture) { | 705 if (!texture) { |
| 705 return false; | 706 return false; |
| 706 } | 707 } |
| 707 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, | 708 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, |
| 708 dstM.fImage, dstM.fRowBytes); | 709 dstM.fImage, dstM.fRowBytes); |
| 709 | 710 |
| 710 SkRect maskRect = SkRect::Make(dstM.fBounds); | 711 SkRect maskRect = SkRect::Make(dstM.fBounds); |
| 711 | 712 |
| 712 return draw_mask(context, rt, clipData, viewMatrix, maskRect, grp, texture); | 713 return draw_mask(context, rt, clipData, viewMatrix, maskRect, grp, texture); |
| 713 } | 714 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 727 desc.fSampleCnt = doAA ? sampleCnt : 0; | 728 desc.fSampleCnt = doAA ? sampleCnt : 0; |
| 728 // We actually only need A8, but it often isn't supported as a | 729 // We actually only need A8, but it often isn't supported as a |
| 729 // render target so default to RGBA_8888 | 730 // render target so default to RGBA_8888 |
| 730 desc.fConfig = kRGBA_8888_GrPixelConfig; | 731 desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 731 | 732 |
| 732 if (context->isConfigRenderable(kAlpha_8_GrPixelConfig, | 733 if (context->isConfigRenderable(kAlpha_8_GrPixelConfig, |
| 733 desc.fSampleCnt > 0)) { | 734 desc.fSampleCnt > 0)) { |
| 734 desc.fConfig = kAlpha_8_GrPixelConfig; | 735 desc.fConfig = kAlpha_8_GrPixelConfig; |
| 735 } | 736 } |
| 736 | 737 |
| 737 GrTexture* mask = context->refScratchTexture(desc,GrContext::kApprox_Scratch
TexMatch); | 738 GrTexture* mask = context->textureProvider()->refScratchTexture( |
| 739 desc, GrTextureProvider::kApprox_ScratchTexMatch); |
| 738 if (NULL == mask) { | 740 if (NULL == mask) { |
| 739 return NULL; | 741 return NULL; |
| 740 } | 742 } |
| 741 | 743 |
| 742 SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height()); | 744 SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height()); |
| 743 | 745 |
| 744 context->clear(NULL, 0x0, true, mask->asRenderTarget()); | 746 context->clear(NULL, 0x0, true, mask->asRenderTarget()); |
| 745 | 747 |
| 746 GrPaint tempPaint; | 748 GrPaint tempPaint; |
| 747 tempPaint.setAntiAlias(doAA); | 749 tempPaint.setAntiAlias(doAA); |
| (...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1941 desc.fWidth = cinfo.fInfo.width(); | 1943 desc.fWidth = cinfo.fInfo.width(); |
| 1942 desc.fHeight = cinfo.fInfo.height(); | 1944 desc.fHeight = cinfo.fInfo.height(); |
| 1943 desc.fSampleCnt = fRenderTarget->numSamples(); | 1945 desc.fSampleCnt = fRenderTarget->numSamples(); |
| 1944 | 1946 |
| 1945 SkAutoTUnref<GrTexture> texture; | 1947 SkAutoTUnref<GrTexture> texture; |
| 1946 // Skia's convention is to only clear a device if it is non-opaque. | 1948 // Skia's convention is to only clear a device if it is non-opaque. |
| 1947 unsigned flags = cinfo.fInfo.isOpaque() ? 0 : kNeedClear_Flag; | 1949 unsigned flags = cinfo.fInfo.isOpaque() ? 0 : kNeedClear_Flag; |
| 1948 | 1950 |
| 1949 // layers are never draw in repeat modes, so we can request an approx | 1951 // layers are never draw in repeat modes, so we can request an approx |
| 1950 // match and ignore any padding. | 1952 // match and ignore any padding. |
| 1951 const GrContext::ScratchTexMatch match = (kNever_TileUsage == cinfo.fTileUsa
ge) ? | 1953 const GrTextureProvider::ScratchTexMatch match = (kNever_TileUsage == cinfo.
fTileUsage) ? |
| 1952 GrContext::kApprox_ScratchTexMat
ch : | 1954 GrTextureProvider::kApprox_Scr
atchTexMatch : |
| 1953 GrContext::kExact_ScratchTexMatc
h; | 1955 GrTextureProvider::kExact_Scra
tchTexMatch; |
| 1954 texture.reset(fContext->refScratchTexture(desc, match)); | 1956 texture.reset(fContext->textureProvider()->refScratchTexture(desc, match)); |
| 1955 | 1957 |
| 1956 if (texture) { | 1958 if (texture) { |
| 1957 SkSurfaceProps props(fSurfaceProps.flags(), cinfo.fPixelGeometry); | 1959 SkSurfaceProps props(fSurfaceProps.flags(), cinfo.fPixelGeometry); |
| 1958 return SkGpuDevice::Create( | 1960 return SkGpuDevice::Create( |
| 1959 texture->asRenderTarget(), cinfo.fInfo.width(), cinfo.fInfo.height()
, &props, flags); | 1961 texture->asRenderTarget(), cinfo.fInfo.width(), cinfo.fInfo.height()
, &props, flags); |
| 1960 } else { | 1962 } else { |
| 1961 SkErrorInternals::SetError( kInternalError_SkError, | 1963 SkErrorInternals::SetError( kInternalError_SkError, |
| 1962 "---- failed to create gpu device texture [%
d %d]\n", | 1964 "---- failed to create gpu device texture [%
d %d]\n", |
| 1963 cinfo.fInfo.width(), cinfo.fInfo.height()); | 1965 cinfo.fInfo.width(), cinfo.fInfo.height()); |
| 1964 return NULL; | 1966 return NULL; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2038 #endif | 2040 #endif |
| 2039 } | 2041 } |
| 2040 | 2042 |
| 2041 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 2043 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 2042 // We always return a transient cache, so it is freed after each | 2044 // We always return a transient cache, so it is freed after each |
| 2043 // filter traversal. | 2045 // filter traversal. |
| 2044 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 2046 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 2045 } | 2047 } |
| 2046 | 2048 |
| 2047 #endif | 2049 #endif |
| OLD | NEW |