Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: cc/output/gl_renderer.cc

Issue 520793002: Use SkSurface and SkImage instead of SkGpuDevice and SkBitmap in cc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove #include in resource_provider.cc Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | cc/resources/resource_provider.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/output/gl_renderer.cc
diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc
index d14feb6abf50053380bb4785909a3e12352e71bf..58b2a35ff36d564aca11565edeb58fc2af2d0671 100644
--- a/cc/output/gl_renderer.cc
+++ b/cc/output/gl_renderer.cc
@@ -36,10 +36,10 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkColorFilter.h"
+#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrTexture.h"
-#include "third_party/skia/include/gpu/SkGpuDevice.h"
#include "third_party/skia/include/gpu/SkGrTexturePixelRef.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
#include "ui/gfx/geometry/quad_f.h"
@@ -610,7 +610,7 @@ void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame,
GLC(gl_, gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0));
}
-static SkBitmap ApplyImageFilter(
+static SkImage* ApplyImageFilter(
scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context,
ResourceProvider* resource_provider,
const gfx::Point& origin,
@@ -618,10 +618,10 @@ static SkBitmap ApplyImageFilter(
SkImageFilter* filter,
ScopedResource* source_texture_resource) {
if (!filter)
- return SkBitmap();
+ return NULL;
if (!use_gr_context)
- return SkBitmap();
+ return NULL;
ResourceProvider::ScopedReadLockGL lock(resource_provider,
source_texture_resource->id());
@@ -664,36 +664,37 @@ static SkBitmap ApplyImageFilter(
TRACE_EVENT_INSTANT0("cc",
"ApplyImageFilter scratch texture allocation failed",
TRACE_EVENT_SCOPE_THREAD);
- return SkBitmap();
+ return NULL;
}
- // Create a device and canvas using that backing store.
- skia::RefPtr<SkGpuDevice> device =
- skia::AdoptRef(SkGpuDevice::Create(backing_store->asRenderTarget()));
- DCHECK(device.get());
- SkCanvas canvas(device.get());
+ // Create surface to draw into.
+ skia::RefPtr<SkSurface> surface = skia::AdoptRef(
+ SkSurface::NewRenderTargetDirect(backing_store->asRenderTarget()));
+ SkCanvas* canvas = surface->getCanvas();
// Draw the source bitmap through the filter to the canvas.
SkPaint paint;
paint.setImageFilter(filter);
- canvas.clear(SK_ColorTRANSPARENT);
+ canvas->clear(SK_ColorTRANSPARENT);
- canvas.translate(SkIntToScalar(-origin.x()), SkIntToScalar(-origin.y()));
- canvas.scale(scale.x(), scale.y());
- canvas.drawSprite(source, 0, 0, &paint);
+ canvas->translate(SkIntToScalar(-origin.x()), SkIntToScalar(-origin.y()));
+ canvas->scale(scale.x(), scale.y());
+ canvas->drawSprite(source, 0, 0, &paint);
+
+ SkImage* image = surface->newImageSnapshot();
// Flush the GrContext to ensure all buffered GL calls are drawn to the
// backing store before we access and return it, and have cc begin using the
// GL context again.
- use_gr_context->context()->flush();
+ canvas->flush();
- return device->accessBitmap(false);
+ return image;
}
-static SkBitmap ApplyBlendModeWithBackdrop(
+static SkImage* ApplyBlendModeWithBackdrop(
scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context,
ResourceProvider* resource_provider,
- SkBitmap source_bitmap_with_filters,
+ SkImage* source_bitmap_with_filters,
ScopedResource* source_texture_resource,
ScopedResource* background_texture_resource,
SkXfermode::Mode blend_mode) {
@@ -711,11 +712,11 @@ static SkBitmap ApplyBlendModeWithBackdrop(
int source_texture_with_filters_id;
scoped_ptr<ResourceProvider::ScopedReadLockGL> lock;
- if (source_bitmap_with_filters.getTexture()) {
- DCHECK_EQ(source_size.width(), source_bitmap_with_filters.width());
- DCHECK_EQ(source_size.height(), source_bitmap_with_filters.height());
+ if (source_bitmap_with_filters) {
+ DCHECK_EQ(source_size.width(), source_bitmap_with_filters->width());
+ DCHECK_EQ(source_size.height(), source_bitmap_with_filters->height());
GrTexture* texture =
- reinterpret_cast<GrTexture*>(source_bitmap_with_filters.getTexture());
+ reinterpret_cast<GrTexture*>(source_bitmap_with_filters->getTexture());
source_texture_with_filters_id = texture->getTextureHandle();
} else {
lock.reset(new ResourceProvider::ScopedReadLockGL(
@@ -785,24 +786,26 @@ static SkBitmap ApplyBlendModeWithBackdrop(
}
// Create a device and canvas using that backing store.
- skia::RefPtr<SkGpuDevice> device =
- skia::AdoptRef(SkGpuDevice::Create(backing_store->asRenderTarget()));
- DCHECK(device.get());
- SkCanvas canvas(device.get());
+ skia::RefPtr<SkSurface> surface = skia::AdoptRef(
+ SkSurface::NewRenderTargetDirect(backing_store->asRenderTarget()));
+ if (!surface)
+ return NULL;
+ SkCanvas* canvas = surface->getCanvas();
// Draw the source bitmap through the filter to the canvas.
- canvas.clear(SK_ColorTRANSPARENT);
- canvas.drawSprite(background, 0, 0);
+ canvas->clear(SK_ColorTRANSPARENT);
+ canvas->drawSprite(background, 0, 0);
SkPaint paint;
paint.setXfermodeMode(blend_mode);
- canvas.drawSprite(source, 0, 0, &paint);
+ canvas->drawSprite(source, 0, 0, &paint);
+ SkImage* image = surface->newImageSnapshot();
enne (OOO) 2014/08/29 19:05:40 After fixing numerous memory leaks, I'm a little a
bsalomon 2014/08/29 20:47:33 I tried in the new patch. I've never used these be
enne (OOO) 2014/08/29 21:20:21 Thanks. Those usages look right to me, based on w
// Flush the GrContext to ensure all buffered GL calls are drawn to the
// backing store before we access and return it, and have cc begin using the
// GL context again.
- use_gr_context->context()->flush();
+ canvas->flush();
- return device->accessBitmap(false);
+ return image;
}
scoped_ptr<ScopedResource> GLRenderer::GetBackgroundWithFilters(
@@ -873,23 +876,22 @@ scoped_ptr<ScopedResource> GLRenderer::GetBackgroundWithFilters(
skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter(
quad->background_filters, device_background_texture->size());
- SkBitmap filtered_device_background;
+ skia::RefPtr<SkImage> filtered_device_background;
if (apply_background_filters) {
filtered_device_background =
- ApplyImageFilter(ScopedUseGrContext::Create(this, frame),
- resource_provider_,
- quad->rect.origin(),
- quad->filters_scale,
- filter.get(),
- device_background_texture.get());
+ skia::AdoptRef(ApplyImageFilter(ScopedUseGrContext::Create(this, frame),
+ resource_provider_,
+ quad->rect.origin(),
+ quad->filters_scale,
+ filter.get(),
+ device_background_texture.get()));
}
- *background_changed = (filtered_device_background.getTexture() != NULL);
+ *background_changed = (filtered_device_background != NULL);
int filtered_device_background_texture_id = 0;
scoped_ptr<ResourceProvider::ScopedReadLockGL> lock;
- if (filtered_device_background.getTexture()) {
- GrTexture* texture =
- reinterpret_cast<GrTexture*>(filtered_device_background.getTexture());
+ if (filtered_device_background) {
+ GrTexture* texture = filtered_device_background->getTexture();
filtered_device_background_texture_id = texture->getTextureHandle();
} else {
lock.reset(new ResourceProvider::ScopedReadLockGL(
@@ -988,7 +990,7 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
// TODO(senorblanco): Cache this value so that we don't have to do it for both
// the surface and its replica. Apply filters to the contents texture.
- SkBitmap filter_bitmap;
+ skia::RefPtr<SkImage> filter_bitmap;
SkScalar color_matrix[20];
bool use_color_matrix = false;
if (!quad->filters.IsEmpty()) {
@@ -1008,26 +1010,26 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
// in the compositor.
use_color_matrix = true;
} else {
- filter_bitmap =
+ filter_bitmap = skia::AdoptRef(
ApplyImageFilter(ScopedUseGrContext::Create(this, frame),
resource_provider_,
quad->rect.origin(),
quad->filters_scale,
filter.get(),
- contents_texture);
+ contents_texture));
}
}
}
if (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode &&
background_texture) {
- filter_bitmap =
+ filter_bitmap = skia::AdoptRef(
ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame),
resource_provider_,
- filter_bitmap,
+ filter_bitmap.get(),
contents_texture,
background_texture.get(),
- quad->shared_quad_state->blend_mode);
+ quad->shared_quad_state->blend_mode));
}
// Draw the background texture if it has some filters applied.
@@ -1076,9 +1078,8 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
// this draw instead of having a separate copy of the background texture.
scoped_ptr<ResourceProvider::ScopedSamplerGL> contents_resource_lock;
- if (filter_bitmap.getTexture()) {
- GrTexture* texture =
- reinterpret_cast<GrTexture*>(filter_bitmap.getTexture());
+ if (filter_bitmap) {
+ GrTexture* texture = filter_bitmap->getTexture();
DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle());
} else {
@@ -1333,7 +1334,7 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
// Flush the compositor context before the filter bitmap goes out of
// scope, so the draw gets processed before the filter texture gets deleted.
- if (filter_bitmap.getTexture())
+ if (filter_bitmap)
GLC(gl_, gl_->Flush());
}
« no previous file with comments | « no previous file | cc/resources/resource_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698