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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 const SkPaint* paint) { | 70 const SkPaint* paint) { |
71 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); | 71 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); |
72 } | 72 } |
73 | 73 |
74 // Create a new SkGpuDevice and, if necessary, copy the contents of the old | 74 // Create a new SkGpuDevice and, if necessary, copy the contents of the old |
75 // device into it. Note that this flushes the SkGpuDevice but | 75 // device into it. Note that this flushes the SkGpuDevice but |
76 // doesn't force an OpenGL flush. | 76 // doesn't force an OpenGL flush. |
77 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { | 77 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { |
78 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 78 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
79 // are we sharing our render target with the image? | 79 // are we sharing our render target with the image? |
80 SkASSERT(NULL != this->getCachedImage()); | 80 SkASSERT(this->getCachedImage()); |
81 if (rt->asTexture() == SkTextureImageGetTexture(this->getCachedImage())) { | 81 if (rt->asTexture() == SkTextureImageGetTexture(this->getCachedImage())) { |
82 // We call createCompatibleDevice because it uses the texture cache. Thi
s isn't | 82 // We call createCompatibleDevice because it uses the texture cache. Thi
s isn't |
83 // necessarily correct (http://skbug.com/2252), but never using the cach
e causes | 83 // necessarily correct (http://skbug.com/2252), but never using the cach
e causes |
84 // a Chromium regression. (http://crbug.com/344020) | 84 // a Chromium regression. (http://crbug.com/344020) |
85 SkGpuDevice* newDevice = static_cast<SkGpuDevice*>( | 85 SkGpuDevice* newDevice = static_cast<SkGpuDevice*>( |
86 fDevice->createCompatibleDevice(fDevice->imageInfo())); | 86 fDevice->createCompatibleDevice(fDevice->imageInfo())); |
87 SkAutoTUnref<SkGpuDevice> aurd(newDevice); | 87 SkAutoTUnref<SkGpuDevice> aurd(newDevice); |
88 if (kRetain_ContentChangeMode == mode) { | 88 if (kRetain_ContentChangeMode == mode) { |
89 fDevice->context()->copyTexture(rt->asTexture(), newDevice->accessRe
nderTarget()); | 89 fDevice->context()->copyTexture(rt->asTexture(), newDevice->accessRe
nderTarget()); |
90 } | 90 } |
91 SkASSERT(NULL != this->getCachedCanvas()); | 91 SkASSERT(this->getCachedCanvas()); |
92 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice); | 92 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice); |
93 | 93 |
94 this->getCachedCanvas()->setRootDevice(newDevice); | 94 this->getCachedCanvas()->setRootDevice(newDevice); |
95 SkRefCnt_SafeAssign(fDevice, newDevice); | 95 SkRefCnt_SafeAssign(fDevice, newDevice); |
96 } else if (kDiscard_ContentChangeMode == mode) { | 96 } else if (kDiscard_ContentChangeMode == mode) { |
97 this->SkSurface_Gpu::onDiscard(); | 97 this->SkSurface_Gpu::onDiscard(); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 void SkSurface_Gpu::onDiscard() { | 101 void SkSurface_Gpu::onDiscard() { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 desc.fSampleCnt = sampleCount; | 148 desc.fSampleCnt = sampleCount; |
149 | 149 |
150 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k
Exact_ScratchTexMatch)); | 150 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k
Exact_ScratchTexMatch)); |
151 | 151 |
152 if (NULL == tex) { | 152 if (NULL == tex) { |
153 return NULL; | 153 return NULL; |
154 } | 154 } |
155 | 155 |
156 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, trm, flags)); | 156 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, trm, flags)); |
157 } | 157 } |
OLD | NEW |