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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 } | 78 } |
79 | 79 |
80 // Create a new SkGpuDevice and, if necessary, copy the contents of the old | 80 // Create a new SkGpuDevice and, if necessary, copy the contents of the old |
81 // device into it. Note that this flushes the SkGpuDevice but | 81 // device into it. Note that this flushes the SkGpuDevice but |
82 // doesn't force an OpenGL flush. | 82 // doesn't force an OpenGL flush. |
83 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { | 83 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { |
84 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 84 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
85 // are we sharing our render target with the image? | 85 // are we sharing our render target with the image? |
86 SkASSERT(NULL != this->getCachedImage()); | 86 SkASSERT(NULL != this->getCachedImage()); |
87 if (rt->asTexture() == SkTextureImageGetTexture(this->getCachedImage())) { | 87 if (rt->asTexture() == SkTextureImageGetTexture(this->getCachedImage())) { |
88 SkGpuDevice* newDevice = static_cast<SkGpuDevice*>( | 88 SkAutoTUnref<SkGpuDevice> newDevice(SkNEW_ARGS(SkGpuDevice, |
89 fDevice->createCompatibleDevice(fDevice->config(), fDevice->width(), | 89 (fDevice->context(), fDevice->config(), fDevice->width(), |
90 fDevice->height(), fDevice->isOpaque())); | 90 fDevice->height(), rt->numSamples()))); |
91 SkAutoTUnref<SkGpuDevice> aurd(newDevice); | 91 |
92 if (kRetain_ContentChangeMode == mode) { | 92 if (kRetain_ContentChangeMode == mode) { |
93 fDevice->context()->copyTexture(rt->asTexture(), | 93 fDevice->context()->copyTexture(rt->asTexture(), |
94 reinterpret_cast<GrRenderTarget*>(newDevice->accessRenderTarget(
))); | 94 reinterpret_cast<GrRenderTarget*>(newDevice->accessRenderTarget(
))); |
95 } | 95 } |
96 SkASSERT(NULL != this->getCachedCanvas()); | 96 SkASSERT(NULL != this->getCachedCanvas()); |
97 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice); | 97 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice); |
98 this->getCachedCanvas()->setDevice(newDevice); | 98 this->getCachedCanvas()->setDevice(newDevice); |
99 SkRefCnt_SafeAssign(fDevice, newDevice); | 99 SkRefCnt_SafeAssign(fDevice, newDevice.get()); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 /////////////////////////////////////////////////////////////////////////////// | 103 /////////////////////////////////////////////////////////////////////////////// |
104 | 104 |
105 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target) { | 105 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target) { |
106 if (NULL == target) { | 106 if (NULL == target) { |
107 return NULL; | 107 return NULL; |
108 } | 108 } |
109 return SkNEW_ARGS(SkSurface_Gpu, (target)); | 109 return SkNEW_ARGS(SkSurface_Gpu, (target)); |
(...skipping 21 matching lines...) Expand all Loading... |
131 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); | 131 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); |
132 desc.fSampleCnt = sampleCount; | 132 desc.fSampleCnt = sampleCount; |
133 | 133 |
134 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); | 134 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); |
135 if (NULL == tex) { | 135 if (NULL == tex) { |
136 return NULL; | 136 return NULL; |
137 } | 137 } |
138 | 138 |
139 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget())); | 139 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget())); |
140 } | 140 } |
OLD | NEW |