| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkSurface_Base.h" | 8 #include "SkSurface_Base.h" |
| 9 #include "SkImagePriv.h" | 9 #include "SkImagePriv.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 SkSurface_Gpu::~SkSurface_Gpu() { | 60 SkSurface_Gpu::~SkSurface_Gpu() { |
| 61 SkSafeUnref(fDevice); | 61 SkSafeUnref(fDevice); |
| 62 } | 62 } |
| 63 | 63 |
| 64 SkCanvas* SkSurface_Gpu::onNewCanvas() { | 64 SkCanvas* SkSurface_Gpu::onNewCanvas() { |
| 65 return SkNEW_ARGS(SkCanvas, (fDevice)); | 65 return SkNEW_ARGS(SkCanvas, (fDevice)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 SkSurface* SkSurface_Gpu::onNewSurface(const SkImage::Info& info) { | 68 SkSurface* SkSurface_Gpu::onNewSurface(const SkImage::Info& info) { |
| 69 GrRenderTarget* rt = (GrRenderTarget*) fDevice->accessRenderTarget(); | 69 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
| 70 int sampleCount = rt->numSamples(); | 70 int sampleCount = rt->numSamples(); |
| 71 return SkSurface::NewRenderTarget(fDevice->context(), info, sampleCount); | 71 return SkSurface::NewRenderTarget(fDevice->context(), info, sampleCount); |
| 72 } | 72 } |
| 73 | 73 |
| 74 SkImage* SkSurface_Gpu::onNewImageSnapshot() { | 74 SkImage* SkSurface_Gpu::onNewImageSnapshot() { |
| 75 | 75 |
| 76 GrRenderTarget* rt = (GrRenderTarget*) fDevice->accessRenderTarget(); | 76 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
| 77 | 77 |
| 78 return SkImage::NewTexture(rt->asTexture()); | 78 return SkImage::NewTexture(rt->asTexture()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, | 81 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, |
| 82 const SkPaint* paint) { | 82 const SkPaint* paint) { |
| 83 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); | 83 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Create a new SkGpuDevice and, if necessary, copy the contents of the old | 86 // Create a new SkGpuDevice and, if necessary, copy the contents of the old |
| 87 // device into it. Note that this flushes the SkGpuDevice but | 87 // device into it. Note that this flushes the SkGpuDevice but |
| 88 // doesn't force an OpenGL flush. | 88 // doesn't force an OpenGL flush. |
| 89 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { | 89 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { |
| 90 GrRenderTarget* rt = (GrRenderTarget*) fDevice->accessRenderTarget(); | 90 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
| 91 // are we sharing our render target with the image? | 91 // are we sharing our render target with the image? |
| 92 SkASSERT(NULL != this->getCachedImage()); | 92 SkASSERT(NULL != this->getCachedImage()); |
| 93 if (rt->asTexture() == SkTextureImageGetTexture(this->getCachedImage())) { | 93 if (rt->asTexture() == SkTextureImageGetTexture(this->getCachedImage())) { |
| 94 SkGpuDevice* newDevice = static_cast<SkGpuDevice*>( | 94 SkGpuDevice* newDevice = static_cast<SkGpuDevice*>( |
| 95 fDevice->createCompatibleDevice(fDevice->config(), fDevice->width(), | 95 fDevice->createCompatibleDevice(fDevice->config(), fDevice->width(), |
| 96 fDevice->height(), fDevice->isOpaque())); | 96 fDevice->height(), fDevice->isOpaque())); |
| 97 SkAutoTUnref<SkGpuDevice> aurd(newDevice); | 97 SkAutoTUnref<SkGpuDevice> aurd(newDevice); |
| 98 if (kRetain_ContentChangeMode == mode) { | 98 if (kRetain_ContentChangeMode == mode) { |
| 99 fDevice->context()->copyTexture(rt->asTexture(), | 99 fDevice->context()->copyTexture(rt->asTexture(), |
| 100 reinterpret_cast<GrRenderTarget*>(newDevice->accessRenderTarget(
))); | 100 reinterpret_cast<GrRenderTarget*>(newDevice->accessRenderTarget(
))); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); | 132 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); |
| 133 desc.fSampleCnt = sampleCount; | 133 desc.fSampleCnt = sampleCount; |
| 134 | 134 |
| 135 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); | 135 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); |
| 136 if (NULL == tex) { | 136 if (NULL == tex) { |
| 137 return NULL; | 137 return NULL; |
| 138 } | 138 } |
| 139 | 139 |
| 140 return SkNEW_ARGS(SkSurface_Gpu, (ctx, tex->asRenderTarget())); | 140 return SkNEW_ARGS(SkSurface_Gpu, (ctx, tex->asRenderTarget())); |
| 141 } | 141 } |
| OLD | NEW |