aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-01-18 20:57:22 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-01-18 20:57:22 +0000
commit2e7b43d33cc495663cb814a7a9d1ecdc09c31828 (patch)
tree10d01113bbac30d6e3b121d4a9ab5552a6567fd6 /src
parent44b2c73ca6358ba9c4a413d7b39db7991612a6a2 (diff)
Remove notion of default rendertarget. This doesn't map well to usage patterns outside sample app. Make binding between SkGpuDevice and a GrRenderTarget more explicit. Create method on GrContext to wrap the current target in the 3D API with a GrRenderTarget.
git-svn-id: http://skia.googlecode.com/svn/trunk@706 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/gpu/SkGpuCanvas.cpp9
-rw-r--r--src/gpu/SkGpuDevice.cpp66
-rw-r--r--src/utils/mac/SkOSWindow_Mac.cpp1
-rw-r--r--src/utils/win/SkOSWindow_Win.cpp3
4 files changed, 42 insertions, 37 deletions
diff --git a/src/gpu/SkGpuCanvas.cpp b/src/gpu/SkGpuCanvas.cpp
index 5ca1736264..9513bbd91f 100644
--- a/src/gpu/SkGpuCanvas.cpp
+++ b/src/gpu/SkGpuCanvas.cpp
@@ -23,11 +23,14 @@
///////////////////////////////////////////////////////////////////////////////
-static SkDeviceFactory* make_df(GrContext* context) {
- return SkNEW_ARGS(SkGpuDeviceFactory, (context));
+static SkDeviceFactory* make_df(GrContext* context,
+ GrRenderTarget* renderTarget) {
+ return SkNEW_ARGS(SkGpuDeviceFactory, (context, renderTarget));
}
-SkGpuCanvas::SkGpuCanvas(GrContext* context) : SkCanvas(make_df(context)) {
+SkGpuCanvas::SkGpuCanvas(GrContext* context,
+ GrRenderTarget* renderTarget)
+ : SkCanvas(make_df(context, renderTarget)) {
SkASSERT(context);
fContext = context;
fContext->ref();
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index d55f6f2211..f14de3545e 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -109,8 +109,14 @@ public:
///////////////////////////////////////////////////////////////////////////////
-SkGpuDevice::SkGpuDevice(GrContext* context, const SkBitmap& bitmap, bool isLayer)
- : SkDevice(NULL, bitmap, false) {
+GrRenderTarget* SkGpuDevice::Current3DApiRenderTarget() {
+ return (GrRenderTarget*) -1;
+}
+
+SkGpuDevice::SkGpuDevice(GrContext* context,
+ const SkBitmap& bitmap,
+ GrRenderTarget* renderTargetOrNull)
+ : SkDevice(NULL, bitmap, (NULL == renderTargetOrNull)) {
fNeedPrepareRenderTarget = false;
fDrawProcs = NULL;
@@ -123,7 +129,7 @@ SkGpuDevice::SkGpuDevice(GrContext* context, const SkBitmap& bitmap, bool isLaye
fRenderTarget = NULL;
fNeedClear = false;
- if (isLayer) {
+ if (NULL == renderTargetOrNull) {
SkBitmap::Config c = bitmap.config();
if (c != SkBitmap::kRGB_565_Config) {
c = SkBitmap::kARGB_8888_Config;
@@ -164,16 +170,13 @@ SkGpuDevice::SkGpuDevice(GrContext* context, const SkBitmap& bitmap, bool isLaye
} else {
GrPrintf("--- failed to create gpu-offscreen [%d %d]\n",
this->width(), this->height());
+ GrAssert(false);
}
- }
-
- if (NULL == fRenderTarget) {
- GrAssert(NULL == fCache);
- GrAssert(NULL == fTexture);
-
- fRenderTarget = fContext->currentRenderTarget();
+ } else if (Current3DApiRenderTarget() == renderTargetOrNull) {
+ fRenderTarget = fContext->createRenderTargetFrom3DApiState();
+ } else {
+ fRenderTarget = renderTargetOrNull;
fRenderTarget->ref();
- fContext->setDefaultRenderTargetSize(this->width(), this->height());
}
}
@@ -196,26 +199,6 @@ SkGpuDevice::~SkGpuDevice() {
}
}
-void SkGpuDevice::bindDeviceToTargetHandle(intptr_t handle) {
- if (fCache) {
- GrAssert(NULL != fTexture);
- GrAssert(fRenderTarget == fTexture->asRenderTarget());
- // IMPORTANT: reattach the rendertarget/tex back to the cache.
- fContext->reattachAndUnlockCachedTexture((GrTextureEntry*)fCache);
- } else if (NULL != fTexture) {
- GrAssert(!CACHE_LAYER_TEXTURES);
- fTexture->unref();
- } else if (NULL != fRenderTarget) {
- fRenderTarget->unref();
- }
-
- fCache = NULL;
- fTexture = NULL;
- fRenderTarget = fContext->createPlatformRenderTarget(handle,
- this->width(),
- this->height());
-}
-
intptr_t SkGpuDevice::getLayerTextureHandle() const {
if (fTexture) {
return fTexture->getTextureHandle();
@@ -1050,12 +1033,29 @@ void SkGpuDevice::unlockCachedTexture(TexCache* cache) {
///////////////////////////////////////////////////////////////////////////////
-SkGpuDeviceFactory::SkGpuDeviceFactory(GrContext* context) : fContext(context) {
+SkGpuDeviceFactory::SkGpuDeviceFactory(GrContext* context,
+ GrRenderTarget* rootRenderTarget)
+ : fContext(context) {
+
+ GrAssert(NULL != context);
+ GrAssert(NULL != rootRenderTarget);
+
+ // check this now rather than passing this value to SkGpuDevice cons.
+ // we want the rt that is bound *now* in the 3D API, not the one
+ // at the time of newDevice.
+ if (SkGpuDevice::Current3DApiRenderTarget() == rootRenderTarget) {
+ fRootRenderTarget = context->createRenderTargetFrom3DApiState();
+ } else {
+ fRootRenderTarget = rootRenderTarget;
+ rootRenderTarget->ref();
+ }
context->ref();
+
}
SkGpuDeviceFactory::~SkGpuDeviceFactory() {
fContext->unref();
+ fRootRenderTarget->unref();
}
SkDevice* SkGpuDeviceFactory::newDevice(SkCanvas*, SkBitmap::Config config,
@@ -1064,6 +1064,6 @@ SkDevice* SkGpuDeviceFactory::newDevice(SkCanvas*, SkBitmap::Config config,
SkBitmap bm;
bm.setConfig(config, width, height);
bm.setIsOpaque(isOpaque);
- return new SkGpuDevice(fContext, bm, isLayer);
+ return new SkGpuDevice(fContext, bm, isLayer ? NULL : fRootRenderTarget);
}
diff --git a/src/utils/mac/SkOSWindow_Mac.cpp b/src/utils/mac/SkOSWindow_Mac.cpp
index 6828a955f0..d4ef7e97b0 100644
--- a/src/utils/mac/SkOSWindow_Mac.cpp
+++ b/src/utils/mac/SkOSWindow_Mac.cpp
@@ -512,6 +512,7 @@ bool SkOSWindow::attachGL(const SkBitmap* offscreen)
if (success) {
glClearColor(0, 0, 0, 0);
+ glClearStencil(0);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}
return success;
diff --git a/src/utils/win/SkOSWindow_Win.cpp b/src/utils/win/SkOSWindow_Win.cpp
index 40455d2114..53449b1c51 100644
--- a/src/utils/win/SkOSWindow_Win.cpp
+++ b/src/utils/win/SkOSWindow_Win.cpp
@@ -439,7 +439,8 @@ bool SkOSWindow::attachGL(const SkBitmap* offscreen) {
}
if (wglMakeCurrent(GetDC((HWND)fHWND), (HGLRC)fHGLRC)) {
glClearColor(0, 0, 0, 0);
- glClear(GL_COLOR_BUFFER_BIT);
+ glClearStencil(0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
fGLAttached = true;
return true;
}