| 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" |
| 11 #include "SkGpuDevice.h" | 11 #include "SkGpuDevice.h" |
| 12 | 12 |
| 13 class SkSurface_Gpu : public SkSurface_Base { | 13 class SkSurface_Gpu : public SkSurface_Base { |
| 14 public: | 14 public: |
| 15 SK_DECLARE_INST_COUNT(SkSurface_Gpu) | 15 SK_DECLARE_INST_COUNT(SkSurface_Gpu) |
| 16 | 16 |
| 17 SkSurface_Gpu(GrContext*, const SkImageInfo&, int sampleCount); | |
| 18 SkSurface_Gpu(GrRenderTarget*); | 17 SkSurface_Gpu(GrRenderTarget*); |
| 19 virtual ~SkSurface_Gpu(); | 18 virtual ~SkSurface_Gpu(); |
| 20 | 19 |
| 21 virtual SkCanvas* onNewCanvas() SK_OVERRIDE; | 20 virtual SkCanvas* onNewCanvas() SK_OVERRIDE; |
| 22 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; | 21 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; |
| 23 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE; | 22 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE; |
| 24 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, | 23 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, |
| 25 const SkPaint*) SK_OVERRIDE; | 24 const SkPaint*) SK_OVERRIDE; |
| 26 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; | 25 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; |
| 27 | 26 |
| 28 private: | 27 private: |
| 29 SkGpuDevice* fDevice; | 28 SkGpuDevice* fDevice; |
| 30 | 29 |
| 31 typedef SkSurface_Base INHERITED; | 30 typedef SkSurface_Base INHERITED; |
| 32 }; | 31 }; |
| 33 | 32 |
| 34 /////////////////////////////////////////////////////////////////////////////// | 33 /////////////////////////////////////////////////////////////////////////////// |
| 35 | 34 |
| 36 SkSurface_Gpu::SkSurface_Gpu(GrContext* ctx, const SkImageInfo& info, | |
| 37 int sampleCount) | |
| 38 : INHERITED(info.fWidth, info.fHeight) { | |
| 39 SkBitmap::Config config = SkImageInfoToBitmapConfig(info); | |
| 40 | |
| 41 fDevice = SkNEW_ARGS(SkGpuDevice, (ctx, config, info.fWidth, info.fHeight, s
ampleCount)); | |
| 42 | |
| 43 if (!SkAlphaTypeIsOpaque(info.fAlphaType)) { | |
| 44 fDevice->clear(0x0); | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget) | 35 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget) |
| 49 : INHERITED(renderTarget->width(), renderTarget->height()) { | 36 : INHERITED(renderTarget->width(), renderTarget->height()) { |
| 50 fDevice = SkNEW_ARGS(SkGpuDevice, (renderTarget->getContext(), renderTarget)
); | 37 fDevice = SkNEW_ARGS(SkGpuDevice, (renderTarget->getContext(), renderTarget)
); |
| 51 | 38 |
| 52 if (kRGB_565_GrPixelConfig != renderTarget->config()) { | 39 if (kRGB_565_GrPixelConfig != renderTarget->config()) { |
| 53 fDevice->clear(0x0); | 40 fDevice->clear(0x0); |
| 54 } | 41 } |
| 55 } | 42 } |
| 56 | 43 |
| 57 SkSurface_Gpu::~SkSurface_Gpu() { | 44 SkSurface_Gpu::~SkSurface_Gpu() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 78 } | 65 } |
| 79 | 66 |
| 80 // Create a new SkGpuDevice and, if necessary, copy the contents of the old | 67 // Create a new SkGpuDevice and, if necessary, copy the contents of the old |
| 81 // device into it. Note that this flushes the SkGpuDevice but | 68 // device into it. Note that this flushes the SkGpuDevice but |
| 82 // doesn't force an OpenGL flush. | 69 // doesn't force an OpenGL flush. |
| 83 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { | 70 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { |
| 84 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 71 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
| 85 // are we sharing our render target with the image? | 72 // are we sharing our render target with the image? |
| 86 SkASSERT(NULL != this->getCachedImage()); | 73 SkASSERT(NULL != this->getCachedImage()); |
| 87 if (rt->asTexture() == SkTextureImageGetTexture(this->getCachedImage())) { | 74 if (rt->asTexture() == SkTextureImageGetTexture(this->getCachedImage())) { |
| 88 SkAutoTUnref<SkGpuDevice> newDevice(SkNEW_ARGS(SkGpuDevice, | 75 SkAutoTUnref<SkGpuDevice> newDevice(SkGpuDevice::Create(fDevice->context
(), |
| 89 (fDevice->context(), fDevice->config(), fDevice->width(), | 76 fDevice->imageInfo(), |
| 90 fDevice->height(), rt->numSamples()))); | 77 rt->numSamples())); |
| 78 SkASSERT(newDevice.get()); |
| 91 | 79 |
| 92 if (kRetain_ContentChangeMode == mode) { | 80 if (kRetain_ContentChangeMode == mode) { |
| 93 fDevice->context()->copyTexture(rt->asTexture(), | 81 fDevice->context()->copyTexture(rt->asTexture(), |
| 94 reinterpret_cast<GrRenderTarget*>(newDevice->accessRenderTarget(
))); | 82 reinterpret_cast<GrRenderTarget*>(newDevice->accessRenderTarget(
))); |
| 95 } | 83 } |
| 96 SkASSERT(NULL != this->getCachedCanvas()); | 84 SkASSERT(NULL != this->getCachedCanvas()); |
| 97 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice); | 85 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice); |
| 98 this->getCachedCanvas()->setDevice(newDevice); | 86 this->getCachedCanvas()->setDevice(newDevice); |
| 99 SkRefCnt_SafeAssign(fDevice, newDevice.get()); | 87 SkRefCnt_SafeAssign(fDevice, newDevice.get()); |
| 100 } | 88 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 123 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); | 111 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); |
| 124 desc.fSampleCnt = sampleCount; | 112 desc.fSampleCnt = sampleCount; |
| 125 | 113 |
| 126 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); | 114 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); |
| 127 if (NULL == tex) { | 115 if (NULL == tex) { |
| 128 return NULL; | 116 return NULL; |
| 129 } | 117 } |
| 130 | 118 |
| 131 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget())); | 119 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget())); |
| 132 } | 120 } |
| OLD | NEW |