Index: cc/resources/ganesh_rasterizer.cc |
diff --git a/cc/resources/ganesh_rasterizer.cc b/cc/resources/ganesh_rasterizer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b39dc41dc44eb7941fd44f17b6e5a154c0ac1a19 |
--- /dev/null |
+++ b/cc/resources/ganesh_rasterizer.cc |
@@ -0,0 +1,113 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "cc/resources/ganesh_rasterizer.h" |
+ |
+#include "base/logging.h" |
+#include "cc/output/context_provider.h" |
+#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
+#include "third_party/skia/include/core/SkCanvas.h" |
+#include "third_party/skia/include/gpu/GrContext.h" |
+#include "third_party/skia/include/gpu/SkGpuDevice.h" |
+#include "ui/gfx/size_conversions.h" |
+ |
+namespace cc { |
+ |
+scoped_ptr<GaneshRasterizer> GaneshRasterizer::Create( |
+ ContextProvider* context_provider, |
+ ResourceProvider* resource_provider) { |
+ if (!context_provider || |
vmpstr
2013/11/22 21:29:12
Should these just be dchecks? or is there a valid
slavi
2013/11/23 01:27:19
Done.
|
+ !context_provider->Context3d() || |
+ !context_provider->GrContext()) |
+ return scoped_ptr<cc::GaneshRasterizer>(); |
+ return make_scoped_ptr( |
+ new GaneshRasterizer(context_provider, resource_provider)); |
+} |
+ |
+GaneshRasterizer::GaneshRasterizer( |
+ ContextProvider* context_provider, |
+ ResourceProvider* resource_provider) |
+ : client_(NULL), |
+ context_provider_(context_provider), |
+ resource_provider_(resource_provider) { |
+ DCHECK(context_provider_->Context3d()); |
+ DCHECK(context_provider_->GrContext()); |
+} |
+ |
+GaneshRasterizer::~GaneshRasterizer() { |
+} |
+ |
+void GaneshRasterizer::SetClient(GaneshRasterizerClient* client) { |
+ DCHECK(client); |
+ DCHECK(!client_); |
vmpstr
2013/11/22 21:29:12
With these two dchecks, it seems that client shoul
slavi
2013/11/23 01:27:19
This class get's instantiated before TileManager (
|
+ client_ = client; |
+} |
+ |
+GaneshRasterizer::RasterTask* GaneshRasterizer::CreateRasterTask( |
+ Tile* tile, scoped_ptr<ResourcePool::Resource> resource) { |
+ return new RasterTask(tile, resource.Pass()); |
+} |
+ |
+void GaneshRasterizer::Rasterize( |
+ RasterTaskVector& tasks, |
+ RenderingStatsInstrumentation* rendering_stats_instrumentation) { |
+ TRACE_EVENT0("cc", "GaneshRasterizer::Rasterize"); |
+ |
+ DCHECK(client_); |
+ |
+ if (tasks.empty()) |
+ return; |
+ |
+ blink::WebGraphicsContext3D* context = context_provider_->Context3d(); |
+ GrContext* gr_context = context_provider_->GrContext(); |
+ |
+ context->makeContextCurrent(); |
+ gr_context->resetContext(); |
+ for (RasterTaskVector::iterator it = tasks.begin(); it != tasks.end(); ++it) { |
+ RasterTask* task = *it; |
+ Tile* tile = task->tile_; |
+ ManagedTileState& mts = tile->managed_state(); |
+ DCHECK(mts.raster_mode == GANESH_RASTER_MODE); |
+ DCHECK_NE(task->resource_->id(), 0u); |
+ { |
+ ResourceProvider::ScopedWriteLockGL lock( |
+ resource_provider_, task->resource_->id()); |
+ |
+ DCHECK_NE(lock.texture_id(), 0u); |
+ GrBackendTextureDesc desc; |
+ desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
+ desc.fWidth = tile->size().width(); |
+ desc.fHeight = tile->size().height(); |
+ desc.fConfig = kSkia8888_GrPixelConfig; |
+ desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
+ desc.fTextureHandle = lock.texture_id(); |
+ skia::RefPtr<GrTexture> texture = |
+ skia::AdoptRef(gr_context->wrapBackendTexture(desc)); |
+ skia::RefPtr<SkGpuDevice> device = |
+ skia::AdoptRef(SkGpuDevice::Create(texture.get())); |
+ CHECK(device); |
+ skia::RefPtr<SkCanvas> canvas = |
+ skia::AdoptRef(new SkCanvas(device.get())); |
+ |
+ if (tile->opaque_rect().IsEmpty()) |
+ canvas->clear(SK_ColorTRANSPARENT); |
+ |
+ tile->picture_pile_->RasterDirect( |
+ canvas.get(), tile->content_rect_, tile->contents_scale_, |
+ rendering_stats_instrumentation); |
+ |
+ // TODO(skaslev) Remove this marker. |
+ { |
+ SkPaint paint; |
+ paint.setColor(SkColorSetRGB(255, 127, 0)); |
+ canvas->drawRect(SkRect::MakeXYWH(5, 5, 15, 15), paint); |
+ } |
+ } |
+ |
+ client_->OnGaneshRasterTaskCompleted(tile, task->resource_.Pass(), false); |
+ } |
+ gr_context->flush(); |
+} |
+ |
+} // namespace cc |