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_Gpu.h" | 8 #include "SkSurface_Gpu.h" |
9 | 9 |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkGpuDevice.h" | 11 #include "SkGpuDevice.h" |
12 #include "SkImage_Base.h" | 12 #include "SkImage_Base.h" |
| 13 #include "SkImage_Gpu.h" |
13 #include "SkImagePriv.h" | 14 #include "SkImagePriv.h" |
14 #include "SkSurface_Base.h" | 15 #include "SkSurface_Base.h" |
15 | 16 |
16 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
17 | 18 |
18 /////////////////////////////////////////////////////////////////////////////// | 19 /////////////////////////////////////////////////////////////////////////////// |
19 | 20 |
20 SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device) | 21 SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device) |
21 : INHERITED(device->width(), device->height(), &device->surfaceProps()) | 22 : INHERITED(device->width(), device->height(), &device->surfaceProps()) |
22 , fDevice(SkRef(device)) { | 23 , fDevice(SkRef(device)) { |
(...skipping 15 matching lines...) Expand all Loading... |
38 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 39 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
39 int sampleCount = rt->numSamples(); | 40 int sampleCount = rt->numSamples(); |
40 // TODO: Make caller specify this (change virtual signature of onNewSurface)
. | 41 // TODO: Make caller specify this (change virtual signature of onNewSurface)
. |
41 static const Budgeted kBudgeted = kNo_Budgeted; | 42 static const Budgeted kBudgeted = kNo_Budgeted; |
42 return SkSurface::NewRenderTarget(fDevice->context(), kBudgeted, info, sampl
eCount, | 43 return SkSurface::NewRenderTarget(fDevice->context(), kBudgeted, info, sampl
eCount, |
43 &this->props()); | 44 &this->props()); |
44 } | 45 } |
45 | 46 |
46 SkImage* SkSurface_Gpu::onNewImageSnapshot(Budgeted budgeted) { | 47 SkImage* SkSurface_Gpu::onNewImageSnapshot(Budgeted budgeted) { |
47 const int sampleCount = fDevice->accessRenderTarget()->numSamples(); | 48 const int sampleCount = fDevice->accessRenderTarget()->numSamples(); |
48 SkImage* image = SkNewImageFromBitmapTexture(fDevice->accessBitmap(false), s
ampleCount, | 49 SkImage* image = NULL; |
49 budgeted); | 50 GrTexture* tex = fDevice->accessRenderTarget()->asTexture(); |
| 51 if (tex) { |
| 52 image = SkNEW_ARGS(SkImage_Gpu, |
| 53 (fDevice->width(), fDevice->height(), tex, sampleCoun
t, budgeted)); |
| 54 } |
50 if (image) { | 55 if (image) { |
51 as_IB(image)->initWithProps(this->props()); | 56 as_IB(image)->initWithProps(this->props()); |
52 } | 57 } |
53 return image; | 58 return image; |
54 } | 59 } |
55 | 60 |
56 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, | 61 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, |
57 const SkPaint* paint) { | 62 const SkPaint* paint) { |
58 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); | 63 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); |
59 } | 64 } |
60 | 65 |
61 // Create a new render target and, if necessary, copy the contents of the old | 66 // Create a new render target and, if necessary, copy the contents of the old |
62 // render target into it. Note that this flushes the SkGpuDevice but | 67 // render target into it. Note that this flushes the SkGpuDevice but |
63 // doesn't force an OpenGL flush. | 68 // doesn't force an OpenGL flush. |
64 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { | 69 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { |
65 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 70 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
66 // are we sharing our render target with the image? Note this call should ne
ver create a new | 71 // are we sharing our render target with the image? Note this call should ne
ver create a new |
67 // image because onCopyOnWrite is only called when there is a cached image. | 72 // image because onCopyOnWrite is only called when there is a cached image. |
68 SkImage* image = this->getCachedImage(kNo_Budgeted); | 73 SkImage* image = this->getCachedImage(kNo_Budgeted); |
69 SkASSERT(image); | 74 SkASSERT(image); |
70 if (rt->asTexture() == SkTextureImageGetTexture(image)) { | 75 if (rt->asTexture() == image->getTexture()) { |
71 this->fDevice->replaceRenderTarget(SkSurface::kRetain_ContentChangeMode
== mode); | 76 this->fDevice->replaceRenderTarget(SkSurface::kRetain_ContentChangeMode
== mode); |
72 SkTextureImageApplyBudgetedDecision(image); | 77 SkTextureImageApplyBudgetedDecision(image); |
73 } else if (kDiscard_ContentChangeMode == mode) { | 78 } else if (kDiscard_ContentChangeMode == mode) { |
74 this->SkSurface_Gpu::onDiscard(); | 79 this->SkSurface_Gpu::onDiscard(); |
75 } | 80 } |
76 } | 81 } |
77 | 82 |
78 void SkSurface_Gpu::onDiscard() { | 83 void SkSurface_Gpu::onDiscard() { |
79 fDevice->accessRenderTarget()->discard(); | 84 fDevice->accessRenderTarget()->discard(); |
80 } | 85 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 118 } |
114 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(surface->asRenderTarget
(), props, | 119 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(surface->asRenderTarget
(), props, |
115 SkGpuDevice::kNeedClear
_Flag)); | 120 SkGpuDevice::kNeedClear
_Flag)); |
116 if (!device) { | 121 if (!device) { |
117 return NULL; | 122 return NULL; |
118 } | 123 } |
119 return SkNEW_ARGS(SkSurface_Gpu, (device)); | 124 return SkNEW_ARGS(SkSurface_Gpu, (device)); |
120 } | 125 } |
121 | 126 |
122 #endif | 127 #endif |
OLD | NEW |